diff options
4 files changed, 31 insertions, 50 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java index adbec863c..ba070f638 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -23,8 +23,6 @@ import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.consumers.AbstractMonitoredConsumer; import org.apache.archiva.consumers.ConsumerException; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.archiva.model.ProjectReference; -import org.apache.archiva.model.VersionedReference; import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.ManagedRepository; @@ -33,7 +31,6 @@ import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryNotFoundException; import org.apache.archiva.repository.RepositoryRegistry; import org.apache.archiva.repository.content.Artifact; -import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.Project; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.base.MetadataTools; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index b0383affb..14f55c1d4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -25,8 +25,6 @@ import org.apache.archiva.metadata.audit.RepositoryListener; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.model.ProjectReference; -import org.apache.archiva.model.VersionedReference; import org.apache.archiva.repository.BaseRepositoryContentLayout; import org.apache.archiva.repository.ContentNotFoundException; import org.apache.archiva.repository.LayoutException; @@ -142,10 +140,6 @@ public class CleanupReleasedSnapshotsRepositoryPurge // Now clean out any version that is earlier than the highest released version. boolean needsMetadataUpdate = false; - VersionedReference versionRef = new VersionedReference( ); - versionRef.setGroupId( artifactRef.getNamespace( ).getId() ); - versionRef.setArtifactId( artifactRef.getId( ) ); - ArchivaItemSelector.Builder versionSelectorBuilder = ArchivaItemSelector.builder( ) .withNamespace( artifactRef.getNamespace().getId() ) .withProjectId( artifactRef.getId( ) ) diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java index 32560ebdd..477185a10 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/main/java/org/apache/archiva/proxy/maven/MavenRepositoryProxyHandler.java @@ -148,34 +148,31 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { throw new ProxyException("Unsupported target repository protocol: " + protocol); } - if (wagon == null) { - throw new ProxyException("Unsupported target repository protocol: " + protocol); - } - boolean connected = connectToRepository(connector, wagon, remoteRepository); if (connected) { - transferArtifact(wagon, remoteRepository, remotePath, repository, resource.getFilePath(), workingDirectory, - tmpResource); + transferArtifact(wagon, remoteRepository, remotePath, resource.getFilePath(), + tmpResource); // 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 - for (int i=0; i<checksumFiles.length; i++) { - String ext = "."+StringUtils.substringAfterLast(checksumFiles[i].getName( ), "." ); - transferChecksum(wagon, remoteRepository, remotePath, repository, resource.getFilePath(), ext, - checksumFiles[i].getFilePath()); + for ( StorageAsset checksumFile : checksumFiles ) + { + String ext = "." + StringUtils.substringAfterLast( checksumFile.getName( ), "." ); + transferChecksum( wagon, remoteRepository, remotePath, resource.getFilePath( ), ext, + checksumFile.getFilePath( ) ); } } - } catch (NotFoundException e) { - urlFailureCache.cacheFailure(url); - throw e; - } catch (NotModifiedException e) { + } + catch (NotModifiedException e) { // Do not cache url here. throw e; - } catch (ProxyException e) { + } + catch ( ProxyException e) { urlFailureCache.cacheFailure(url); throw e; - } catch (WagonFactoryException e) { + } + catch (WagonFactoryException e) { throw new ProxyException(e.getMessage(), e); } finally { if (wagon != null) { @@ -188,11 +185,11 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { } } - protected void transferArtifact(Wagon wagon, RemoteRepository remoteRepository, String remotePath, - ManagedRepository repository, Path resource, Path tmpDirectory, - StorageAsset destFile) + protected void transferArtifact( Wagon wagon, RemoteRepository remoteRepository, String remotePath, + Path resource, + StorageAsset destFile ) throws ProxyException { - transferSimpleFile(wagon, remoteRepository, remotePath, repository, resource, destFile.getFilePath()); + transferSimpleFile(wagon, remoteRepository, remotePath, resource, destFile.getFilePath()); } /** @@ -203,13 +200,12 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { * @param wagon the wagon instance (should already be connected) to use. * @param remoteRepository the remote repository to transfer from. * @param remotePath the remote path to the resource to get. - * @param repository the managed repository that will hold the file * @param resource the local file that should contain the downloaded contents * @param ext the type of checksum to transfer (example: ".md5" or ".sha1") * @throws ProxyException if copying the downloaded file into place did not succeed. */ protected void transferChecksum( Wagon wagon, RemoteRepository remoteRepository, String remotePath, - ManagedRepository repository, Path resource, String ext, + Path resource, String ext, Path destFile ) throws ProxyException { String url = remoteRepository.getLocation().toString() + remotePath + ext; @@ -220,7 +216,7 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { } try { - transferSimpleFile(wagon, remoteRepository, remotePath + ext, repository, resource, destFile); + transferSimpleFile(wagon, remoteRepository, remotePath + ext, resource, destFile); log.debug("Checksum {} Downloaded: {} to move to {}", url, destFile, resource); } catch (NotFoundException e) { urlFailureCache.cacheFailure(url); @@ -243,27 +239,26 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { * @param wagon the wagon instance to use. * @param remoteRepository the remote repository to use * @param remotePath the remote path to attempt to get - * @param repository the managed repository that will hold the file * @param origFile the local file to save to * @throws ProxyException if there was a problem moving the downloaded file into place. */ - protected void transferSimpleFile(Wagon wagon, RemoteRepository remoteRepository, String remotePath, - ManagedRepository repository, Path origFile, Path destFile) + protected void transferSimpleFile( Wagon wagon, RemoteRepository remoteRepository, String remotePath, + Path origFile, Path destFile ) throws ProxyException { assert (remotePath != null); // Transfer the file. try { - boolean success = false; + if (!Files.exists(origFile)) { log.debug("Retrieving {} from {}", remotePath, remoteRepository.getId()); wagon.get(addParameters(remotePath, remoteRepository), destFile.toFile()); - success = true; // You wouldn't get here on failure, a WagonException would have been thrown. log.debug("Downloaded successfully."); } else { + boolean success; log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getId()); try { success = wagon.getIfNewer(addParameters(remotePath, remoteRepository), destFile.toFile(), @@ -306,8 +301,6 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { */ protected boolean connectToRepository(ProxyConnector connector, Wagon wagon, RemoteRepository remoteRepository) { - boolean connected = false; - final ProxyInfo networkProxy = connector.getProxyId() == null ? null : this.networkProxyMap.get(connector.getProxyId()); @@ -356,13 +349,12 @@ public class MavenRepositoryProxyHandler extends DefaultRepositoryProxyHandler { Repository wagonRepository = new Repository(remoteRepository.getId(), remoteRepository.getLocation().toString()); wagon.connect(wagonRepository, authInfo, networkProxy); - connected = true; + return true; } catch (ConnectionException | AuthenticationException e) { log.warn("Could not connect to {}: {}", remoteRepository.getId(), e.getMessage()); - connected = false; + return false; } - return connected; } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java index c5c38de42..5b5fd5322 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java @@ -20,23 +20,21 @@ package org.apache.archiva.repository.maven.metadata; import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.content.ItemSelector; -import org.apache.archiva.repository.content.base.ArchivaItemSelector; -import org.apache.archiva.repository.maven.metadata.storage.mock.MockConfiguration; -import org.apache.archiva.model.ProjectReference; -import org.apache.archiva.model.VersionedReference; import org.apache.archiva.policies.CachedFailuresPolicy; import org.apache.archiva.policies.ChecksumPolicy; import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; -import org.apache.archiva.repository.maven.AbstractRepositoryLayerTestCase; import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RemoteRepositoryContent; import org.apache.archiva.repository.RepositoryContentProvider; +import org.apache.archiva.repository.content.ItemSelector; +import org.apache.archiva.repository.content.base.ArchivaItemSelector; +import org.apache.archiva.repository.maven.AbstractRepositoryLayerTestCase; +import org.apache.archiva.repository.maven.MavenManagedRepository; +import org.apache.archiva.repository.maven.metadata.storage.mock.MockConfiguration; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.base.MetadataTools; -import org.apache.archiva.repository.maven.MavenManagedRepository; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Test; |