diff options
author | Olivier Lamy <olamy@apache.org> | 2012-10-24 21:33:16 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-10-24 21:33:16 +0000 |
commit | 5f42d3dcac2229031a1276c69fc0d34e8ae4dbf7 (patch) | |
tree | 204ede4c273f7f178bf2678df94b6a7c218f6d5b | |
parent | a51724b013f4035bf06154266cf3ed0fce74c09e (diff) | |
download | archiva-5f42d3dcac2229031a1276c69fc0d34e8ae4dbf7.tar.gz archiva-5f42d3dcac2229031a1276c69fc0d34e8ae4dbf7.zip |
[MRM-1705] Feature to add custom parameters and/or headers when requesting an external repositories.
add parameters.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1401896 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 87 insertions, 8 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java index 788ae80fe..d9f1ea640 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -23,6 +23,7 @@ import com.google.common.io.Files; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.NetworkProxy; import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType; +import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; @@ -921,7 +922,7 @@ public class DefaultRepositoryProxyConnectors if ( !origFile.exists() ) { log.debug( "Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName() ); - wagon.get( remotePath, destFile ); + wagon.get( addParameters( remotePath, remoteRepository.getRepository() ), destFile ); success = true; // You wouldn't get here on failure, a WagonException would have been thrown. @@ -930,7 +931,8 @@ public class DefaultRepositoryProxyConnectors else { log.debug( "Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName() ); - success = wagon.getIfNewer( remotePath, destFile, origFile.lastModified() ); + success = wagon.getIfNewer( addParameters( remotePath, remoteRepository.getRepository() ), destFile, + origFile.lastModified() ); if ( !success ) { throw new NotModifiedException( @@ -1249,6 +1251,29 @@ public class DefaultRepositoryProxyConnectors } } + protected String addParameters( String path, RemoteRepository remoteRepository ) + { + if ( remoteRepository.getExtraParameters().isEmpty() ) + { + return path; + } + + boolean question = false; + + StringBuilder res = new StringBuilder( path == null ? "" : path ); + + for ( Entry<String, String> entry : remoteRepository.getExtraParameters().entrySet() ) + { + if ( !question ) + { + res.append( '?' ).append( entry.getKey() ).append( '=' ).append( entry.getValue() ); + } + } + + return res.toString(); + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { /* do nothing */ diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java index f8d9271c1..5c08d8d4b 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTask.java @@ -57,6 +57,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -168,7 +169,8 @@ public class DownloadRemoteIndexTask indexDirectory.mkdirs(); } - ResourceFetcher resourceFetcher = new WagonResourceFetcher( log, tempIndexDirectory, wagon ); + ResourceFetcher resourceFetcher = + new WagonResourceFetcher( log, tempIndexDirectory, wagon, remoteRepository ); IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher ); request.setForceFullUpdate( this.fullDownload ); request.setLocalIndexCacheDir( indexCacheDirectory ); @@ -295,11 +297,15 @@ public class DownloadRemoteIndexTask Wagon wagon; - private WagonResourceFetcher( Logger log, File tempIndexDirectory, Wagon wagon ) + RemoteRepository remoteRepository; + + private WagonResourceFetcher( Logger log, File tempIndexDirectory, Wagon wagon, + RemoteRepository remoteRepository ) { this.log = log; this.tempIndexDirectory = tempIndexDirectory; this.wagon = wagon; + this.remoteRepository = remoteRepository; } public void connect( String id, String url ) @@ -326,7 +332,7 @@ public class DownloadRemoteIndexTask file.delete(); } file.deleteOnExit(); - wagon.get( name, file ); + wagon.get( addParameters( name, this.remoteRepository ), file ); return new FileInputStream( file ); } catch ( AuthorizationException e ) @@ -342,7 +348,33 @@ public class DownloadRemoteIndexTask throw new FileNotFoundException( e.getMessage() ); } } + + // FIXME remove crappy copy/paste + protected String addParameters( String path, RemoteRepository remoteRepository ) + { + if ( remoteRepository.getExtraParameters().isEmpty() ) + { + return path; + } + + boolean question = false; + + StringBuilder res = new StringBuilder( path == null ? "" : path ); + + for ( Map.Entry<String, String> entry : remoteRepository.getExtraParameters().entrySet() ) + { + if ( !question ) + { + res.append( '?' ).append( entry.getKey() ).append( '=' ).append( entry.getValue() ); + } + } + + return res.toString(); + } + } + + } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java index 2c7bfb2b8..934cb33f6 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java @@ -262,7 +262,7 @@ public class RepositoryModelResolver String metadataPath = StringUtils.substringBeforeLast( artifactPath, "/" ) + "/" + METADATA_FILENAME; - wagon.get( metadataPath, tmpMetadataResource ); + wagon.get( addParameters( metadataPath, remoteRepository ), tmpMetadataResource ); log.debug( "Successfully downloaded metadata." ); @@ -288,7 +288,7 @@ public class RepositoryModelResolver log.info( "Retrieving {} from {}", artifactPath, remoteRepository.getName() ); - wagon.get( artifactPath, tmpResource ); + wagon.get( addParameters( artifactPath, remoteRepository ), tmpResource ); log.debug( "Downloaded successfully." ); @@ -426,7 +426,7 @@ public class RepositoryModelResolver log.info( "Retrieving {} from {}", remotePath, remoteRepository.getName() ); - wagon.get( remotePath, destFile ); + wagon.get( addParameters( remotePath, remoteRepository ), destFile ); log.debug( "Downloaded successfully." ); @@ -485,4 +485,26 @@ public class RepositoryModelResolver } } } + + protected String addParameters( String path, RemoteRepository remoteRepository ) + { + if ( remoteRepository.getExtraParameters().isEmpty() ) + { + return path; + } + + boolean question = false; + + StringBuilder res = new StringBuilder( path == null ? "" : path ); + + for ( Map.Entry<String, String> entry : remoteRepository.getExtraParameters().entrySet() ) + { + if ( !question ) + { + res.append( '?' ).append( entry.getKey() ).append( '=' ).append( entry.getValue() ); + } + } + + return res.toString(); + } } |