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

The following examples show how to use org.apache.maven.model.Plugin#setVersion() . 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: CreateUtils.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static Plugin resolvePluginInfo(Path pluginXml) throws MojoExecutionException {
    if (!Files.exists(pluginXml)) {
        throw new MojoExecutionException("Failed to locate " + pluginXml);
    }
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        final DocumentBuilder db = dbf.newDocumentBuilder();
        try (InputStream is = Files.newInputStream(pluginXml)) {
            final Document doc = db.parse(is);
            final Node pluginNode = getElement(doc.getChildNodes(), "plugin");
            final Plugin plugin = new Plugin();
            plugin.setGroupId(getChildElementTextValue(pluginNode, "groupId"));
            plugin.setArtifactId(getChildElementTextValue(pluginNode, "artifactId"));
            plugin.setVersion(getChildElementTextValue(pluginNode, "version"));
            return plugin;
        }
    } catch (Throwable t) {
        throw new MojoExecutionException("Failed to parse " + pluginXml, t);
    }
}
 
Example 2
Source File: PomUtils.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
private static boolean ensurePlugin(Model model) {
    org.apache.maven.model.Build build = model.getBuild();
    boolean isPresent = build.getPlugins()
                             .stream()
                             .anyMatch(p -> p.getGroupId().equals(BUILD_TOOLS_GROUP_ID)
                                     && p.getArtifactId().equals(BUILD_TOOLS_PLUGIN_ARTIFACT_ID));
    if (isPresent) {
        // Assume it is what we want rather than updating if not equal, since
        // that could undo future archetype changes.
        return false;
    } else {
        Plugin helidonPlugin = new Plugin();
        helidonPlugin.setGroupId(BUILD_TOOLS_GROUP_ID);
        helidonPlugin.setArtifactId(BUILD_TOOLS_PLUGIN_ARTIFACT_ID);
        helidonPlugin.setVersion("${" + HELIDON_PLUGIN_VERSION_PROPERTY + "}");
        helidonPlugin.setExtensions(true);
        build.addPlugin(helidonPlugin);
        return true;
    }
}
 
Example 3
Source File: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
private Plugin addOsgiHelperMavenPlugin() {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.talend.ci");
    plugin.setArtifactId("osgihelper-maven-plugin");
    plugin.setVersion(VersionUtils.getMojoVersion("osgihelper.version"));

    Xpp3Dom configuration = new Xpp3Dom("configuration");
    Xpp3Dom featuresFile = new Xpp3Dom("featuresFile");
    featuresFile.setValue("${basedir}/src/main/resources/feature/feature.xml");
    configuration.addChild(featuresFile);

    List<PluginExecution> pluginExecutions = new ArrayList<PluginExecution>();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("feature-helper");
    pluginExecution.setPhase("generate-sources");
    pluginExecution.addGoal("generate");
    pluginExecution.setConfiguration(configuration);
    pluginExecutions.add(pluginExecution);
    plugin.setExecutions(pluginExecutions);

    return plugin;
}
 
Example 4
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
private Plugin addOsgiHelperMavenPlugin() {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.talend.ci");
    plugin.setArtifactId("osgihelper-maven-plugin");
    plugin.setVersion(VersionUtils.getMojoVersion("osgihelper.version"));

    Xpp3Dom configuration = new Xpp3Dom("configuration");
    Xpp3Dom featuresFile = new Xpp3Dom("featuresFile");
    featuresFile.setValue(PATH_FEATURE);
    configuration.addChild(featuresFile);

    List<PluginExecution> pluginExecutions = new ArrayList<PluginExecution>();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("feature-helper");
    pluginExecution.setPhase("generate-sources");
    pluginExecution.addGoal("generate");
    pluginExecution.setConfiguration(configuration);
    pluginExecutions.add(pluginExecution);
    plugin.setExecutions(pluginExecutions);

    return plugin;
}
 
Example 5
Source File: PomUpdater.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
private void alterSinglePlugin(List<String> errors, String searchingFrom, Properties projectProperties, Plugin plugin) {
    String version = plugin.getVersion();
    if (!isMultiModuleReleasePlugin(plugin) &&
        MavenVersionResolver.isSnapshot(MavenVersionResolver.resolveVersion(version, projectProperties))) {
        try {
            ReleasableModule pluginBeingReleased = reactor.find(plugin.getGroupId(), plugin.getArtifactId(), version);
            plugin.setVersion(pluginBeingReleased.getVersionToDependOn());
            log.info("Plugin dependency on " + pluginBeingReleased.getArtifactId() + " rewritten to version " + pluginBeingReleased.getVersionToDependOn());
        } catch (UnresolvedSnapshotDependencyException e) {
            errors.add(searchingFrom + " references plugin dependency " + e.artifactId + " " + e.version);
        }
    }
    else {
        log.debug("Plugin dependency on " + plugin.getArtifactId() + " kept at version " + plugin.getVersion());
    }
}
 
Example 6
Source File: MavenUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
/**
 * Upgrade the plugin versions of the given maven project. 
 * This will change the maven plugin versions of Developer Studio projects 
 * according to the working version of Developer Studio. 
 * @param project
 * @param mavenProject
 */
public static void upgradePluginVersions(IProject project, MavenProject mavenProject) {
	List<Plugin> plugins = mavenProject.getBuildPlugins();
	
	for(Plugin plugin : plugins) {
		if (GROUP_ID_ORG_WSO2_MAVEN.equals(plugin.getGroupId())) {
			String newVersion = WSO2MavenPluginVersions.getPluginVersion(plugin.getArtifactId());
			if (newVersion != null && !plugin.getVersion().equals(newVersion)) {
				// Update the plugin version.
				plugin.setVersion(newVersion);
			}
		}
	}
}
 
Example 7
Source File: RangeResolver.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private void handleVersionWithRange( Plugin p )
{
    try
    {
        VersionRange versionRange = VersionRange.createFromVersionSpec( p.getVersion() );

        // If its a range then try to use a matching version...
        if ( versionRange.hasRestrictions() )
        {
            final List<ArtifactVersion> versions = getVersions( new SimpleProjectRef( p.getGroupId(), p.getArtifactId() ) );
            final ArtifactVersion result = versionRange.matchVersion( versions );

            logger.debug( "Resolved range for plugin {} got versionRange {} and potential replacement of {} ", p, versionRange, result );

            if ( result != null )
            {
                p.setVersion( result.toString() );
            }
            else
            {
                logger.warn( "Unable to find replacement for range." );
            }
        }
    }
    catch ( InvalidVersionSpecificationException e )
    {
        throw new ManipulationUncheckedException( new ManipulationException( "Invalid range", e ) );
    }
}
 
Example 8
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private Plugin addFeaturesMavenPlugin(String finalNameValue) {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.apache.karaf.tooling");
    plugin.setArtifactId("karaf-maven-plugin");
    plugin.setVersion("4.2.4");

    Xpp3Dom configuration = new Xpp3Dom("configuration");

    Xpp3Dom finalName = new Xpp3Dom("finalName");

    finalName.setValue(finalNameValue);// "${talend.job.finalName}"

    Xpp3Dom resourcesDir = new Xpp3Dom("resourcesDir");
    resourcesDir.setValue("${project.build.directory}/bin");

    Xpp3Dom featuresFile = new Xpp3Dom("featuresFile");
    featuresFile.setValue(PATH_FEATURE);

    configuration.addChild(finalName);
    configuration.addChild(resourcesDir);
    configuration.addChild(featuresFile);

    List<PluginExecution> pluginExecutions = new ArrayList<PluginExecution>();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("create-kar");
    pluginExecution.addGoal("kar");
    pluginExecution.setConfiguration(configuration);

    pluginExecutions.add(pluginExecution);
    plugin.setExecutions(pluginExecutions);

    return plugin;
}
 
Example 9
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 5 votes vote down vote up
private static Plugin toPlugin(Artifact artifact) {
    Plugin plugin = new Plugin();
    plugin.setGroupId(artifact.getGroupId());
    plugin.setArtifactId(artifact.getArtifactId());
    plugin.setVersion(artifact.getVersion());
    return plugin;
}
 
Example 10
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Plugin toPlugin( ReportPlugin reportPlugin )
{
    Plugin plugin = new Plugin();
    plugin.setGroupId( reportPlugin.getGroupId() );
    plugin.setArtifactId( reportPlugin.getArtifactId() );
    plugin.setVersion( reportPlugin.getVersion() );
    return plugin;
}
 
Example 11
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds those project plugins which are not inherited from the parent definitions to the list of plugins.
 *
 * @param plugins The list of plugins.
 * @param projectPlugins The project's plugins.
 * @param parentDefinitions The parent plugin definitions.
 * @since 1.0-alpha-1
 */
private void addProjectPlugins( Map<String, Plugin> plugins, Collection<Plugin> projectPlugins,
                                Map<String, String> parentDefinitions )
{
    for ( Plugin plugin : projectPlugins )
    {
        String coord = plugin.getKey();
        String version = plugin.getVersion();
        String parentVersion = parentDefinitions.get( coord );
        if ( version == null
            && ( !plugins.containsKey( coord ) || plugins.get( coord ).getVersion() == null )
            && parentVersion != null )
        {
            Plugin parentPlugin = new Plugin();
            parentPlugin.setGroupId( plugin.getGroupId() );
            parentPlugin.setArtifactId( plugin.getArtifactId() );
            parentPlugin.setVersion( parentVersion );
            plugins.put( coord, parentPlugin );
        }
        else if ( parentVersion == null || !parentVersion.equals( version ) )
        {
            if ( !plugins.containsKey( coord ) || plugins.get( coord ).getVersion() == null )
            {
                plugins.put( coord, plugin );
            }
        }
        if ( !plugins.containsKey( coord ) )
        {
            plugins.put( coord, plugin );
        }
    }
}
 
Example 12
Source File: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private Plugin addFeaturesMavenPlugin() {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.apache.karaf.tooling");
    plugin.setArtifactId("karaf-maven-plugin");
    plugin.setVersion("4.2.4");

    Xpp3Dom configuration = new Xpp3Dom("configuration");

    Xpp3Dom resourcesDir = new Xpp3Dom("resourcesDir");
    resourcesDir.setValue("${project.build.directory}/bin");

    Xpp3Dom featuresFile = new Xpp3Dom("featuresFile");
    featuresFile.setValue("${basedir}/src/main/resources/feature/feature.xml");

    configuration.addChild(resourcesDir);
    configuration.addChild(featuresFile);

    List<PluginExecution> pluginExecutions = new ArrayList<PluginExecution>();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("create-kar");
    pluginExecution.addGoal("kar");
    pluginExecution.setConfiguration(configuration);

    pluginExecutions.add(pluginExecution);
    plugin.setExecutions(pluginExecutions);

    return plugin;
}
 
Example 13
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 5 votes vote down vote up
static Plugin newPlugin( String groupId, String artifactId, String version )
{
    Plugin plugin = new Plugin();
    plugin.setArtifactId( artifactId );
    plugin.setGroupId( groupId );
    plugin.setVersion( version );
    return plugin;
}
 
Example 14
Source File: VersioningMojo.java    From maven-git-versioning-extension with MIT License 5 votes vote down vote up
static Plugin asPlugin() {
    Plugin plugin = new Plugin();
    plugin.setGroupId(BuildProperties.projectGroupId());
    plugin.setArtifactId(BuildProperties.projectArtifactId());
    plugin.setVersion(BuildProperties.projectVersion());
    return plugin;
}
 
Example 15
Source File: PluginToStringTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static Plugin createPlugin(String gid, String aid, String version) {
  Plugin p = new Plugin();
  p.setGroupId(gid);
  p.setArtifactId(aid);
  p.setVersion(version);
  return p;
}
 
Example 16
Source File: PluginState.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
public void setRemoteRESTOverrides( Map<ArtifactRef, String> overrides )
{
    for ( ArtifactRef a : overrides.keySet() )
    {
        Plugin p = new Plugin();
        p.setGroupId( a.getGroupId() );
        p.setArtifactId( a.getArtifactId() );
        p.setVersion( overrides.get( a ) );
        remoteRESTplugins.add( p );
    }
}
 
Example 17
Source File: ModelUtil.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
static Build prepareBuildWithSurefirePlugin(String version) {
    Plugin surefirePlugin = new Plugin();
    surefirePlugin.setArtifactId(ApplicablePlugins.SUREFIRE.getArtifactId());
    surefirePlugin.setVersion(version);

    Build build = new Build();
    build.addPlugin(surefirePlugin);

    return build;
}
 
Example 18
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 19
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);
}
 
Example 20
Source File: CreateMavenBundlePom.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
private Plugin addSkipDeployFeatureMavenPlugin() {

        Plugin plugin = new Plugin();

        plugin.setGroupId("org.apache.maven.plugins");
        plugin.setArtifactId("maven-deploy-plugin");
        plugin.setVersion("2.7");

        Xpp3Dom configuration = new Xpp3Dom("configuration");

        Xpp3Dom skip = new Xpp3Dom("skip");
        skip.setValue("true");
        configuration.addChild(skip);
        plugin.setConfiguration(configuration);

        return plugin;

    }