String version = artifact.getVersion();
if (!LATEST.equals(version))
return delegate.resolveVersion(session,request);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
VersionResult result = new VersionResult( request );
Metadata metadata =
new DefaultMetadata( artifact.getGroupId(), artifact.getArtifactId(), MAVEN_METADATA_XML,
Metadata.Nature.RELEASE_OR_SNAPSHOT );
List<MetadataRequest> metadataRequests = new ArrayList<MetadataRequest>(request.getRepositories().size());
metadataRequests.add( new MetadataRequest( metadata, null, request.getRequestContext() ) );
for ( RemoteRepository repository : request.getRepositories() )
{
MetadataRequest metadataRequest =
new MetadataRequest( metadata, repository, request.getRequestContext() );
metadataRequest.setDeleteLocalCopyIfMissing( true );
metadataRequest.setFavorLocalRepository( true );
metadataRequest.setTrace( trace );
metadataRequests.add( metadataRequest );
}
List<MetadataResult> metadataResults = metadataResolver.resolveMetadata( session, metadataRequests );
List<VersionInfo> infos = new ArrayList<VersionInfo>();
for (MetadataResult metadataResult : metadataResults) {
result.addException(metadataResult.getException());
ArtifactRepository repository = metadataResult.getRequest().getRepository();
if (repository == null) {
repository = session.getLocalRepository();
}
Versioning versioning = readVersions(session, trace, metadataResult.getMetadata(), repository, result);
merge(versioning, repository, infos);
}
VersionInfo latest = findLatest(infos);
if (latest!=null) {
result.setRepository(latest.repository);
result.setVersion(latest.version.toString());
}
if (latest != null && latest.version.toString().endsWith(SNAPSHOT)) {
VersionRequest subRequest = new VersionRequest();
subRequest.setArtifact(artifact.setVersion(result.getVersion()));
if (result.getRepository() instanceof RemoteRepository) {
subRequest.setRepositories(Collections.singletonList((RemoteRepository) result.getRepository()));
} else {
subRequest.setRepositories(request.getRepositories());
}
VersionResult subResult = resolveVersion(session, subRequest);
result.setVersion(subResult.getVersion());
result.setRepository(subResult.getRepository());
for (Exception exception : subResult.getExceptions()) {
result.addException(exception);
}
}
if ( StringUtils.isEmpty(result.getVersion()) )