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

The following examples show how to use org.apache.maven.model.Plugin#getVersion() . 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: AddPropertyDialog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String findVersion(String groupId, String artifactId) {
    String key = groupId + ":" + artifactId;
    List<Plugin> plugins = new ArrayList<Plugin>();
    if (project != null) {
        List<Plugin> bld = project.getOriginalMavenProject().getBuildPlugins();
        if (bld != null) {
            plugins.addAll(bld);
        }
        if (project.getOriginalMavenProject().getPluginManagement() != null) {
            List<Plugin> pm = project.getOriginalMavenProject().getPluginManagement().getPlugins();
            if (pm != null) {
                plugins.addAll(pm);
            }
        }
    }

    for (Plugin plg : plugins) {
        if (key.equals(plg.getKey())) {
            return plg.getVersion();
        }
    }
    return null;
}
 
Example 2
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 3
Source File: IteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Taken from MojoExecutor of Don Brown. Make it working with Maven 3.1.
 * 
 * @param plugin
 * @param goal
 * @param configuration
 * @param env
 * @throws MojoExecutionException
 * @throws PluginResolutionException
 * @throws PluginDescriptorParsingException
 * @throws InvalidPluginDescriptorException
 * @throws PluginManagerException
 * @throws PluginConfigurationException
 * @throws MojoFailureException
 */
private void executeMojo( Plugin plugin, String goal, Xpp3Dom configuration )
    throws MojoExecutionException, PluginResolutionException, PluginDescriptorParsingException,
    InvalidPluginDescriptorException, MojoFailureException, PluginConfigurationException, PluginManagerException
{

    if ( configuration == null )
    {
        throw new NullPointerException( "configuration may not be null" );
    }

    PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin );

    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
    if ( mojoDescriptor == null )
    {
        throw new MojoExecutionException( "Could not find goal '" + goal + "' in plugin " + plugin.getGroupId()
            + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() );
    }

    MojoExecution exec = mojoExecution( mojoDescriptor, configuration );
    pluginManager.executeMojo( getMavenSession(), exec );
}
 
Example 4
Source File: MojoExecutionService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public void callPluginGoal(String fullGoal) {
    String[] parts = splitGoalSpec(fullGoal);
    Plugin plugin = project.getPlugin(parts[0]);
    String goal = parts[1];

    if (plugin == null) {
        throw new IllegalStateException("No goal " + fullGoal + " found in pom.xml");
    }

    try {
        String executionId = null;
        if (goal != null && goal.length() > 0 && goal.indexOf('#') > -1) {
            int pos = goal.indexOf('#');
            executionId = goal.substring(pos + 1);
            goal = goal.substring(0, pos);
        }

        PluginDescriptor pluginDescriptor = getPluginDescriptor(project, plugin);
        MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
        if (mojoDescriptor == null) {
            throw new MojoExecutionException("Could not find goal '" + goal + "' in plugin "
                                             + plugin.getGroupId() + ":"
                                             + plugin.getArtifactId() + ":"
                                             + plugin.getVersion());
        }
        MojoExecution exec = getMojoExecution(executionId, mojoDescriptor);
        pluginManager.executeMojo(session, exec);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to execute mojo", e);
    }
}
 
Example 5
Source File: DefaultVersionsHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public PluginUpdatesDetails lookupPluginUpdates( Plugin plugin, boolean allowSnapshots )
    throws ArtifactMetadataRetrievalException, InvalidVersionSpecificationException
{
    String version = plugin.getVersion();
    version = version == null ? "LATEST" : version;
    getLog().debug( "Checking " + ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() )
        + " for updates newer than " + version );

    VersionRange versionRange = VersionRange.createFromVersion( version );

    final boolean includeSnapshots = allowSnapshots;

    final ArtifactVersions pluginArtifactVersions =
        lookupArtifactVersions( createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ),
                                true );

    Set<Dependency> pluginDependencies = new TreeSet<Dependency>( new DependencyComparator() );
    if ( plugin.getDependencies() != null )
    {
        pluginDependencies.addAll( plugin.getDependencies() );
    }
    Map<Dependency, ArtifactVersions> pluginDependencyDetails =
        lookupDependenciesUpdates( pluginDependencies, false );

    return new PluginUpdatesDetails( pluginArtifactVersions, pluginDependencyDetails, includeSnapshots );
}
 
Example 6
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 7
Source File: MojoExecutionService.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
public void callPluginGoal(String fullGoal) throws MojoFailureException, MojoExecutionException {
    String[] parts = splitGoalSpec(fullGoal);
    Plugin plugin = project.getPlugin(parts[0]);
    String goal = parts[1];

    if (plugin == null) {
        throw new MojoFailureException("No goal " + fullGoal + " found in pom.xml");
    }

    try {
        String executionId = null;
        if (goal != null && goal.length() > 0 && goal.indexOf('#') > -1) {
            int pos = goal.indexOf('#');
            executionId = goal.substring(pos + 1);
            goal = goal.substring(0, pos);
        }

        PluginDescriptor pluginDescriptor = getPluginDescriptor(project, plugin);
        MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal);
        if (mojoDescriptor == null) {
            throw new MojoExecutionException("Could not find goal '" + goal + "' in plugin "
                                             + plugin.getGroupId() + ":"
                                             + plugin.getArtifactId() + ":"
                                             + plugin.getVersion());
        }
        MojoExecution exec = getMojoExecution(executionId, mojoDescriptor);
        pluginManager.executeMojo(session, exec);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to execute mojo", e);
    }
}
 
Example 8
Source File: PluginExtractor.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the plugin version from Maven Project.
 *
 * @param mojo   the mojo
 * @param plugin the artifact id of the plugin
 * @return the version, {@code null} if the Maven Project does not used the given plugin
 */
public static String getBuildPluginVersion(AbstractWisdomMojo mojo, String plugin) {
    List<Plugin> plugins = mojo.project.getBuildPlugins();
    for (Plugin plug : plugins) {
        if (plug.getArtifactId().equals(plugin)) {
            return plug.getVersion();
        }
    }
    // Not found.
    return null;
}
 
Example 9
Source File: DependencyDownloader.java    From go-offline-maven-plugin with Apache License 2.0 4 votes vote down vote up
private Artifact toArtifact(Plugin plugin) {
    ArtifactType artifactType = typeRegistry.get(MAVEN_PLUGIN_ARTIFACT_TYPE);
    return new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), artifactType.getClassifier(), artifactType.getExtension(), plugin.getVersion(),
            artifactType);
}
 
Example 10
Source File: IsSnapshotPlugin.java    From unleash-maven-plugin with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean apply(Plugin p) {
  String version = p.getVersion();
  version = propertyResolver.expandPropertyReferences(version);
  return version != null && MavenVersionUtil.isSnapshot(version);
}
 
Example 11
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Takes a list of {@link org.apache.maven.model.Plugin} instances and adds associations to properties used to
 * define versions of the plugin artifact or any of the plugin dependencies specified in the pom.
 *
 * @param helper Our helper.
 * @param expressionEvaluator Our expression evaluator.
 * @param result The map of {@link org.codehaus.mojo.versions.api.PropertyVersionsBuilder} keyed by property name.
 * @param plugins The list of {@link org.apache.maven.model.Plugin}.
 * @throws ExpressionEvaluationException if an expression cannot be evaluated.
 */
private static void addPluginAssociations( VersionsHelper helper, ExpressionEvaluator expressionEvaluator,
                                           Map<String, PropertyVersionsBuilder> result, List<Plugin> plugins )
    throws ExpressionEvaluationException
{
    if ( plugins == null )
    {
        return;
    }
    for ( Plugin plugin : plugins )
    {
        String version = plugin.getVersion();
        if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 )
        {
            version = StringUtils.deleteWhitespace( version );
            for ( PropertyVersionsBuilder property : result.values() )
            {
                // any of these could be defined by a property
                final String propertyRef = "${" + property.getName() + "}";
                if ( version.contains( propertyRef ) )
                {
                    String groupId = plugin.getGroupId();
                    if ( groupId == null || groupId.trim().length() == 0 )
                    {
                        // group Id has a special default
                        groupId = APACHE_MAVEN_PLUGINS_GROUPID;
                    }
                    else
                    {
                        groupId = (String) expressionEvaluator.evaluate( groupId );
                    }
                    String artifactId = plugin.getArtifactId();
                    if ( artifactId == null || artifactId.trim().length() == 0 )
                    {
                        // malformed pom
                        continue;
                    }
                    else
                    {
                        artifactId = (String) expressionEvaluator.evaluate( artifactId );
                    }
                    // might as well capture the current value
                    VersionRange versionRange =
                        VersionRange.createFromVersion( (String) expressionEvaluator.evaluate( plugin.getVersion() ) );
                    property.addAssociation( helper.createPluginArtifact( groupId, artifactId, versionRange ),
                                             true );
                    if ( !propertyRef.equals( version ) )
                    {
                        addBounds( property, version, propertyRef, versionRange.toString() );
                    }
                }
            }
        }
        addDependencyAssocations( helper, expressionEvaluator, result, plugin.getDependencies(), true );
    }
}
 
Example 12
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 4 votes vote down vote up
private Artifact toArtifact(Plugin plugin) {
    return new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null, Constants.MAVEN_PLUGIN_TYPE, null, getArtifactHandler());
}
 
Example 13
Source File: ArtifactPluginWrapper.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
public ArtifactPluginWrapper( Plugin p )
{
    super (p.getGroupId(), p.getArtifactId(), p.getVersion(), null, null, null);
    this.original = p;
}
 
Example 14
Source File: IteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 4 votes vote down vote up
private boolean isPluginVersionDefined( Plugin plugin )
{
    return plugin.getVersion() != null;
}