Java Code Examples for org.apache.maven.model.Plugin#setDependencies()

The following examples show how to use org.apache.maven.model.Plugin#setDependencies() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PomChangePlugin.java    From butterfly with MIT License 5 votes vote down vote up
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    TOExecutionResult result;

    Plugin plugin = getPlugin(model, groupId, artifactId);
    if (plugin != null) {
        model.getBuild().removePlugin(plugin);

        if (removeVersion) plugin.setVersion(null); else if (version != null) plugin.setVersion(version);
        if (removeExtensions) plugin.setExtensions(null); else if (extensions != null) plugin.setExtensions(extensions);
        if (removeExecutions) plugin.setExecutions(null); else if (executions != null) plugin.setExecutions(executions);
        if (removePluginDependencies) plugin.setDependencies(null); else if (pluginDependencies != null) plugin.setDependencies(pluginDependencies);

        model.getBuild().addPlugin(plugin);

        String details = String.format("Plugin %s:%s has been changed in %s", groupId, artifactId, getRelativePath());
        result = TOExecutionResult.success(this, details);
    } else {
        String message = String.format("Plugin %s:%s is not present in %s", groupId, artifactId, getRelativePath());

        switch (ifNotPresent) {
            case Warn:
                result = TOExecutionResult.warning(this, new TransformationOperationException(message));
                break;
            case NoOp:
                result = TOExecutionResult.noOp(this, message);
                break;
            case Fail:
                // Fail is the default
            default:
                result = TOExecutionResult.error(this, new TransformationOperationException(message));
                break;
        }
    }

    return result;
}
 
Example 2
Source File: AbstractSarlMojo.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** 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.
 * @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(MessageFormat.format(Messages.AbstractSarlMojo_0, plugin.getId()));

	final PluginDescriptor pluginDescriptor = this.mavenHelper.loadPlugin(plugin);
	if (pluginDescriptor == null) {
		throw new MojoExecutionException(MessageFormat.format(Messages.AbstractSarlMojo_1, plugin.getId()));
	}
	final MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
	if (mojoDescriptor == null) {
		throw new MojoExecutionException(MessageFormat.format(Messages.AbstractSarlMojo_2, goal));
	}

	final Xpp3Dom mojoXml;
	try {
		mojoXml = this.mavenHelper.toXpp3Dom(mojoDescriptor.getMojoConfiguration());
	} catch (PlexusConfigurationException e1) {
		throw new MojoExecutionException(e1.getLocalizedMessage(), e1);
	}
	Xpp3Dom configurationXml = this.mavenHelper.toXpp3Dom(configuration, getLog());
	if (configurationXml != null) {
		configurationXml = Xpp3DomUtils.mergeXpp3Dom(
				configurationXml,
				mojoXml);
	} else {
		configurationXml = mojoXml;
	}

	getLog().debug(MessageFormat.format(Messages.AbstractSarlMojo_3, plugin.getId(), configurationXml.toString()));

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

	this.mavenHelper.executeMojo(execution);
}