private String resolveMetaVersion()

in maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java [656:764]


    private String resolveMetaVersion( String groupId, String artifactId, MavenProject project,
                                       ArtifactRepository localRepository, String metaVersionId )
        throws PluginVersionResolutionException, InvalidPluginException
    {
        Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId );

        String key = artifact.getDependencyConflictId();
        if ( resolvedMetaVersions.containsKey( key ) )
        {
            return (String) resolvedMetaVersions.get( key );
        }

        String version = null;

        // This takes the spec version and resolves a real version
        try
        {
            ResolutionGroup resolutionGroup =
                artifactMetadataSource.retrieve( artifact, localRepository, project.getPluginArtifactRepositories() );

            // switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom
            // artifact.
            artifact = resolutionGroup.getPomArtifact();
        }
        catch ( ArtifactMetadataRetrievalException e )
        {
            throw new PluginVersionResolutionException( groupId, artifactId, e.getMessage(), e );
        }

        String artifactVersion = artifact.getVersion();

        // make sure this artifact was actually resolved to a file in the repo...
        if ( artifact.getFile() != null )
        {
            boolean pluginValid = false;

            while ( !pluginValid && artifactVersion != null )
            {
                pluginValid = true;
                MavenProject pluginProject;
                try
                {
                    artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion );
                    pluginProject = mavenProjectBuilder.buildFromRepository( artifact,
                                                                             project.getPluginArtifactRepositories(),
                                                                             localRepository, false );
                }
                catch ( ProjectBuildingException e )
                {
                    throw new InvalidPluginException( "Unable to build project information for plugin '"
                        + ArtifactUtils.versionlessKey( groupId, artifactId ) + "': " + e.getMessage(), e );
                }

                // if we don't have the required Maven version, then ignore an update
                if ( pluginProject.getPrerequisites() != null && pluginProject.getPrerequisites().getMaven() != null )
                {
                    DefaultArtifactVersion requiredVersion =
                        new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );

                    if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 )
                    {
                        getLogger().info( "Ignoring available plugin update: " + artifactVersion
                            + " as it requires Maven version " + requiredVersion );

                        VersionRange vr;
                        try
                        {
                            vr = VersionRange.createFromVersionSpec( "(," + artifactVersion + ")" );
                        }
                        catch ( InvalidVersionSpecificationException e )
                        {
                            throw new PluginVersionResolutionException( groupId, artifactId,
                                                                        "Error getting available plugin versions: "
                                                                            + e.getMessage(), e );
                        }

                        getLogger().debug( "Trying " + vr );
                        try
                        {
                            List versions = artifactMetadataSource.retrieveAvailableVersions( artifact, localRepository,
                                                                                              project.getPluginArtifactRepositories() );
                            ArtifactVersion v = vr.matchVersion( versions );
                            artifactVersion = v != null ? v.toString() : null;
                        }
                        catch ( ArtifactMetadataRetrievalException e )
                        {
                            throw new PluginVersionResolutionException( groupId, artifactId,
                                                                        "Error getting available plugin versions: "
                                                                            + e.getMessage(), e );
                        }

                        if ( artifactVersion != null )
                        {
                            getLogger().debug( "Found " + artifactVersion );
                            pluginValid = false;
                        }
                    }
                }
            }
        }

        if ( !metaVersionId.equals( artifactVersion ) )
        {
            version = artifactVersion;
            resolvedMetaVersions.put( key, version );
        }

        return version;
    }