Example usage for org.apache.maven.plugin.descriptor MojoDescriptor getMojoConfiguration

List of usage examples for org.apache.maven.plugin.descriptor MojoDescriptor getMojoConfiguration

Introduction

In this page you can find the example usage for org.apache.maven.plugin.descriptor MojoDescriptor getMojoConfiguration.

Prototype

public PlexusConfiguration getMojoConfiguration() 

Source Link

Usage

From source file:com.maltera.technologic.maven.mcforge.AbstractForgeMojo.java

License:Open Source License

/** Deletes the Forge directory by invoking clean:clean.
 * Recursive deletion is hard to get right, so we just let Maven handle it.
 * @throws MojoFailureException if mojo invocation fails
 *///  w ww  . j av a2 s . c o m
protected void cleanOutputDirectory() throws MojoFailureException {
    final MojoDescriptor mojo;
    try {
        final Plugin plugin = new Plugin();
        plugin.setGroupId("org.apache.maven.plugins");
        plugin.setArtifactId("maven-clean-plugin");
        plugin.setVersion("2.5");

        mojo = plugins.getMojoDescriptor(plugin, "clean", pluginRepos, aetherSession);
    } catch (Exception caught) {
        throw new MojoFailureException("error loading maven-clean-plugin:clean", caught);
    }

    final MojoExecution request = new MojoExecution(mojo,
            Xpp3DomUtils.mergeXpp3Dom(
                    node("configuration", node("excludeDefaultDirectories", "true"),
                            node("filesets",
                                    node("fileset", node("directory", outputDir.getPath()),
                                            node("useDefaultExcludes", "false")))),
                    node(mojo.getMojoConfiguration())));

    try {
        plugins.executeMojo(session, request);
    } catch (Exception caught) {
        throw new MojoFailureException("error invoking maven-clean-plugin:clean", caught);
    }
}

From source file:com.soebes.maven.plugins.iterator.IteratorMojo.java

License:Apache License

private MojoExecution mojoExecution(MojoDescriptor mojoDescriptor, Xpp3Dom configuration) {
    Xpp3Dom resultConfiguration = Xpp3DomUtils.mergeXpp3Dom(configuration,
            toXpp3Dom(mojoDescriptor.getMojoConfiguration()));
    return new MojoExecution(mojoDescriptor, resultConfiguration);
}

From source file:io.fabric8.maven.docker.service.MojoExecutionService.java

License:Apache License

private MojoExecution getMojoExecution(String executionId, MojoDescriptor mojoDescriptor) {
    if (executionId != null) {
        return new MojoExecution(mojoDescriptor, executionId);
    } else {/*from w w w.  ja  v a  2  s  .  c  om*/
        return new MojoExecution(mojoDescriptor, toXpp3Dom(mojoDescriptor.getMojoConfiguration()));
    }
}

From source file:io.sarl.maven.compiler.AbstractSarlMojo.java

License:Apache License

/** Execute another MOJO.
 *
 * @param groupId - identifier of the MOJO plugin group.
 * @param artifactId - identifier of the MOJO plugin artifact.
 * @param version - version of the MOJO plugin version.
 * @param goal - the goal to run./*w w  w .  j a  v a 2s .  c o m*/
 * @param configuration - the XML code for the configuration.
 * @param dependencies - the dependencies of the plugin.
 * @throws MojoExecutionException when cannot run the MOJO.
 * @throws MojoFailureException when the build failed.
 */
protected void executeMojo(String groupId, String artifactId, String version, String goal, String configuration,
        Dependency... dependencies) throws MojoExecutionException, MojoFailureException {
    final Plugin plugin = new Plugin();
    plugin.setArtifactId(artifactId);
    plugin.setGroupId(groupId);
    plugin.setVersion(version);
    plugin.setDependencies(Arrays.asList(dependencies));

    getLog().debug(Locale.getString(AbstractSarlMojo.class, "LAUNCHING", plugin.getId())); //$NON-NLS-1$

    final PluginDescriptor pluginDescriptor = this.mavenHelper.loadPlugin(plugin);
    if (pluginDescriptor == null) {
        throw new MojoExecutionException(
                Locale.getString(AbstractSarlMojo.class, "PLUGIN_NOT_FOUND", plugin.getId())); //$NON-NLS-1$
    }
    final MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
    if (mojoDescriptor == null) {
        throw new MojoExecutionException(Locale.getString(AbstractSarlMojo.class, "GOAL_NOT_FOUND", goal)); //$NON-NLS-1$
    }

    final Xpp3Dom mojoXml;
    try {
        mojoXml = toXpp3Dom(mojoDescriptor.getMojoConfiguration());
    } catch (PlexusConfigurationException e1) {
        throw new MojoExecutionException(e1.getLocalizedMessage(), e1);
    }
    Xpp3Dom configurationXml = null;
    if (configuration != null && !configuration.isEmpty()) {
        try (StringReader sr = new StringReader(configuration)) {
            try {
                configurationXml = Xpp3DomBuilder.build(sr);
            } catch (XmlPullParserException | IOException e) {
                getLog().debug(e);
            }
        }
    }
    if (configurationXml != null) {
        configurationXml = Xpp3DomUtils.mergeXpp3Dom(configurationXml, mojoXml);
    } else {
        configurationXml = mojoXml;
    }

    getLog().debug(Locale.getString(AbstractSarlMojo.class, "CONFIGURATION_FOR", //$NON-NLS-1$
            plugin.getId(), configurationXml.toString()));

    final MojoExecution execution = new MojoExecution(mojoDescriptor, configurationXml);

    this.mavenHelper.executeMojo(execution);
}

From source file:io.wcm.maven.plugins.cq.InstallMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    Plugin plugin = new Plugin();
    plugin.setGroupId("org.apache.sling");
    plugin.setArtifactId("maven-sling-plugin");
    plugin.setVersion(this.slingPluginVersion);

    try {/*  w w w . j  av a  2 s  .c  om*/
        PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(plugin,
                project.getRemotePluginRepositories(), session.getRepositorySession());
        MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("install");
        MojoExecution mojoExecution = new MojoExecution(pluginDescriptor.getMojo("install"));

        Xpp3Dom config = convertConfiguration(mojoDescriptor.getMojoConfiguration());
        config.getChild("slingUrl").setValue(this.slingConsoleUrl);
        config.getChild("user").setValue(this.slingConsoleUser);
        config.getChild("password").setValue(this.slingConsolePassword);
        config.getChild("mountByFS").setValue("false");
        mojoExecution.setConfiguration(config);

        buildPluginManager.executeMojo(session, mojoExecution);
    } catch (Throwable ex) {
        throw new MojoExecutionException("Faild to execute plugin: " + plugin, ex);
    }

}

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

License:Open Source License

private Xpp3Dom convert(MojoDescriptor mojoDescriptor) {
    Xpp3Dom dom = new Xpp3Dom("configuration");

    PlexusConfiguration c = mojoDescriptor.getMojoConfiguration();

    PlexusConfiguration[] ces = c.getChildren();

    if (ces != null) {
        for (PlexusConfiguration ce : ces) {
            String value = ce.getValue(null);
            String defaultValue = ce.getAttribute("default-value", null);
            if (value != null || defaultValue != null) {
                Xpp3Dom e = new Xpp3Dom(ce.getName());
                e.setValue(value);/*w  ww .j  a va  2s .c o m*/
                if (defaultValue != null) {
                    e.setAttribute("default-value", defaultValue);
                }
                dom.addChild(e);
            }
        }
    }

    return dom;
}

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;

        try {//from w  ww . ja  v a2  s.co m
            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

private Xpp3Dom convert(MojoDescriptor mojoDescriptor) {
    PlexusConfiguration config = mojoDescriptor.getMojoConfiguration();
    return (config != null) ? convert(config) : new Xpp3Dom("configuration");
}

From source file:org.twdata.maven.mojoexecutor.MojoExecutor.java

License:Apache License

private static MojoExecution mojoExecution(MojoDescriptor mojoDescriptor, String executionId,
        Xpp3Dom configuration) {// w  ww .j  a  va2 s. c  om
    if (executionId != null) {
        return new MojoExecution(mojoDescriptor, executionId);
    } else {
        configuration = Xpp3DomUtils.mergeXpp3Dom(configuration,
                toXpp3Dom(mojoDescriptor.getMojoConfiguration()));
        return new MojoExecution(mojoDescriptor, configuration);
    }
}

From source file:org.universAAL.maven.MyMojoExecutorV15.java

License:Apache License

/**
 * Executes mojo in maven 3./* w ww  .  j av  a2s .co m*/
 * 
 * @param mojoDescriptor
 *            descriptor of mojo
 * @param executionId
 *            execution id
 * @param configuration
 *            configuration
 * @return mojo execution
 */
private static MojoExecution mojoExecution3(final MojoDescriptor mojoDescriptor, final String executionId,
        final Xpp3Dom configuration) {
    if (executionId != null) {
        return new MojoExecution(mojoDescriptor, executionId);
    } else {
        Xpp3Dom newconfiguration = Xpp3DomUtils.mergeXpp3Dom(configuration,
                toXpp3Dom(mojoDescriptor.getMojoConfiguration()));
        return new MojoExecution(mojoDescriptor, newconfiguration);
    }
}