mirror of https://github.com/apache/maven.git
if the plugin version is not working with this version of Maven, rollback until one is found.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
156464c205
commit
c74d08fa48
|
@ -23,7 +23,10 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
|||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
import org.apache.maven.execution.RuntimeInformation;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
|
@ -52,6 +55,7 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DefaultPluginVersionManager
|
||||
|
@ -73,6 +77,9 @@ public class DefaultPluginVersionManager
|
|||
|
||||
private RuntimeInformation runtimeInformation;
|
||||
|
||||
// TODO: Revisit to remove this piece of state. PLUGIN REGISTRY MAY BE UPDATED ON DISK OUT-OF-PROCESS!
|
||||
private Map resolvedMetaVersions = new HashMap();
|
||||
|
||||
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
|
||||
ArtifactRepository localRepository )
|
||||
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
|
||||
|
@ -648,6 +655,12 @@ public class DefaultPluginVersionManager
|
|||
{
|
||||
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
|
||||
|
@ -665,12 +678,20 @@ public class DefaultPluginVersionManager
|
|||
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 );
|
||||
|
@ -681,8 +702,6 @@ public class DefaultPluginVersionManager
|
|||
ArtifactUtils.versionlessKey( groupId, artifactId ) + "': " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
boolean pluginValid = true;
|
||||
|
||||
// if we don't have the required Maven version, then ignore an update
|
||||
if ( pluginProject.getPrerequisites() != null && pluginProject.getPrerequisites().getMaven() != null )
|
||||
{
|
||||
|
@ -691,18 +710,50 @@ public class DefaultPluginVersionManager
|
|||
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 )
|
||||
{
|
||||
getLogger().info( "Ignoring available plugin update: " + artifact.getVersion() +
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String artifactVersion = artifact.getVersion();
|
||||
|
||||
if ( pluginValid && !metaVersionId.equals( artifactVersion ) )
|
||||
if ( !metaVersionId.equals( artifactVersion ) )
|
||||
{
|
||||
version = artifactVersion;
|
||||
}
|
||||
resolvedMetaVersions.put( key, version );
|
||||
}
|
||||
|
||||
return version;
|
||||
|
|
Loading…
Reference in New Issue