diff options
author | James William Dumay <jdumay@apache.org> | 2008-08-13 03:09:52 +0000 |
---|---|---|
committer | James William Dumay <jdumay@apache.org> | 2008-08-13 03:09:52 +0000 |
commit | 384b971464f8febadd44ee4e232f8c8dee91a675 (patch) | |
tree | 826def702ab4bb6c6cd7fe9cef5c15561b985441 /archiva-modules/archiva-base/archiva-proxy | |
parent | f4fa2961acc5da0622eed92c06dcae65169f588a (diff) | |
download | archiva-384b971464f8febadd44ee4e232f8c8dee91a675.tar.gz archiva-384b971464f8febadd44ee4e232f8c8dee91a675.zip |
MRM-907 - Remove VersionedReference/ProjectReference/ArtifactReference from RepositoryProxyConnectors
* Merging from https://svn.apache.org/repos/asf/archiva/branches/metadata-rejig-1.2
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@685423 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-proxy')
3 files changed, 44 insertions, 187 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 5e9978fa6..000c8c6c8 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -32,7 +32,6 @@ import java.util.Map.Entry; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; @@ -40,9 +39,7 @@ import org.apache.maven.archiva.configuration.NetworkProxyConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.Keys; -import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.RepositoryURL; -import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.policies.DownloadErrorPolicy; import org.apache.maven.archiva.policies.DownloadPolicy; import org.apache.maven.archiva.policies.PolicyConfigurationException; @@ -51,13 +48,11 @@ import org.apache.maven.archiva.policies.PostDownloadPolicy; import org.apache.maven.archiva.policies.PreDownloadPolicy; import org.apache.maven.archiva.policies.ProxyDownloadException; import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; -import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RemoteRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; -import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers; @@ -269,13 +264,13 @@ public class DefaultRepositoryProxyConnectors return null; } - - public File fetchFromProxies( ManagedRepositoryContent repository, VersionedReference metadata ) + + public File fetchMetatadaFromProxies(ManagedRepositoryContent repository, String logicalPath) { File workingDir = createWorkingDirectory(repository); try { - File localFile = toLocalFile( repository, metadata ); + File localFile = new File(repository.getRepoRoot(), logicalPath); Properties requestProperties = new Properties(); requestProperties.setProperty( "filetype", "metadata" ); @@ -286,14 +281,13 @@ public class DefaultRepositoryProxyConnectors for ( ProxyConnector connector : connectors ) { RemoteRepositoryContent targetRepository = connector.getTargetRepository(); - String targetPath = metadataTools.toPath( metadata ); - File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); + File localRepoFile = toLocalRepoFile( repository, targetRepository, logicalPath ); long originalMetadataTimestamp = getLastModified( localRepoFile ); try { - transferFile( connector, targetRepository, targetPath, repository, workingDir, localRepoFile, requestProperties, true ); + transferFile( connector, targetRepository, logicalPath, repository, workingDir, localRepoFile, requestProperties, true ); if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) { @@ -302,20 +296,20 @@ public class DefaultRepositoryProxyConnectors } catch ( NotFoundException e ) { - log.debug( "Versioned Metadata " + Keys.toKey( metadata ) + log.debug( "Metadata " + logicalPath + " not found on remote repository \"" - + targetRepository.getRepository().getId() + "\"." ); + + targetRepository.getRepository().getId() + "\".", e ); } catch ( NotModifiedException e ) { - log.debug( "Versioned Metadata " + Keys.toKey( metadata ) + log.debug( "Metadata " + logicalPath + " not updated on remote repository \"" - + targetRepository.getRepository().getId() + "\"." ); + + targetRepository.getRepository().getId() + "\".", e ); } catch ( ProxyException e ) { log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() + - "\" for versioned Metadata " + Keys.toKey( metadata ) + + "\" for versioned Metadata " + logicalPath + ", continuing to next repository. Error message: " + e.getMessage() ); log.debug( "Full stack trace", e ); } @@ -330,126 +324,11 @@ public class DefaultRepositoryProxyConnectors { try { - metadataTools.updateMetadata( repository, metadata ); - } - catch ( LayoutException e ) - { - log.warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage() ); - // TODO: add into repository report? + metadataTools.updateMetadata( repository, logicalPath ); } catch ( RepositoryMetadataException e ) { log.warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage(), e ); - // TODO: add into repository report? - } - catch ( IOException e ) - { - log.warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage(), e ); - // TODO: add into repository report? - } - catch ( ContentNotFoundException e ) - { - log.warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage(), e ); - // TODO: add into repository report? - } - } - - if ( fileExists( localFile ) ) - { - return localFile; - } - } - finally - { - FileUtils.deleteQuietly(workingDir); - } - - return null; - } - - public File fetchFromProxies( ManagedRepositoryContent repository, ProjectReference metadata ) - { - File workingDir = createWorkingDirectory(repository); - try - { - File localFile = toLocalFile( repository, metadata ); - - Properties requestProperties = new Properties(); - requestProperties.setProperty( "filetype", "metadata" ); - boolean metadataNeedsUpdating = false; - long originalTimestamp = getLastModified( localFile ); - - List<ProxyConnector> connectors = getProxyConnectors( repository ); - for ( ProxyConnector connector : connectors ) - { - RemoteRepositoryContent targetRepository = connector.getTargetRepository(); - String targetPath = metadataTools.toPath( metadata ); - - File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath ); - long originalMetadataTimestamp = getLastModified( localRepoFile ); - try - { - transferFile( connector, targetRepository, targetPath, repository, workingDir, localRepoFile, requestProperties, true ); - - if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) ) - { - metadataNeedsUpdating = true; - } - } - catch ( NotFoundException e ) - { - log.debug( "Project Metadata " + Keys.toKey( metadata ) + " not found on remote repository \"" - + targetRepository.getRepository().getId() + "\"." ); - } - catch ( NotModifiedException e ) - { - log.debug( "Project Metadata " + Keys.toKey( metadata ) - + " not updated on remote repository \"" - + targetRepository.getRepository().getId() + "\"." ); - } - catch ( ProxyException e ) - { - log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() + - "\" for project metadata " + Keys.toKey( metadata ) + - ", continuing to next repository. Error message: " + e.getMessage() ); - log.debug( "Full stack trace", e ); - } - - } - - if ( hasBeenUpdated( localFile, originalTimestamp ) ) - { - metadataNeedsUpdating = true; - } - - if ( metadataNeedsUpdating ) - { - try - { - metadataTools.updateMetadata( repository, metadata ); - } - catch ( LayoutException e ) - { - log.warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage() ); - // TODO: add into repository report? - } - catch ( RepositoryMetadataException e ) - { - log - .warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage(), e ); - // TODO: add into repository report? - } - catch ( IOException e ) - { - log - .warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage(), e ); - // TODO: add into repository report? - } - catch ( ContentNotFoundException e ) - { - log - .warn( "Unable to update metadata " + localFile.getAbsolutePath() + ": " + e.getMessage(), e ); - // TODO: add into repository report? } } @@ -510,18 +389,6 @@ public class DefaultRepositoryProxyConnectors return repository.toFile( artifact ); } - private File toLocalFile( ManagedRepositoryContent repository, ProjectReference metadata ) - { - String sourcePath = metadataTools.toPath( metadata ); - return new File( repository.getRepoRoot(), sourcePath ); - } - - private File toLocalFile( ManagedRepositoryContent repository, VersionedReference metadata ) - { - String sourcePath = metadataTools.toPath( metadata ); - return new File( repository.getRepoRoot(), sourcePath ); - } - /** * Simple method to test if the file exists on the local disk. * @@ -555,7 +422,7 @@ public class DefaultRepositoryProxyConnectors * @param remoteRepository the remote repository get the resource from. * @param remotePath the path in the remote repository to the resource to get. * @param repository the managed repository that will hold the file - * @param localFile the local file to place the downloaded resource into + * @param resource the local file to place the downloaded resource into * @param requestProperties the request properties to utilize for policy handling. * @param executeConsumers whether to execute the consumers after proxying * @return the local file that was downloaded, or null if not downloaded. @@ -565,10 +432,10 @@ public class DefaultRepositoryProxyConnectors * @throws ProxyException if transfer was unsuccessful. */ private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, File workingDirectory, File localFile, Properties requestProperties, + ManagedRepositoryContent repository, File workingDirectory, File resource, Properties requestProperties, boolean executeConsumers ) throws ProxyException, NotModifiedException - { + { String url = remoteRepository.getURL().getUrl(); if ( !url.endsWith( "/" ) ) { @@ -601,15 +468,15 @@ public class DefaultRepositoryProxyConnectors // Handle pre-download policy try { - validatePolicies( this.preDownloadPolicies, connector.getPolicies(), requestProperties, localFile ); + validatePolicies( this.preDownloadPolicies, connector.getPolicies(), requestProperties, resource ); } catch ( PolicyViolationException e ) { String emsg = "Transfer not attempted on " + url + " : " + e.getMessage(); - if ( fileExists( localFile ) ) + if ( fileExists( resource ) ) { log.info( emsg + ": using already present local file." ); - return localFile; + return resource; } log.info( emsg ); @@ -623,7 +490,7 @@ public class DefaultRepositoryProxyConnectors File tmpMd5 = null; File tmpSha1 = null; - File tmpLocalFile = null; + File tmpResource = null; Wagon wagon = null; try @@ -639,12 +506,12 @@ public class DefaultRepositoryProxyConnectors boolean connected = connectToRepository( connector, wagon, remoteRepository ); if ( connected ) { - tmpLocalFile = transferSimpleFile( wagon, remoteRepository, remotePath, repository, workingDirectory, localFile ); + tmpResource = transferSimpleFile( wagon, remoteRepository, remotePath, repository, workingDirectory, resource ); // 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 - tmpSha1 = transferChecksum( wagon, remoteRepository, remotePath, repository, workingDirectory, localFile, ".sha1" ); - tmpMd5 = transferChecksum( wagon, remoteRepository, remotePath, repository, workingDirectory, localFile, ".md5" ); + tmpSha1 = transferChecksum( wagon, remoteRepository, remotePath, repository, workingDirectory, resource, ".sha1" ); + tmpMd5 = transferChecksum( wagon, remoteRepository, remotePath, repository, workingDirectory, resource, ".md5" ); } } catch ( NotFoundException e ) @@ -706,32 +573,36 @@ public class DefaultRepositoryProxyConnectors // Handle post-download policies. try { - validatePolicies( this.postDownloadPolicies, connector.getPolicies(), requestProperties, tmpLocalFile ); + validatePolicies( this.postDownloadPolicies, connector.getPolicies(), requestProperties, tmpResource ); } catch ( PolicyViolationException e ) { log.info( "Transfer invalidated from " + url + " : " + e.getMessage() ); executeConsumers = false; - if ( !fileExists( tmpLocalFile ) ) + if ( !fileExists( tmpResource ) ) { - localFile = null; + resource = null; } } - if (localFile != null) + if (resource != null) { - moveFileIfExists(tmpMd5, localFile); - moveFileIfExists(tmpSha1, localFile); - moveFileIfExists(tmpLocalFile, localFile); + synchronized (resource.getAbsolutePath().intern()) + { + File directory = resource.getParentFile(); + moveFileIfExists(tmpMd5, directory); + moveFileIfExists(tmpSha1, directory); + moveFileIfExists(tmpResource, directory); + } } if ( executeConsumers ) { // Just-in-time update of the index and database by executing the consumers for this artifact - consumers.executeConsumers( connector.getSourceRepository().getRepository(), localFile ); + consumers.executeConsumers( connector.getSourceRepository().getRepository(), resource ); } - return localFile; + return resource; } @@ -740,13 +611,14 @@ public class DefaultRepositoryProxyConnectors * Moves the file into repository location if it exists * * @param fileToMove this could be either the main artifact, sha1 or md5 checksum file. - * @param localFile this is always the main artifact + * @param directory directory to write files to */ - private void moveFileIfExists(File fileToMove, File localFile) throws ProxyException + private void moveFileIfExists(File fileToMove, File directory) throws ProxyException { if (fileToMove != null && fileToMove.exists()) { - moveTempToTarget(fileToMove, new File(localFile.getParentFile(), fileToMove.getName())); + File newLocation = new File(directory, fileToMove.getName()); + moveTempToTarget(fileToMove, newLocation); } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java index cf68c9509..760688db0 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/RepositoryProxyConnectors.java @@ -20,8 +20,6 @@ package org.apache.maven.archiva.proxy; */ import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.ProjectReference; -import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.policies.ProxyDownloadException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; @@ -50,20 +48,7 @@ public interface RepositoryProxyConnectors */ public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) throws ProxyDownloadException; - - /** - * Performs the metadata fetch operation against the target repositories - * of the provided source repository. - * - * If the metadata is found, it is downloaded and placed into the source repository - * filesystem. - * - * @param repository the source repository to use. (must be a managed repository) - * @param metadata the metadata to fetch. - * @return the file that was obtained, or null if no content was obtained - */ - public File fetchFromProxies( ManagedRepositoryContent repository, VersionedReference metadata ); - + /** * Performs the metadata fetch operation against the target repositories * of the provided source repository. @@ -75,7 +60,7 @@ public interface RepositoryProxyConnectors * @param metadata the metadata to fetch. * @return the file that was obtained, or null if no content was obtained */ - public File fetchFromProxies( ManagedRepositoryContent repository, ProjectReference metadata ); + public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath ); /** * Performs the fetch operation against the target repositories diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java index 3cab9107b..8e7d20d68 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java @@ -905,7 +905,7 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -929,7 +929,7 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir, requestedResource ); ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); assertNull( downloadedFile ); assertNoTempFiles( expectedFile ); @@ -948,7 +948,7 @@ public class MetadataTransferTest VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -972,7 +972,7 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir, requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); assertNull( downloadedFile ); assertNoTempFiles( expectedFile ); |