{
logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() );
DefaultPluginVersionResult result = new DefaultPluginVersionResult();
Metadata mergedMetadata = new Metadata();
ArtifactRepository localRepository = request.getLocalRepository();
// Search in remote repositories for a (released) version.
//
// maven-metadata-{central|nexus|...}.xml
//
// TODO: we should cycle through the repositories but take the repository which actually satisfied the prefix.
for ( ArtifactRepository repository : request.getRemoteRepositories() )
{
String localPath = getLocalMetadataPath( request, repository );
File artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
if ( !request.isOffline() && ( !artifactMetadataFile.exists() /* || user requests snapshot updates */) )
{
String remotePath = getRemoteMetadataPath( request, repository );
try
{
repositorySystem.retrieve( repository, artifactMetadataFile, remotePath,
request.getTransferListener() );
}
catch ( ArtifactTransferFailedException e )
{
if ( logger.isDebugEnabled() )
{
logger.warn( "Failed to retrieve " + remotePath + ": " + e.getMessage(), e );
}
else
{
logger.warn( "Failed to retrieve " + remotePath + ": " + e.getMessage() );
}
continue;
}
catch ( ArtifactDoesNotExistException e )
{
continue;
}
}
if ( mergeMetadata( mergedMetadata, artifactMetadataFile ) )
{
result.setRepository( repository );
}
}
// Search in the local repositiory for a (development) version
//
// maven-metadata-local.xml
//
{
String localPath = getLocalMetadataPath( request, localRepository );
File artifactMetadataFile = new File( localRepository.getBasedir(), localPath );
if ( mergeMetadata( mergedMetadata, artifactMetadataFile ) )
{
result.setRepository( localRepository );
}
}
if ( mergedMetadata.getVersioning() != null )
{
String release = mergedMetadata.getVersioning().getRelease();
if ( StringUtils.isNotEmpty( release ) )
{
result.setVersion( release );
}
else
{
String latest = mergedMetadata.getVersioning().getLatest();
if ( StringUtils.isNotEmpty( latest ) )
{
result.setVersion( latest );
}