From 3a601de20da76b39707fb616927d9b84e778e9d4 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Sat, 8 Oct 2005 17:37:55 +0000 Subject: [PATCH] - ensure we only blacklist a repository on resolve, not deploy - fail if offline when attempting to deploy or retrieve essential metadata git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307317 13f79535-47bb-0310-9956-ffa450edef68 --- .../deployer/DefaultArtifactDeployer.java | 4 +-- .../DefaultRepositoryMetadataManager.java | 35 +++++++++++++------ .../transform/SnapshotTransformation.java | 9 ++--- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 9d873cd273..0530c7b723 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -59,8 +59,8 @@ public class DefaultArtifactDeployer { if ( !wagonManager.isOnline() ) { - getLogger().warn( "System is offline. Cannot deploy artifact: " + artifact + "." ); - return; + // deployment shouldn't silently fail when offline + throw new ArtifactDeploymentException( "System is offline. Cannot deploy artifact: " + artifact + "." ); } try diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java index d0752e0c72..2caacc41aa 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java @@ -85,7 +85,7 @@ public class DefaultRepositoryMetadataManager { getLogger().info( metadata.getKey() + ": checking for updates from " + repository.getId() ); - resolveAlways( metadata, repository, file, policy.getChecksumPolicy() ); + resolveAlways( metadata, repository, file, policy.getChecksumPolicy(), true ); } // touch file so that this is not checked again until interval has passed @@ -247,14 +247,15 @@ public class DefaultRepositoryMetadataManager { if ( !wagonManager.isOnline() ) { - getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); - return; + // metadata is required for deployment, can't be offline + throw new ArtifactMetadataRetrievalException( + "System is offline. Cannot resolve required metadata:\n" + metadata.extendedToString() ); } File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) ); - resolveAlways( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); + resolveAlways( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN, false ); if ( file.exists() ) { @@ -264,12 +265,23 @@ public class DefaultRepositoryMetadataManager } private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file, - String checksumPolicy ) + String checksumPolicy, boolean allowBlacklisting ) + throws ArtifactMetadataRetrievalException { if ( !wagonManager.isOnline() ) { - getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); - return; + if ( !allowBlacklisting ) + { + getLogger().debug( + "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); + return; + } + else + { + // metadata is required for deployment, can't be offline + throw new ArtifactMetadataRetrievalException( + "System is offline. Cannot resolve required metadata:\n" + metadata.extendedToString() ); + } } try @@ -292,7 +304,7 @@ public class DefaultRepositoryMetadataManager " due to an error: " + e.getCause().getMessage() ); getLogger().info( "Repository '" + repository.getId() + "' will be blacklisted" ); getLogger().debug( "Exception", e ); - repository.setBlacklisted( true ); + repository.setBlacklisted( allowBlacklisting ); } } @@ -307,8 +319,9 @@ public class DefaultRepositoryMetadataManager { if ( !wagonManager.isOnline() ) { - getLogger().warn( "System is offline. Cannot deploy metadata:\n" + metadata.extendedToString() + "\n\n" ); - return; + // deployment shouldn't silently fail when offline + throw new ArtifactMetadataRetrievalException( + "System is offline. Cannot deploy metadata:\n" + metadata.extendedToString() ); } getLogger().info( "Retrieving previous metadata from " + deploymentRepository.getId() ); @@ -316,7 +329,7 @@ public class DefaultRepositoryMetadataManager File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) ); - resolveAlways( metadata, deploymentRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); + resolveAlways( metadata, deploymentRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN, false ); metadata.storeInLocalRepository( localRepository, deploymentRepository ); diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index 1c7644ff88..e6e39b7019 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -133,12 +133,9 @@ public class SnapshotTransformation if ( !wagonManager.isOnline() ) { - getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); - - getLogger().info( "System is offline. Assuming build number of 0 for " + metadata.getGroupId() + ":" + - metadata.getArtifactId() + " snapshot." ); - - return 0; + // build number is a required feature for metadata consistency + throw new ArtifactMetadataRetrievalException( + "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" ); } getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() );