List of usage examples for org.apache.maven.plugin MojoExecution getMojoDescriptor
public MojoDescriptor getMojoDescriptor()
From source file:com.basistech.m2e.code.quality.shared.AbstractMavenPluginProjectConfigurator.java
License:Open Source License
public ClassRealm getPluginClassRealm(MavenSession session, MojoExecution mojoExecution) throws CoreException { IMaven maven = MavenPlugin.getMaven(); // call for side effect of ensuring that the realm is set in the descriptor. maven.getConfiguredMojo(session, mojoExecution, Mojo.class); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); return mojoDescriptor.getPluginDescriptor().getClassRealm(); }
From source file:com.github.sdedwards.m2e_nar.internal.MavenUtils.java
License:Apache License
private static <T extends AbstractMojo> T getConfiguredMojo(MavenSession session, MojoExecution mojoExecution, Class<T> asType, Log log) throws CoreException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); ClassRealm pluginRealm = getMyRealm(pluginDescriptor.getClassRealm().getWorld()); T mojo;/*from ww w .j a va 2s . c o m*/ try { mojo = asType.newInstance(); } catch (Exception e) { throw new CoreException( new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Problem when creating mojo", e)); } mojo.setLog(log); logger.debug("Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm); Xpp3Dom dom = mojoExecution.getConfiguration(); PlexusConfiguration pomConfiguration; if (dom == null) { pomConfiguration = new XmlPlexusConfiguration("configuration"); } else { pomConfiguration = new XmlPlexusConfiguration(dom); } ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); populatePluginFields(mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator); return mojo; }
From source file:com.github.sdedwards.m2e_nar.internal.NarTestCompileBuildParticipant.java
License:Apache License
public NarTestCompileBuildParticipant(MojoExecution execution, boolean runOnIncremental, boolean runOnConfiguration) { super(new MojoExecution(execution.getMojoDescriptor(), execution.getExecutionId(), execution.getSource()), runOnIncremental, runOnConfiguration); // Some versions of nar-maven-plugin don't have a nar-test-unpack goal // this means the test artifacts won't be available to us. // What we need to do is run the nar-testCompile goal without any tests // its configuration in order to just unpack. Xpp3Dom configuration = new Xpp3Dom(execution.getConfiguration()); logger.debug("Configuration before: " + configuration); for (int i = 0; i < configuration.getChildCount(); ++i) { if ("tests".equals(configuration.getChild(i).getName())) { configuration.removeChild(i); break; }/*from w w w .j av a 2 s . c o m*/ } logger.debug("Configuration after: " + configuration); getMojoExecution().setConfiguration(configuration); }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
private void finalizeMojoConfiguration(MojoExecution mojoExecution) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MavenProject project = getMavenSession().getCurrentProject(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); Plugin plugin = project.getPlugin(pluginDescriptor.getPluginLookupKey()); pluginDescriptor.setPlugin(plugin);/*from w w w . j a v a 2 s . c o m*/ Xpp3Dom executionConfiguration = mojoExecution.getConfiguration(); if (executionConfiguration == null) executionConfiguration = new Xpp3Dom("configuration"); Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert(mojoDescriptor); Xpp3Dom finalConfiguration = new Xpp3Dom("configuration"); if (mojoDescriptor.getParameters() != null) { for (Parameter parameter : mojoDescriptor.getParameters()) { Xpp3Dom parameterConfiguration = executionConfiguration.getChild(parameter.getName()); if (parameterConfiguration == null) parameterConfiguration = executionConfiguration.getChild(parameter.getAlias()); Xpp3Dom parameterDefaults = defaultConfiguration.getChild(parameter.getName()); parameterConfiguration = Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults, Boolean.TRUE); if (parameterConfiguration != null) { parameterConfiguration = new Xpp3Dom(parameterConfiguration, parameter.getName()); if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation")) && StringUtils.isNotEmpty(parameter.getImplementation())) { parameterConfiguration.setAttribute("implementation", parameter.getImplementation()); } finalConfiguration.addChild(parameterConfiguration); } } } if (plugin != null) { String goal = mojoExecution.getGoal(); for (PluginExecution pe : plugin.getExecutions()) { if (pe.getGoals().contains(goal)) { Xpp3Dom execConfig = (Xpp3Dom) pe.getConfiguration(); if (execConfig != null) finalConfiguration = Xpp3Dom.mergeXpp3Dom(execConfig, finalConfiguration); break; } } } mojoExecution.setConfiguration(finalConfiguration); }
From source file:fr.jcgay.maven.plugin.buildplan.display.AbstractTableDescriptor.java
License:Apache License
protected static Map<TableColumn, Integer> findMaxSize(Collection<MojoExecution> executions, TableColumn... columns) { Map<TableColumn, Integer> result = new HashMap<TableColumn, Integer>(); Multimap<TableColumn, Integer> count = ArrayListMultimap.create(); for (MojoExecution execution : executions) { for (TableColumn column : columns) { switch (column) { case ARTIFACT_ID: count.put(column, safeLength(execution.getArtifactId())); break; case EXECUTION_ID: count.put(column, safeLength(execution.getExecutionId())); break; case GOAL: count.put(column, safeLength(execution.getGoal())); break; case PHASE: MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); if (mojoDescriptor != null && mojoDescriptor.getPhase() != null) { count.put(column, safeLength(mojoDescriptor.getPhase())); } else { count.put(column, safeLength(execution.getLifecyclePhase())); }/*from ww w . java 2s .co m*/ } } } for (TableColumn column : TableColumn.values()) { count.put(column, column.title().length()); } for (TableColumn key : count.keySet()) { result.put(key, Collections.max(count.get(key))); } return result; }
From source file:hudson.gridmaven.MojoInfo.java
License:Open Source License
public MojoInfo(MojoExecution mojoExecution, Mojo mojo, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator) { // in Maven3 there's no easy way to get the Mojo instance that's being executed, // so we just can't pass it in. if (mojo == null) mojo = new Maven3ProvidesNoAccessToMojo(); this.mojo = mojo; this.mojoExecution = mojoExecution; this.configuration = configuration; this.expressionEvaluator = expressionEvaluator; this.pluginName = new PluginName(mojoExecution.getMojoDescriptor().getPluginDescriptor()); }
From source file:hudson.maven.agent.RunCommand.java
License:Open Source License
public Object call() throws Throwable { // return Main.class.getClassLoader().toString(); PluginManagerInterceptor.setListener(new PluginManagerListener() { public void preExecute(MavenProject project, MojoExecution exec, Mojo mojo, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException, AbortException { System.out.println("***** " + exec.getMojoDescriptor().getGoal()); }/*w w w . j a v a 2 s .com*/ public void postExecute(MavenProject project, MojoExecution exec, Mojo mojo, PlexusConfiguration mergedConfig, ExpressionEvaluator eval, Exception exception) throws IOException, InterruptedException, AbortException { System.out.println("==== " + exec.getMojoDescriptor().getGoal()); } public void onReportGenerated(MavenReport report, MojoExecution mojoExecution, PlexusConfiguration mergedConfig, ExpressionEvaluator eval) throws IOException, InterruptedException { System.out.println("//// " + report); } }); return new Integer(Main.launch(args)); }
From source file:hudson.maven.MojoInfo.java
License:Open Source License
public MojoInfo(MojoExecution mojoExecution, Mojo mojo, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, long startTime) { // in Maven3 there's no easy way to get the Mojo instance that's being executed, // so we just can't pass it in. if (mojo == null) mojo = new Maven3ProvidesNoAccessToMojo(); this.mojo = mojo; this.mojoExecution = mojoExecution; this.configuration = configuration; this.expressionEvaluator = expressionEvaluator; this.pluginName = new PluginName(mojoExecution.getMojoDescriptor().getPluginDescriptor()); this.startTime = startTime; }
From source file:io.fabric8.maven.core.util.GoalFinder.java
License:Apache License
private boolean checkGoalInPhase(MavenProject project, MavenSession session, String goal, String phase) throws MojoExecutionException { Lifecycle lifecycle = defaultLifeCycles.get(phase); if (lifecycle == null) { throw new MojoExecutionException("Cannot find lifecycle phase " + phase); }//from ww w . ja v a2 s.c o m LifecycleMappingDelegate delegate = findDelegate(lifecycle); try { Map<String, List<MojoExecution>> executionsMap = delegate.calculateLifecycleMappings(session, project, lifecycle, phase); boolean foundPhase = false; boolean foundGoal = false; for (String p : lifecycle.getPhases()) { List<MojoExecution> executions = executionsMap.get(p); if (executions != null) { for (MojoExecution execution : executions) { MojoDescriptor desc = execution.getMojoDescriptor(); if (desc != null && desc.getFullGoalName().equals(goal)) { foundGoal = true; break; } } } if (phase.equals(p)) { foundPhase = true; break; } } return foundPhase && foundGoal; } catch (Exception e) { throw new MojoExecutionException("Interna: Cannot extract executions", e); } }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
protected void finalizeMojoConfiguration(MojoExecution mojoExecution) { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); Xpp3Dom executionConfiguration = mojoExecution.getConfiguration(); if (executionConfiguration == null) { executionConfiguration = new Xpp3Dom("configuration"); }//from w w w . j av a2 s . c o m Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert(mojoDescriptor); Xpp3Dom finalConfiguration = new Xpp3Dom("configuration"); if (mojoDescriptor.getParameters() != null) { for (Parameter parameter : mojoDescriptor.getParameters()) { Xpp3Dom parameterConfiguration = executionConfiguration.getChild(parameter.getName()); if (parameterConfiguration == null) { parameterConfiguration = executionConfiguration.getChild(parameter.getAlias()); } Xpp3Dom parameterDefaults = defaultConfiguration.getChild(parameter.getName()); parameterConfiguration = Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults, Boolean.TRUE); if (parameterConfiguration != null) { parameterConfiguration = new Xpp3Dom(parameterConfiguration, parameter.getName()); if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation")) && StringUtils.isNotEmpty(parameter.getImplementation())) { parameterConfiguration.setAttribute("implementation", parameter.getImplementation()); } finalConfiguration.addChild(parameterConfiguration); } } } mojoExecution.setConfiguration(finalConfiguration); }