diff options
author | Edwin L. Punzalan <epunzalan@apache.org> | 2006-03-16 02:57:41 +0000 |
---|---|---|
committer | Edwin L. Punzalan <epunzalan@apache.org> | 2006-03-16 02:57:41 +0000 |
commit | 859145b3df7bf6820b5bafa290b71c990936dfe7 (patch) | |
tree | 67480cda343749980d0b3a2d546fb2ad0acd4d15 | |
parent | c59ef6d44f31eda55192d12e17f3d19d06a0729d (diff) | |
download | archiva-859145b3df7bf6820b5bafa290b71c990936dfe7.tar.gz archiva-859145b3df7bf6820b5bafa290b71c990936dfe7.zip |
PR: MRM-105
executed cacheFailure configuration option
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@386244 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java | 249 |
1 files changed, 166 insertions, 83 deletions
diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java index bad33befb..a533b79ef 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java @@ -47,6 +47,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.ArrayList; /** * @author Edwin Punzalan @@ -81,6 +82,11 @@ public class DefaultProxyManager */ private Map repositoryLayoutMap; + /** + * A map + */ + private Map failuresCache = new HashMap(); + public void setConfiguration( ProxyConfiguration config ) { this.config = config; @@ -187,18 +193,79 @@ public class DefaultProxyManager if ( !artifactFile.exists() ) { - try + for ( Iterator iter = repositories.iterator(); iter.hasNext(); ) + { + ProxyRepository repository = (ProxyRepository) iter.next(); + try + { + if ( checkIfFailureCached( repository.pathOf( artifact ), repository ) ) + { + getLogger().debug( "Skipping repository " + repository.getKey() + + " for a cached path failure." ); + } + else + { + wagonManager.getArtifact( artifact, repository ); + } + } + catch ( TransferFailedException e ) + { + if ( repository.isHardfail() ) + { + throw new ProxyException( e.getMessage(), e ); + } + } + catch ( ResourceDoesNotExistException e ) + { + //handle the failure cache then throw exception as expected + doCacheFailure( repository.pathOf( artifact ), repository ); + + throw e; + } + } + } + } + + private void doCacheFailure( String path, ProxyRepository repository ) + { + if ( repository.isCacheFailures() ) + { + String key = repository.getKey(); + if ( !failuresCache.containsKey( key ) ) { - //@todo usage of repository cache period - wagonManager.getArtifact( artifact, repositories ); + failuresCache.put( key, new ArrayList() ); } - catch ( TransferFailedException e ) + + List failureCache = (List) failuresCache.get( key ); + if ( !failureCache.contains( path ) ) { - throw new ProxyException( e.getMessage(), e ); + failureCache.add( path ); } } } + private boolean checkIfFailureCached( String path, ProxyRepository repository ) + { + boolean pathAlreadyFailed = false; + + if ( repository.isCacheFailures() ) + { + String key = repository.getKey(); + + if ( failuresCache.containsKey( key ) ) + { + List failureCache = (List) failuresCache.get( key ); + + if ( failureCache.contains( path ) ) + { + pathAlreadyFailed = true; + } + } + } + + return pathAlreadyFailed; + } + private ArtifactRepositoryLayout getLayout() throws ProxyException { @@ -284,10 +351,6 @@ public class DefaultProxyManager private File getRepositoryFile( String path, List repositories, boolean useChecksum ) throws ResourceDoesNotExistException, ProxyException { - Map checksums = null; - Wagon wagon = null; - boolean connected = false; - ArtifactRepository cache = getRepositoryCache(); File target = new File( cache.getBasedir(), path ); @@ -295,101 +358,121 @@ public class DefaultProxyManager { ProxyRepository repository = (ProxyRepository) repos.next(); - try + if ( checkIfFailureCached( path, repository ) ) { - wagon = wagonManager.getWagon( repository.getProtocol() ); + getLogger().debug( "Skipping repository " + repository.getKey() + + " for a cached path failure." ); + } + else + { + getFromRepository( target, path, repository, useChecksum ); + } + } - //@todo configure wagonManager + if ( !target.exists() ) + { + throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." ); + } - if ( useChecksum ) - { - checksums = prepareChecksumListeners( wagon ); - } + return target; + } + + private void getFromRepository( File target, String path, ProxyRepository repository, boolean useChecksum ) + throws ProxyException + { + boolean connected = false; + Map checksums = null; + Wagon wagon = null; + + try + { + wagon = wagonManager.getWagon( repository.getProtocol() ); + + //@todo configure wagonManager + + if ( useChecksum ) + { + checksums = prepareChecksumListeners( wagon ); + } + + connected = connectToRepository( wagon, repository ); + if ( connected ) + { + File temp = new File( target.getAbsolutePath() + ".tmp" ); + temp.deleteOnExit(); - connected = connectToRepository( wagon, repository ); - if ( connected ) + int tries = 0; + boolean success = true; + + do { - File temp = new File( target.getAbsolutePath() + ".tmp" ); - temp.deleteOnExit(); + tries++; - int tries = 0; - boolean success = true; + getLogger().info( "Trying " + path + " from " + repository.getId() + "..." ); - do + if ( !target.exists() ) + { + wagon.get( path, temp ); + } + else { - tries++; - - getLogger().info( "Trying " + path + " from " + repository.getId() + "..." ); - - if ( !target.exists() ) - { - wagon.get( path, temp ); - } - else - { - long repoTimestamp = target.lastModified() + repository.getCachePeriod() * 1000; - wagon.getIfNewer( path, temp, repoTimestamp ); - } - - if ( useChecksum ) - { - success = doChecksumCheck( checksums, path, wagon ); - } - - if ( tries > 1 && !success ) - { - throw new ProxyException( "Checksum failures occurred while downloading " + path ); - } + long repoTimestamp = target.lastModified() + repository.getCachePeriod() * 1000; + wagon.getIfNewer( path, temp, repoTimestamp ); } - while ( !success ); - disconnectWagon( wagon ); + if ( useChecksum ) + { + success = doChecksumCheck( checksums, path, wagon ); + } - if ( temp.exists() ) + if ( tries > 1 && !success ) { - moveTempToTarget( temp, target ); + throw new ProxyException( "Checksum failures occurred while downloading " + path ); } + } + while ( !success ); - return target; + disconnectWagon( wagon ); + + if ( temp.exists() ) + { + moveTempToTarget( temp, target ); } - //try next repository - } - catch ( TransferFailedException e ) - { - String message = "Skipping repository " + repository.getUrl() + ": " + e.getMessage(); - processRepositoryFailure( repository, message, e ); } - catch ( ResourceDoesNotExistException e ) - { - //@todo usage for cacheFailure - //do nothing, file not found in this repository - } - catch ( AuthorizationException e ) - { - String message = "Skipping repository " + repository.getUrl() + ": " + e.getMessage(); - processRepositoryFailure( repository, message, e ); - } - catch ( UnsupportedProtocolException e ) + //try next repository + } + catch ( TransferFailedException e ) + { + String message = "Skipping repository " + repository.getUrl() + ": " + e.getMessage(); + processRepositoryFailure( repository, message, e ); + } + catch ( ResourceDoesNotExistException e ) + { + doCacheFailure( path, repository ); + } + catch ( AuthorizationException e ) + { + String message = "Skipping repository " + repository.getUrl() + ": " + e.getMessage(); + processRepositoryFailure( repository, message, e ); + } + catch ( UnsupportedProtocolException e ) + { + String message = "Skipping repository " + repository.getUrl() + ": no wagonManager configured " + + "for protocol " + repository.getProtocol(); + processRepositoryFailure( repository, message, e ); + } + finally + { + if ( wagon != null && checksums != null ) { - String message = "Skipping repository " + repository.getUrl() + ": no wagonManager configured " + - "for protocol " + repository.getProtocol(); - processRepositoryFailure( repository, message, e ); + releaseChecksumListeners( wagon, checksums ); } - finally - { - if ( wagon != null && checksums != null ) - { - releaseChecksumListeners( wagon, checksums ); - } - if ( connected ) - { - disconnectWagon( wagon ); - } + if ( connected ) + { + disconnectWagon( wagon ); } } - - throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." ); } /** |