only create the working directory at the point it is needed

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755844 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-03-19 06:09:14 +00:00
parent e5ce444a9c
commit 6095cf8484
1 changed files with 352 additions and 367 deletions

View File

@ -76,7 +76,8 @@ import org.slf4j.LoggerFactory;
* DefaultRepositoryProxyConnectors * DefaultRepositoryProxyConnectors
* *
* @version $Id$ * @version $Id$
* @todo exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than your average brown onion * @todo exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than
* your average brown onion
* @plexus.component role-hint="default" * @plexus.component role-hint="default"
*/ */
public class DefaultRepositoryProxyConnectors public class DefaultRepositoryProxyConnectors
@ -135,9 +136,6 @@ public class DefaultRepositoryProxyConnectors
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
throws ProxyDownloadException throws ProxyDownloadException
{
File workingDirectory = createWorkingDirectory(repository);
try
{ {
File localFile = toLocalFile( repository, artifact ); File localFile = toLocalFile( repository, artifact );
@ -150,7 +148,7 @@ public class DefaultRepositoryProxyConnectors
Map<String, Exception> previousExceptions = new LinkedHashMap<String, Exception>(); Map<String, Exception> previousExceptions = new LinkedHashMap<String, Exception>();
for ( ProxyConnector connector : connectors ) for ( ProxyConnector connector : connectors )
{ {
if (connector.isDisabled()) if ( connector.isDisabled() )
{ {
continue; continue;
} }
@ -163,7 +161,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
File downloadedFile = File downloadedFile =
transferFile( connector, targetRepository, targetPath, repository, workingDirectory, localFile, requestProperties, transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
true ); true );
if ( fileExists( downloadedFile ) ) if ( fileExists( downloadedFile ) )
@ -196,19 +194,11 @@ public class DefaultRepositoryProxyConnectors
} }
log.debug( "Exhausted all target repositories, artifact " + Keys.toKey( artifact ) + " not found." ); log.debug( "Exhausted all target repositories, artifact " + Keys.toKey( artifact ) + " not found." );
}
finally
{
FileUtils.deleteQuietly(workingDirectory);
}
return null; return null;
} }
public File fetchFromProxies( ManagedRepositoryContent repository, String path ) public File fetchFromProxies( ManagedRepositoryContent repository, String path )
{
File workingDir = createWorkingDirectory(repository);
try
{ {
File localFile = new File( repository.getRepoRoot(), path ); File localFile = new File( repository.getRepoRoot(), path );
@ -225,7 +215,7 @@ public class DefaultRepositoryProxyConnectors
List<ProxyConnector> connectors = getProxyConnectors( repository ); List<ProxyConnector> connectors = getProxyConnectors( repository );
for ( ProxyConnector connector : connectors ) for ( ProxyConnector connector : connectors )
{ {
if (connector.isDisabled()) if ( connector.isDisabled() )
{ {
continue; continue;
} }
@ -238,7 +228,8 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
File downloadedFile = File downloadedFile =
transferFile( connector, targetRepository, targetPath, repository, workingDir, localFile, requestProperties, false ); transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
false );
if ( fileExists( downloadedFile ) ) if ( fileExists( downloadedFile ) )
{ {
@ -265,21 +256,13 @@ public class DefaultRepositoryProxyConnectors
} }
log.debug( "Exhausted all target repositories, resource " + path + " not found." ); log.debug( "Exhausted all target repositories, resource " + path + " not found." );
}
finally
{
FileUtils.deleteQuietly(workingDir);
}
return null; return null;
} }
public File fetchMetatadaFromProxies(ManagedRepositoryContent repository, String logicalPath) public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath )
{ {
File workingDir = createWorkingDirectory(repository); File localFile = new File( repository.getRepoRoot(), logicalPath );
try
{
File localFile = new File(repository.getRepoRoot(), logicalPath);
Properties requestProperties = new Properties(); Properties requestProperties = new Properties();
requestProperties.setProperty( "filetype", "metadata" ); requestProperties.setProperty( "filetype", "metadata" );
@ -289,7 +272,7 @@ public class DefaultRepositoryProxyConnectors
List<ProxyConnector> connectors = getProxyConnectors( repository ); List<ProxyConnector> connectors = getProxyConnectors( repository );
for ( ProxyConnector connector : connectors ) for ( ProxyConnector connector : connectors )
{ {
if (connector.isDisabled()) if ( connector.isDisabled() )
{ {
continue; continue;
} }
@ -301,7 +284,8 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
transferFile( connector, targetRepository, logicalPath, repository, workingDir, localRepoFile, requestProperties, true ); transferFile( connector, targetRepository, logicalPath, repository, localRepoFile, requestProperties,
true );
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
{ {
@ -310,21 +294,19 @@ public class DefaultRepositoryProxyConnectors
} }
catch ( NotFoundException e ) catch ( NotFoundException e )
{ {
log.debug( "Metadata " + logicalPath log.debug( "Metadata " + logicalPath + " not found on remote repository \""
+ " not found on remote repository \""
+ targetRepository.getRepository().getId() + "\".", e ); + targetRepository.getRepository().getId() + "\".", e );
} }
catch ( NotModifiedException e ) catch ( NotModifiedException e )
{ {
log.debug( "Metadata " + logicalPath log.debug( "Metadata " + logicalPath + " not updated on remote repository \""
+ " not updated on remote repository \""
+ targetRepository.getRepository().getId() + "\".", e ); + targetRepository.getRepository().getId() + "\".", e );
} }
catch ( ProxyException e ) catch ( ProxyException e )
{ {
log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() + log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId()
"\" for versioned Metadata " + logicalPath + + "\" for versioned Metadata " + logicalPath + ", continuing to next repository. Error message: "
", continuing to next repository. Error message: " + e.getMessage() ); + e.getMessage() );
log.debug( "Full stack trace", e ); log.debug( "Full stack trace", e );
} }
} }
@ -334,7 +316,7 @@ public class DefaultRepositoryProxyConnectors
metadataNeedsUpdating = true; metadataNeedsUpdating = true;
} }
if ( metadataNeedsUpdating || !localFile.exists()) if ( metadataNeedsUpdating || !localFile.exists() )
{ {
try try
{ {
@ -350,11 +332,6 @@ public class DefaultRepositoryProxyConnectors
{ {
return localFile; return localFile;
} }
}
finally
{
FileUtils.deleteQuietly(workingDir);
}
return null; return null;
} }
@ -441,12 +418,12 @@ public class DefaultRepositoryProxyConnectors
* @param executeConsumers whether to execute the consumers after proxying * @param executeConsumers whether to execute the consumers after proxying
* @return the local file that was downloaded, or null if not downloaded. * @return the local file that was downloaded, or null if not downloaded.
* @throws NotFoundException if the file was not found on the remote repository. * @throws NotFoundException if the file was not found on the remote repository.
* @throws NotModifiedException if the localFile was present, and the resource was present on remote repository, * @throws NotModifiedException if the localFile was present, and the resource was present on remote repository, but
* but the remote resource is not newer than the local File. * the remote resource is not newer than the local File.
* @throws ProxyException if transfer was unsuccessful. * @throws ProxyException if transfer was unsuccessful.
*/ */
private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File workingDirectory, File resource, Properties requestProperties, ManagedRepositoryContent repository, File resource, Properties requestProperties,
boolean executeConsumers ) boolean executeConsumers )
throws ProxyException, NotModifiedException throws ProxyException, NotModifiedException
{ {
@ -464,9 +441,9 @@ public class DefaultRepositoryProxyConnectors
// Path must belong to whitelist. // Path must belong to whitelist.
if ( !matchesPattern( remotePath, connector.getWhitelist() ) ) if ( !matchesPattern( remotePath, connector.getWhitelist() ) )
{ {
log.debug( "Path [" + remotePath + log.debug( "Path [" + remotePath
"] is not part of defined whitelist (skipping transfer from repository [" + + "] is not part of defined whitelist (skipping transfer from repository ["
remoteRepository.getRepository().getName() + "])." ); + remoteRepository.getRepository().getName() + "])." );
return null; return null;
} }
} }
@ -474,8 +451,8 @@ public class DefaultRepositoryProxyConnectors
// Is target path part of blacklist? // Is target path part of blacklist?
if ( matchesPattern( remotePath, connector.getBlacklist() ) ) if ( matchesPattern( remotePath, connector.getBlacklist() ) )
{ {
log.debug( "Path [" + remotePath + "] is part of blacklist (skipping transfer from repository [" + log.debug( "Path [" + remotePath + "] is part of blacklist (skipping transfer from repository ["
remoteRepository.getRepository().getName() + "])." ); + remoteRepository.getRepository().getName() + "])." );
return null; return null;
} }
@ -501,6 +478,9 @@ public class DefaultRepositoryProxyConnectors
File tmpSha1 = null; File tmpSha1 = null;
File tmpResource = null; File tmpResource = null;
File workingDirectory = createWorkingDirectory( repository );
try
{
Wagon wagon = null; Wagon wagon = null;
try try
{ {
@ -515,12 +495,18 @@ public class DefaultRepositoryProxyConnectors
boolean connected = connectToRepository( connector, wagon, remoteRepository ); boolean connected = connectToRepository( connector, wagon, remoteRepository );
if ( connected ) if ( connected )
{ {
tmpResource = transferSimpleFile( wagon, remoteRepository, remotePath, repository, workingDirectory, resource ); tmpResource = new File( workingDirectory, resource.getName() );
transferSimpleFile( wagon, remoteRepository, remotePath, repository, resource, tmpResource );
// TODO: these should be used to validate the download based on the policies, not always downloaded to // TODO: these should be used to validate the download based on the policies, not always downloaded
// to
// save on connections since md5 is rarely used // save on connections since md5 is rarely used
tmpSha1 = transferChecksum( wagon, remoteRepository, remotePath, repository, workingDirectory, resource, ".sha1" ); tmpSha1 =
tmpMd5 = transferChecksum( wagon, remoteRepository, remotePath, repository, workingDirectory, resource, ".md5" ); transferChecksum( wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
".sha1" );
tmpMd5 =
transferChecksum( wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
".md5" );
} }
} }
catch ( NotFoundException e ) catch ( NotFoundException e )
@ -568,16 +554,21 @@ public class DefaultRepositoryProxyConnectors
} }
} }
if (resource != null) if ( resource != null )
{ {
synchronized (resource.getAbsolutePath().intern()) synchronized ( resource.getAbsolutePath().intern() )
{ {
File directory = resource.getParentFile(); File directory = resource.getParentFile();
moveFileIfExists(tmpMd5, directory); moveFileIfExists( tmpMd5, directory );
moveFileIfExists(tmpSha1, directory); moveFileIfExists( tmpSha1, directory );
moveFileIfExists(tmpResource, directory); moveFileIfExists( tmpResource, directory );
} }
} }
}
finally
{
FileUtils.deleteQuietly( workingDirectory );
}
if ( executeConsumers ) if ( executeConsumers )
{ {
@ -588,20 +579,19 @@ public class DefaultRepositoryProxyConnectors
return resource; return resource;
} }
/** /**
* Moves the file into repository location if it exists * Moves the file into repository location if it exists
* *
* @param fileToMove this could be either the main artifact, sha1 or md5 checksum file. * @param fileToMove this could be either the main artifact, sha1 or md5 checksum file.
* @param directory directory to write files to * @param directory directory to write files to
*/ */
private void moveFileIfExists(File fileToMove, File directory) throws ProxyException private void moveFileIfExists( File fileToMove, File directory )
throws ProxyException
{ {
if (fileToMove != null && fileToMove.exists()) if ( fileToMove != null && fileToMove.exists() )
{ {
File newLocation = new File(directory, fileToMove.getName()); File newLocation = new File( directory, fileToMove.getName() );
moveTempToTarget(fileToMove, newLocation); moveTempToTarget( fileToMove, newLocation );
} }
} }
@ -619,27 +609,27 @@ public class DefaultRepositoryProxyConnectors
* @throws ProxyException if copying the downloaded file into place did not succeed. * @throws ProxyException if copying the downloaded file into place did not succeed.
*/ */
private File transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private File transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File workingDirectory, File localFile, String type ) ManagedRepositoryContent repository, File resource, File tmpDirectory, String ext )
throws ProxyException throws ProxyException
{ {
File hashFile = new File( localFile.getAbsolutePath() + type ); String url = remoteRepository.getURL().getUrl() + remotePath + ext;
File tmpChecksum = new File(workingDirectory, hashFile.getName());
String url = remoteRepository.getURL().getUrl() + remotePath;
// Transfer checksum does not use the policy. // Transfer checksum does not use the policy.
if ( urlFailureCache.hasFailedBefore( url + type ) ) if ( urlFailureCache.hasFailedBefore( url ) )
{ {
return null; return null;
} }
File destFile = new File( tmpDirectory, resource.getName() + ext );
try try
{ {
transferSimpleFile( wagon, remoteRepository, remotePath + type, repository, workingDirectory, hashFile ); transferSimpleFile( wagon, remoteRepository, remotePath + ext, repository, resource, destFile );
log.debug( "Checksum" + type + " Downloaded: " + hashFile ); log.debug( "Checksum " + url + " Downloaded: " + destFile + " to move to " + resource );
} }
catch ( NotFoundException e ) catch ( NotFoundException e )
{ {
urlFailureCache.cacheFailure( url + type ); urlFailureCache.cacheFailure( url );
log.debug( "Transfer failed, checksum not found: " + url ); log.debug( "Transfer failed, checksum not found: " + url );
// Consume it, do not pass this on. // Consume it, do not pass this on.
} }
@ -650,12 +640,12 @@ public class DefaultRepositoryProxyConnectors
} }
catch ( ProxyException e ) catch ( ProxyException e )
{ {
urlFailureCache.cacheFailure( url + type ); urlFailureCache.cacheFailure( url );
log.warn( "Transfer failed on checksum: " + url + " : " + e.getMessage(), e ); log.warn( "Transfer failed on checksum: " + url + " : " + e.getMessage(), e );
// Critical issue, pass it on. // Critical issue, pass it on.
throw e; throw e;
} }
return tmpChecksum; return destFile;
} }
/** /**
@ -665,30 +655,26 @@ public class DefaultRepositoryProxyConnectors
* @param remoteRepository the remote repository to use * @param remoteRepository the remote repository to use
* @param remotePath the remote path to attempt to get * @param remotePath the remote path to attempt to get
* @param repository the managed repository that will hold the file * @param repository the managed repository that will hold the file
* @param localFile the local file to save to * @param origFile the local file to save to
* @return The local file that was transfered. * @return The local file that was transfered.
* @throws ProxyException if there was a problem moving the downloaded file into place. * @throws ProxyException if there was a problem moving the downloaded file into place.
* @throws WagonException if there was a problem tranfering the file. * @throws WagonException if there was a problem tranfering the file.
*/ */
private File transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File workingDirectory, File localFile ) ManagedRepositoryContent repository, File origFile, File destFile )
throws ProxyException throws ProxyException
{ {
assert ( remotePath != null ); assert ( remotePath != null );
// Transfer the file. // Transfer the file.
File temp = null;
try try
{ {
temp = new File(workingDirectory, localFile.getName());
boolean success = false; boolean success = false;
if ( !localFile.exists() ) if ( !origFile.exists() )
{ {
log.debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() ); log.debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() );
wagon.get( remotePath, temp ); wagon.get( remotePath, destFile );
success = true; success = true;
// You wouldn't get here on failure, a WagonException would have been thrown. // You wouldn't get here on failure, a WagonException would have been thrown.
@ -698,26 +684,23 @@ public class DefaultRepositoryProxyConnectors
{ {
log.debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() log.debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName()
+ " if updated" ); + " if updated" );
success = wagon.getIfNewer( remotePath, temp, localFile.lastModified() ); success = wagon.getIfNewer( remotePath, destFile, origFile.lastModified() );
if ( !success ) if ( !success )
{ {
throw new NotModifiedException( throw new NotModifiedException( "Not downloaded, as local file is newer than remote side: "
"Not downloaded, as local file is newer than remote side: " + localFile.getAbsolutePath() ); + origFile.getAbsolutePath() );
} }
if ( temp.exists() ) if ( destFile.exists() )
{ {
log.debug( "Downloaded successfully." ); log.debug( "Downloaded successfully." );
} }
} }
return temp;
} }
catch ( ResourceDoesNotExistException e ) catch ( ResourceDoesNotExistException e )
{ {
throw new NotFoundException( throw new NotFoundException( "Resource [" + remoteRepository.getURL() + "/" + remotePath
"Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: " + e.getMessage(), + "] does not exist: " + e.getMessage(), e );
e );
} }
catch ( WagonException e ) catch ( WagonException e )
{ {
@ -737,8 +720,10 @@ public class DefaultRepositoryProxyConnectors
* Apply the policies. * Apply the policies.
* *
* @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects)
* @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy setting) * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy
* @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) * setting)
* @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}
* )
* @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)})
*/ */
private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings, private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings,
@ -809,35 +794,37 @@ public class DefaultRepositoryProxyConnectors
previousExceptions.remove( content.getId() ); previousExceptions.remove( content.getId() );
} }
log.warn( "Transfer error from repository \"" + content.getRepository().getId() + "\" for artifact " + log.warn( "Transfer error from repository \"" + content.getRepository().getId() + "\" for artifact "
Keys.toKey( artifact ) + ", continuing to next repository. Error message: " + exception.getMessage() ); + Keys.toKey( artifact ) + ", continuing to next repository. Error message: " + exception.getMessage() );
log.debug( "Full stack trace", exception ); log.debug( "Full stack trace", exception );
} }
/** /**
* Creates a working directory in the repository root for this request * Creates a working directory in the repository root for this request
*
* @param repository * @param repository
* @return file location of working directory * @return file location of working directory
* @throws IOException
*/ */
private File createWorkingDirectory(ManagedRepositoryContent repository) private File createWorkingDirectory( ManagedRepositoryContent repository )
{ {
//TODO: This is ugly - lets actually clean this up when we get the new repository api // TODO: This is ugly - lets actually clean this up when we get the new repository api
try try
{ {
File tmpDir = File.createTempFile(".workingdirectory", null, new File(repository.getRepoRoot())); File tmpDir = File.createTempFile( ".workingdirectory", null, new File( repository.getRepoRoot() ) );
tmpDir.delete(); tmpDir.delete();
tmpDir.mkdirs(); tmpDir.mkdirs();
return tmpDir; return tmpDir;
} }
catch (IOException e) catch ( IOException e )
{ {
throw new RuntimeException("Could not create working directory for this request", e); throw new RuntimeException( "Could not create working directory for this request", e );
} }
} }
/** /**
* Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles * Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles its
* its downloaded files. * downloaded files.
* *
* @param temp The completed download file * @param temp The completed download file
* @param target The final location of the downloaded file * @param target The final location of the downloaded file
@ -862,18 +849,20 @@ public class DefaultRepositoryProxyConnectors
} }
catch ( IOException e ) catch ( IOException e )
{ {
if (target.exists()) if ( target.exists() )
{ {
log.debug("Tried to copy file " + temp.getName() + " to " + target.getAbsolutePath() + " but file with this name already exists."); log.debug( "Tried to copy file " + temp.getName() + " to " + target.getAbsolutePath()
+ " but file with this name already exists." );
} }
else else
{ {
throw new ProxyException( "Cannot copy tmp file " + temp.getAbsolutePath() + " to its final location", e ); throw new ProxyException( "Cannot copy tmp file " + temp.getAbsolutePath()
+ " to its final location", e );
} }
} }
finally finally
{ {
FileUtils.deleteQuietly(temp); FileUtils.deleteQuietly( temp );
} }
} }
} }
@ -886,8 +875,7 @@ public class DefaultRepositoryProxyConnectors
* @param remoteRepository the remote repository to connect to. * @param remoteRepository the remote repository to connect to.
* @return true if the connection was successful. false if not connected. * @return true if the connection was successful. false if not connected.
*/ */
private boolean connectToRepository( ProxyConnector connector, Wagon wagon, private boolean connectToRepository( ProxyConnector connector, Wagon wagon, RemoteRepositoryContent remoteRepository )
RemoteRepositoryContent remoteRepository )
{ {
boolean connected = false; boolean connected = false;
@ -923,35 +911,33 @@ public class DefaultRepositoryProxyConnectors
if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) ) if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
{ {
log.debug( "Using username " + username + " to connect to remote repository " log.debug( "Using username " + username + " to connect to remote repository " + remoteRepository.getURL() );
+ remoteRepository.getURL() );
authInfo = new AuthenticationInfo(); authInfo = new AuthenticationInfo();
authInfo.setUserName( username ); authInfo.setUserName( username );
authInfo.setPassword( password ); authInfo.setPassword( password );
} }
//Convert seconds to milliseconds // Convert seconds to milliseconds
int timeoutInMilliseconds = remoteRepository.getRepository().getTimeout() * 1000; int timeoutInMilliseconds = remoteRepository.getRepository().getTimeout() * 1000;
//Set timeout // Set timeout
wagon.setTimeout(timeoutInMilliseconds); wagon.setTimeout( timeoutInMilliseconds );
try try
{ {
Repository wagonRepository = new Repository( remoteRepository.getId(), remoteRepository.getURL().toString() ); Repository wagonRepository =
new Repository( remoteRepository.getId(), remoteRepository.getURL().toString() );
wagon.connect( wagonRepository, authInfo, networkProxy ); wagon.connect( wagonRepository, authInfo, networkProxy );
connected = true; connected = true;
} }
catch ( ConnectionException e ) catch ( ConnectionException e )
{ {
log.warn( log.warn( "Could not connect to " + remoteRepository.getRepository().getName() + ": " + e.getMessage() );
"Could not connect to " + remoteRepository.getRepository().getName() + ": " + e.getMessage() );
connected = false; connected = false;
} }
catch ( AuthenticationException e ) catch ( AuthenticationException e )
{ {
log.warn( log.warn( "Could not connect to " + remoteRepository.getRepository().getName() + ": " + e.getMessage() );
"Could not connect to " + remoteRepository.getRepository().getName() + ": " + e.getMessage() );
connected = false; connected = false;
} }
@ -1003,10 +989,10 @@ public class DefaultRepositoryProxyConnectors
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{ {
if ( ConfigurationNames.isNetworkProxy( propertyName ) || if ( ConfigurationNames.isNetworkProxy( propertyName )
ConfigurationNames.isManagedRepositories( propertyName ) || || ConfigurationNames.isManagedRepositories( propertyName )
ConfigurationNames.isRemoteRepositories( propertyName ) || || ConfigurationNames.isRemoteRepositories( propertyName )
ConfigurationNames.isProxyConnector( propertyName ) ) || ConfigurationNames.isProxyConnector( propertyName ) )
{ {
initConnectorsAndNetworkProxies(); initConnectorsAndNetworkProxies();
} }
@ -1017,7 +1003,7 @@ public class DefaultRepositoryProxyConnectors
/* do nothing */ /* do nothing */
} }
@SuppressWarnings("unchecked") @SuppressWarnings( "unchecked" )
private void initConnectorsAndNetworkProxies() private void initConnectorsAndNetworkProxies()
{ {
synchronized ( this.proxyConnectorMap ) synchronized ( this.proxyConnectorMap )
@ -1025,8 +1011,8 @@ public class DefaultRepositoryProxyConnectors
ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator();
this.proxyConnectorMap.clear(); this.proxyConnectorMap.clear();
List<ProxyConnectorConfiguration> proxyConfigs = archivaConfiguration.getConfiguration() List<ProxyConnectorConfiguration> proxyConfigs =
.getProxyConnectors(); archivaConfiguration.getConfiguration().getProxyConnectors();
for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs )
{ {
String key = proxyConfig.getSourceRepoId(); String key = proxyConfig.getSourceRepoId();
@ -1036,10 +1022,8 @@ public class DefaultRepositoryProxyConnectors
// Create connector object. // Create connector object.
ProxyConnector connector = new ProxyConnector(); ProxyConnector connector = new ProxyConnector();
connector.setSourceRepository( repositoryFactory.getManagedRepositoryContent( proxyConfig connector.setSourceRepository( repositoryFactory.getManagedRepositoryContent( proxyConfig.getSourceRepoId() ) );
.getSourceRepoId() ) ); connector.setTargetRepository( repositoryFactory.getRemoteRepositoryContent( proxyConfig.getTargetRepoId() ) );
connector.setTargetRepository( repositoryFactory.getRemoteRepositoryContent( proxyConfig
.getTargetRepoId() ) );
connector.setProxyId( proxyConfig.getProxyId() ); connector.setProxyId( proxyConfig.getProxyId() );
connector.setPolicies( proxyConfig.getPolicies() ); connector.setPolicies( proxyConfig.getPolicies() );
@ -1095,7 +1079,8 @@ public class DefaultRepositoryProxyConnectors
{ {
this.networkProxyMap.clear(); this.networkProxyMap.clear();
List<NetworkProxyConfiguration> networkProxies = archivaConfiguration.getConfiguration().getNetworkProxies(); List<NetworkProxyConfiguration> networkProxies =
archivaConfiguration.getConfiguration().getNetworkProxies();
for ( NetworkProxyConfiguration networkProxyConfig : networkProxies ) for ( NetworkProxyConfiguration networkProxyConfig : networkProxies )
{ {
String key = networkProxyConfig.getId(); String key = networkProxyConfig.getId();