Example usage for org.apache.maven.plugin MojoExecution MojoExecution

List of usage examples for org.apache.maven.plugin MojoExecution MojoExecution

Introduction

In this page you can find the example usage for org.apache.maven.plugin MojoExecution MojoExecution.

Prototype

public MojoExecution(MojoDescriptor mojoDescriptor, String executionId, Source source) 

Source Link

Usage

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.  ja  va2  s. com*/
    }
    logger.debug("Configuration after: " + configuration);
    getMojoExecution().setConfiguration(configuration);
}

From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java

License:Open Source License

protected MojoExecution newMojoExecution(Plugin plugin, String goal, String executionId) {
    return new MojoExecution(plugin, goal, executionId);
}

From source file:org.codehaus.mojo.sonar.Bootstraper.java

License:Open Source License

private void executeMojo(MavenProject project, MavenSession session) throws MojoExecutionException {
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {/*  w  w  w.  j a  va  2 s .  c o  m*/

        RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
        repositoryRequest.setLocalRepository(session.getLocalRepository());
        repositoryRequest.setRemoteRepositories(project.getPluginArtifactRepositories());

        Plugin plugin = createSonarPlugin();

        List<RemoteRepository> remoteRepositories = session.getCurrentProject().getRemotePluginRepositories();

        PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(plugin, remoteRepositories,
                session.getRepositorySession());

        String goal = "sonar";

        MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
        if (mojoDescriptor == null) {
            throw new MojoExecutionException("Unknown mojo goal: " + goal);
        }
        MojoExecution mojoExecution = new MojoExecution(plugin, goal, "sonar" + goal);

        mojoExecution.setConfiguration(convert(mojoDescriptor));

        mojoExecution.setMojoDescriptor(mojoDescriptor);

        // olamy : we exclude nothing and import nothing regarding realm import and artifacts

        DependencyFilter artifactFilter = new DependencyFilter() {
            public boolean accept(DependencyNode arg0, List<DependencyNode> arg1) {
                return true;
            }
        };

        pluginManager.setupPluginRealm(pluginDescriptor, session,
                Thread.currentThread().getContextClassLoader(), Collections.<String>emptyList(),
                artifactFilter);

        Mojo mojo = pluginManager.getConfiguredMojo(Mojo.class, session, mojoExecution);
        Thread.currentThread().setContextClassLoader(pluginDescriptor.getClassRealm());
        mojo.execute();

    } catch (Exception e) {
        throw new MojoExecutionException("Can not execute Sonar", e);
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
public MojoExecution setupMojoExecution(MavenSession session, MavenProject project, MojoExecution execution)
        throws CoreException {
    MojoExecution clone = new MojoExecution(execution.getPlugin(), execution.getGoal(),
            execution.getExecutionId());
    clone.setMojoDescriptor(execution.getMojoDescriptor());
    if (execution.getConfiguration() != null) {
        clone.setConfiguration(new Xpp3Dom(execution.getConfiguration()));
    }/*  w w  w  .  j a  v  a  2 s. c  o m*/
    clone.setLifecyclePhase(execution.getLifecyclePhase());
    LifecycleExecutionPlanCalculator executionPlanCalculator = lookup(LifecycleExecutionPlanCalculator.class);
    try {
        executionPlanCalculator.setupMojoExecution(session, project, clone);
    } catch (Exception ex) {
        throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
                NLS.bind(Messages.MavenImpl_error_calc_build_plan, ex.getMessage()), ex));
    }
    return clone;
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java

License:Open Source License

@SuppressWarnings("deprecation")
public <T> T getMojoParameterValue(String parameter, Class<T> type, MavenSession session, Plugin plugin,
        ConfigurationContainer configuration, String goal) throws CoreException {
    Xpp3Dom config = (Xpp3Dom) configuration.getConfiguration();
    config = (config != null) ? config.getChild(parameter) : null;

    PlexusConfiguration paramConfig = null;

    if (config == null) {
        MojoDescriptor mojoDescriptor;/*from  w  w w  . j a v a2  s .co  m*/

        try {
            mojoDescriptor = lookup(BuildPluginManager.class).getMojoDescriptor(plugin, goal,
                    session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession());
        } catch (PluginNotFoundException ex) {
            throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
                    Messages.MavenImpl_error_param, ex));
        } catch (PluginResolutionException ex) {
            throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
                    Messages.MavenImpl_error_param, ex));
        } catch (PluginDescriptorParsingException ex) {
            throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
                    Messages.MavenImpl_error_param, ex));
        } catch (MojoNotFoundException ex) {
            throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
                    Messages.MavenImpl_error_param, ex));
        } catch (InvalidPluginDescriptorException ex) {
            throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1,
                    Messages.MavenImpl_error_param, ex));
        }

        PlexusConfiguration defaultConfig = mojoDescriptor.getMojoConfiguration();
        if (defaultConfig != null) {
            paramConfig = defaultConfig.getChild(parameter, false);
        }
    } else {
        paramConfig = new XmlPlexusConfiguration(config);
    }

    if (paramConfig == null) {
        return null;
    }

    try {
        MojoExecution mojoExecution = new MojoExecution(plugin, goal, "default"); //$NON-NLS-1$

        ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session,
                mojoExecution);

        ConfigurationConverter typeConverter = converterLookup.lookupConverterForType(type);

        Object value = typeConverter.fromConfiguration(converterLookup, paramConfig, type, Object.class,
                plexus.getContainerRealm(), expressionEvaluator, null);
        return type.cast(value);
    } catch (ComponentConfigurationException ex) {
        throw new CoreException(
                new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenImpl_error_param, ex));
    } catch (ClassCastException ex) {
        throw new CoreException(
                new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenImpl_error_param, ex));
    }
}

From source file:org.jszip.maven.AbstractJSZipMojo.java

License:Apache License

protected MojoExecution createMojoExecution(Plugin plugin, PluginExecution pluginExecution,
        MojoDescriptor mojoDescriptor) {
    MojoExecution mojoExecution = new MojoExecution(plugin, mojoDescriptor.getGoal(), pluginExecution.getId());
    mojoExecution.setConfiguration(convert(mojoDescriptor));
    if (plugin.getConfiguration() != null || pluginExecution.getConfiguration() != null) {
        Xpp3Dom pluginConfiguration = plugin.getConfiguration() == null ? new Xpp3Dom("fake")
                : (Xpp3Dom) plugin.getConfiguration();

        Xpp3Dom mergedConfigurationWithExecution = Xpp3DomUtils
                .mergeXpp3Dom((Xpp3Dom) pluginExecution.getConfiguration(), pluginConfiguration);

        Xpp3Dom mergedConfiguration = Xpp3DomUtils.mergeXpp3Dom(mergedConfigurationWithExecution,
                convert(mojoDescriptor));

        Xpp3Dom cleanedConfiguration = new Xpp3Dom("configuration");
        if (mergedConfiguration.getChildren() != null) {
            for (Xpp3Dom parameter : mergedConfiguration.getChildren()) {
                if (mojoDescriptor.getParameterMap().containsKey(parameter.getName())) {
                    cleanedConfiguration.addChild(parameter);
                }/*from  w w  w. j  a  v  a 2s.  c  o m*/
            }
        }
        if (getLog().isDebugEnabled()) {
            getLog().debug("mojoExecution mergedConfiguration: " + mergedConfiguration);
            getLog().debug("mojoExecution cleanedConfiguration: " + cleanedConfiguration);
        }

        mojoExecution.setConfiguration(cleanedConfiguration);

    }
    mojoExecution.setMojoDescriptor(mojoDescriptor);
    return mojoExecution;
}

From source file:org.l2x6.maven.srcdeps.SrcdepsLifecycleParticipant.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    boolean globalSkip = Boolean
            .valueOf(session.getUserProperties().getProperty(Element.skip.toSrcDepsProperty(), "false"));
    if (globalSkip) {
        logger.info("srcdeps-maven-plugin skipped");
        return;/*from  w  w  w  . j  a  va 2  s. co m*/
    }

    List<String> goals = session.getGoals();
    if (goals != null && shouldTriggerSrcdepsBuild(goals)) {
        List<MavenProject> projects = session.getProjects();
        logger.debug("SrcdepsLifecycleParticipant projects = " + projects);

        Set<Gav> projectGavs = new HashSet<SrcdepsLifecycleParticipant.Gav>();
        for (MavenProject project : projects) {
            projectGavs.add(Gav.ofModel(project.getModel()));
        }

        boolean builtSomething = false;

        for (MavenProject project : projects) {
            logger.info("srcdeps-maven-plugin scanning project " + project.getGroupId() + ":"
                    + project.getArtifactId());

            Optional<Plugin> plugin = findPlugin(project,
                    SrcdepsPluginConstants.ORG_L2X6_MAVEN_SRCDEPS_GROUP_ID,
                    SrcdepsPluginConstants.SRCDEPS_MAVEN_PLUGIN_ADRTIFACT_ID);
            if (plugin.isPresent() && project.getDependencies() != null) {

                Optional<Xpp3Dom> conf = plugin.map(Mapper.TO_DOM);
                if (conf.isPresent()) {

                    MojoExecution mojoExecution = new MojoExecution(plugin.value(), "install", "whatever");
                    PropsEvaluator evaluator = new PropsEvaluator(
                            new PluginParameterExpressionEvaluator(session, mojoExecution));
                    SrcdepsConfiguration srcdepsConfiguration = new SrcdepsConfiguration.Builder(evaluator,
                            conf.value(), session, logger).build();
                    if (srcdepsConfiguration.isSkip()) {
                        logger.info("srcdeps-maven-plugin skipped for project " + project.getGroupId() + ":"
                                + project.getArtifactId());
                    } else {
                        @SuppressWarnings("unchecked")
                        Map<Dependency, SrcVersion> revisions = filterSrcdeps(project.getDependencies(),
                                projectGavs);
                        if (!revisions.isEmpty()) {
                            assertFailWithProfiles(session, srcdepsConfiguration);
                            new SrcdepsInstaller(session, logger, artifactHandlerManager, srcdepsConfiguration,
                                    revisions, buildService).install();
                            builtSomething = true;
                        }
                    }
                }
            }
        }

        if (builtSomething) {
            Optional<Plugin> plugin = findPlugin(session.getTopLevelProject(), "org.apache.maven.plugins",
                    "maven-clean-plugin");
            if (plugin.isPresent()) {
                addCleanExclude(session.getTopLevelProject(), plugin.value());
            }
        }

    }
}

From source file:org.sonatype.tycho.m2e.felix.internal.MavenBundlePluginConfigurator.java

License:Open Source License

protected static MojoExecution amendMojoExecution(MavenProject mavenProject, MojoExecution execution,
        Map<String, String> instructions) {
    if ("bundle".equals(execution.getGoal())) {
        // do not generate complete bundle. this is both slow and can produce unexpected workspace changes
        // that will trigger unexpected/endless workspace build.
        // we rely on the fact that ManifestPlugin mojo extends BundlePlugin and does not introduce any
        // additional required parameters, so can run manifest goal in place of bundle goal.
        MojoDescriptor descriptor = execution.getMojoDescriptor().clone();
        descriptor.setGoal("manifest");
        descriptor.setImplementation("org.apache.felix.bundleplugin.ManifestPlugin");
        MojoExecution _execution = new MojoExecution(execution.getPlugin(), "manifest",
                "m2e-tycho:" + execution.getExecutionId() + ":manifest");
        _execution.setConfiguration(execution.getConfiguration());
        _execution.setMojoDescriptor(descriptor);
        _execution.setLifecyclePhase(execution.getLifecyclePhase());
        execution = _execution;//  ww w. j  av a2 s  .co m
    }

    Xpp3Dom configuration = new Xpp3Dom(execution.getConfiguration());
    if (VERSION_2_3_6.compareTo(new DefaultArtifactVersion(execution.getVersion())) <= 0) {
        setBoolean(configuration, "rebuildBundle", true);
    }

    if (isDeclerativeServices(mavenProject.getBasedir(), instructions)) {
        setBoolean(configuration, "unpackBundle", true);
    }

    execution.setConfiguration(configuration);

    return execution;
}