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

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

Introduction

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

Prototype

public void setMojoDescriptor(MojoDescriptor mojoDescriptor) 

Source Link

Usage

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 {/*from  w  w w  . j  ava 2  s. c om*/

        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()));
    }//from w  w w  .  j av  a2s .co 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.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 av  a  2  s . com*/
            }
        }
        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.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;//w  w  w.  j  a va 2s  .  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;
}