[MNG-4317] [regression] g:a level metadata is not properly processed when resolving plugin version

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@807140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-24 10:14:21 +00:00
parent 2b5054a347
commit 61e9292993
1 changed files with 68 additions and 56 deletions

View File

@ -64,32 +64,24 @@ public class DefaultPluginVersionResolver
{ {
DefaultPluginVersionResult result = new DefaultPluginVersionResult(); DefaultPluginVersionResult result = new DefaultPluginVersionResult();
Throwable error = null; Metadata mergedMetadata = new Metadata();
ArtifactRepository localRepository = request.getLocalRepository(); ArtifactRepository localRepository = request.getLocalRepository();
File artifactMetadataFile = null;
String localPath;
// Search in remote repositories for a (released) version. // Search in remote repositories for a (released) version.
// //
// maven-metadata-{central|nexus|...}.xml // maven-metadata-{central|nexus|...}.xml
// //
// TODO: we should cycle through the repositories but take the repository which actually // TODO: we should cycle through the repositories but take the repository which actually satisfied the prefix.
// satisfied the prefix.
for ( ArtifactRepository repository : request.getRemoteRepositories() ) for ( ArtifactRepository repository : request.getRemoteRepositories() )
{ {
localPath = String localPath = getLocalMetadataPath( request, repository );
request.getGroupId().replace( '.', '/' ) + "/" + request.getArtifactId() + "/maven-metadata-"
+ repository.getId() + ".xml";
artifactMetadataFile = new File( localRepository.getBasedir(), localPath ); File artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
if ( !request.isOffline() && !artifactMetadataFile.exists() /* || user requests snapshot updates */) if ( !request.isOffline() && ( !artifactMetadataFile.exists() /* || user requests snapshot updates */) )
{ {
String remotePath = String remotePath = getRemoteMetadataPath( request, repository );
request.getGroupId().replace( '.', '/' ) + "/" + request.getArtifactId() + "/maven-metadata.xml";
try try
{ {
@ -97,8 +89,6 @@ public class DefaultPluginVersionResolver
} }
catch ( TransferFailedException e ) catch ( TransferFailedException e )
{ {
error = e;
if ( logger.isDebugEnabled() ) if ( logger.isDebugEnabled() )
{ {
logger.warn( "Failed to retrieve " + remotePath + ": " + e.getMessage(), e ); logger.warn( "Failed to retrieve " + remotePath + ": " + e.getMessage(), e );
@ -116,38 +106,30 @@ public class DefaultPluginVersionResolver
} }
} }
if ( mergeMetadata( mergedMetadata, artifactMetadataFile ) )
{
result.setRepository( repository ); result.setRepository( repository );
}
break;
} }
// Search in the local repositiory for a (development) version // Search in the local repositiory for a (development) version
// //
// maven-metadata-local.xml // maven-metadata-local.xml
// //
if ( artifactMetadataFile == null || !artifactMetadataFile.exists() )
{ {
localPath = String localPath = getLocalMetadataPath( request, localRepository );
request.getGroupId().replace( '.', '/' ) + "/" + request.getArtifactId() + "/maven-metadata-"
+ localRepository.getId() + ".xml";
artifactMetadataFile = new File( localRepository.getBasedir(), localPath ); File artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
if ( mergeMetadata( mergedMetadata, artifactMetadataFile ) )
{
result.setRepository( localRepository ); result.setRepository( localRepository );
} }
}
if ( artifactMetadataFile.exists() ) if ( mergedMetadata.getVersioning() != null )
{ {
logger.debug( "Extracting version for plugin " + request.getGroupId() + ':' + request.getArtifactId() String release = mergedMetadata.getVersioning().getRelease();
+ " from " + artifactMetadataFile );
try
{
Metadata pluginMetadata = readMetadata( artifactMetadataFile );
if ( pluginMetadata.getVersioning() != null )
{
String release = pluginMetadata.getVersioning().getRelease();
if ( StringUtils.isNotEmpty( release ) ) if ( StringUtils.isNotEmpty( release ) )
{ {
@ -155,7 +137,7 @@ public class DefaultPluginVersionResolver
} }
else else
{ {
String latest = pluginMetadata.getVersioning().getLatest(); String latest = mergedMetadata.getVersioning().getLatest();
if ( StringUtils.isNotEmpty( latest ) ) if ( StringUtils.isNotEmpty( latest ) )
{ {
@ -163,18 +145,6 @@ public class DefaultPluginVersionResolver
} }
} }
} }
}
catch ( RepositoryMetadataReadException e )
{
throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(),
e.getMessage(), e );
}
}
else if ( error != null )
{
throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(),
error.getMessage(), error );
}
if ( StringUtils.isEmpty( result.getVersion() ) ) if ( StringUtils.isEmpty( result.getVersion() ) )
{ {
@ -185,6 +155,48 @@ public class DefaultPluginVersionResolver
return result; return result;
} }
private String getLocalMetadataPath( PluginVersionRequest request, ArtifactRepository repository )
{
return request.getGroupId().replace( '.', '/' ) + '/' + request.getArtifactId() + "/maven-metadata-"
+ repository.getId() + ".xml";
}
private String getRemoteMetadataPath( PluginVersionRequest request, ArtifactRepository repository )
{
return request.getGroupId().replace( '.', '/' ) + '/' + request.getArtifactId() + "/maven-metadata.xml";
}
private boolean mergeMetadata( Metadata target, File metadataFile )
{
if ( metadataFile.isFile() )
{
try
{
Metadata repoMetadata = readMetadata( metadataFile );
return mergeMetadata( target, repoMetadata );
}
catch ( RepositoryMetadataReadException e )
{
if ( logger.isDebugEnabled() )
{
logger.warn( "Failed to read metadata " + metadataFile + ": " + e.getMessage(), e );
}
else
{
logger.warn( "Failed to read metadata " + metadataFile + ": " + e.getMessage() );
}
}
}
return false;
}
private boolean mergeMetadata( Metadata target, Metadata source )
{
return target.merge( source );
}
private Metadata readMetadata( File mappingFile ) private Metadata readMetadata( File mappingFile )
throws RepositoryMetadataReadException throws RepositoryMetadataReadException
{ {