}
public void resolve( RepositoryMetadata metadata, RepositoryRequest request )
throws RepositoryMetadataResolutionException
{
RepositoryCache cache = request.getCache();
CacheKey cacheKey = null;
if ( cache != null )
{
cacheKey = new CacheKey( metadata, request );
CacheRecord cacheRecord = (CacheRecord) cache.get( request, cacheKey );
if ( cacheRecord != null )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Resolved metadata from cache: " + metadata + " @ " + cacheRecord.repository );
}
metadata.setMetadata( MetadataUtils.cloneMetadata( cacheRecord.metadata ) );
if ( cacheRecord.repository != null )
{
for ( ArtifactRepository repository : request.getRemoteRepositories() )
{
if ( cacheRecord.repository.equals( repository.getId() ) )
{
metadata.setRepository( repository );
break;
}
}
}
return;
}
}
ArtifactRepository localRepository = request.getLocalRepository();
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
if ( !request.isOffline() )
{
Date localCopyLastModified = getLocalCopyLastModified( localRepository, metadata );
for ( ArtifactRepository repository : remoteRepositories )
{
ArtifactRepositoryPolicy policy = metadata.getPolicy( repository );
File file =
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata,
repository ) );
boolean update;
if ( !policy.isEnabled() )
{
update = false;
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Skipping update check for " + metadata.getKey() + " (" + file
+ ") from disabled repository " + repository.getId() + " ("
+ repository.getUrl() + ")" );
}
}
else if ( request.isForceUpdate() )
{
update = true;
}
else if ( localCopyLastModified != null && !policy.checkOutOfDate( localCopyLastModified ) )
{
update = false;
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Skipping update check for " + metadata.getKey() + " (" + file
+ ") from repository " + repository.getId() + " (" + repository.getUrl()
+ ") in favor of local copy" );
}
}
else if ( updateCheckManager.isUpdateRequired( metadata, repository, file ) )
{
update = true;
}
else
{
update = false;
}
if ( update )
{
getLogger().info( metadata.getKey() + ": checking for updates from " + repository.getId() );
try
{
wagonManager.getArtifactMetadata( metadata, repository, file, policy.getChecksumPolicy() );
}
catch ( ResourceDoesNotExistException e )
{
getLogger().debug( metadata + " could not be found on repository: " + repository.getId() );
// delete the local copy so the old details aren't used.
if ( file.exists() )
{
file.delete();
}
}
catch ( TransferFailedException e )
{
getLogger().warn( metadata + " could not be retrieved from repository: " + repository.getId()
+ " due to an error: " + e.getMessage() );
getLogger().debug( "Exception", e );
}
finally
{
updateCheckManager.touch( metadata, repository, file );
}
}
// TODO: should this be inside the above check?
// touch file so that this is not checked again until interval has passed
if ( file.exists() )
{
file.setLastModified( System.currentTimeMillis() );
}
}
}
try
{
mergeMetadata( metadata, remoteRepositories, localRepository );
}
catch ( RepositoryMetadataStoreException e )
{
throw new RepositoryMetadataResolutionException( "Unable to store local copy of metadata: " + e.getMessage(), e );
}
if ( cache != null )
{
cache.put( request, cacheKey, new CacheRecord( metadata ) );
}
}