[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
This commit is contained in:
Olivier Lamy 2012-10-24 21:33:16 +00:00
parent a51724b013
commit 5f42d3dcac
3 changed files with 87 additions and 8 deletions

View File

@ -23,6 +23,7 @@
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 @@ private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepo
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 @@ private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepo
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 void afterConfigurationChange( Registry registry, String propertyName, Ob
}
}
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 */

View File

@ -57,6 +57,7 @@
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @author Olivier Lamy
@ -168,7 +169,8 @@ public void run()
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 @@ private static class WagonResourceFetcher
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 InputStream retrieve( String name )
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 InputStream retrieve( String name )
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();
}
}
}

View File

@ -262,7 +262,7 @@ private boolean getModelFromProxy( RemoteRepository remoteRepository, String gro
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 @@ private boolean getModelFromProxy( RemoteRepository remoteRepository, String gro
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 @@ private File transferChecksum( Wagon wagon, RemoteRepository remoteRepository, S
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 @@ private void moveFileIfExists( File fileToMove, File directory )
}
}
}
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();
}
}