From 7f658924184c26b88740405c7a57e642fa533092 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 8 Dec 2006 03:35:45 +0000 Subject: [PATCH] [MNG-2681] Add cli flag to set all snapshot repos to updatePolicy = never Submitted by: Jason Dillon git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@483809 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/maven/cli/CLIManager.java | 6 ++++++ .../main/java/org/apache/maven/cli/MavenCli.java | 6 ++++++ .../main/java/org/apache/maven/DefaultMaven.java | 13 ++++++++++--- .../execution/DefaultMavenExecutionRequest.java | 14 ++++++++++++++ .../maven/execution/MavenExecutionRequest.java | 4 ++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java index 3a5aa59ead..ba2c7b549c 100644 --- a/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java @@ -54,6 +54,8 @@ public class CLIManager public static final String SUPPRESS_PLUGIN_REGISTRY = "npr"; + public static final String SUPRESS_SNAPSHOT_UPDATES = "nsu"; + public static final char CHECKSUM_FAILURE_POLICY = 'C'; public static final char CHECKSUM_WARNING_POLICY = 'c'; @@ -113,6 +115,10 @@ public class CLIManager options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription( "Suppress upToDate check for any relevant registered plugins" ).create( SUPPRESS_PLUGIN_UPDATES ) ); + options.addOption(OptionBuilder.withLongOpt("no-snapshot-updates") + .withDescription("Supress SNAPSHOT updates") + .create(SUPRESS_SNAPSHOT_UPDATES)); + options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription( "Don't use ~/.m2/plugin-registry.xml for plugin versions" ).create( SUPPRESS_PLUGIN_REGISTRY ) ); diff --git a/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java index ee11a7c6ca..4164178ecb 100644 --- a/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java @@ -169,6 +169,11 @@ public class MavenCli pluginUpdateOverride = Boolean.FALSE; } + boolean noSnapshotUpdates = false; + if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { + noSnapshotUpdates = true; + } + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -389,6 +394,7 @@ public class MavenCli .setTransferListener( transferListener ) .setOffline( offline ) .setUpdateSnapshots( updateSnapshots ) + .setNoSnapshotUpdates( noSnapshotUpdates ) .setGlobalChecksumPolicy( globalChecksumPolicy ); mavenEmbedder.execute( request ); diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 5b9192f763..bcf703a49a 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -129,9 +129,16 @@ public class DefaultMaven snapshotPolicySet = true; } - if ( !snapshotPolicySet && request.isUpdateSnapshots() ) - { - artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + if ( !snapshotPolicySet ) { + if ( request.isUpdateSnapshots() ) + { + artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + } + else if ( request.isNoSnapshotUpdates() ) + { + getLogger().info( "+ Supressing SNAPSHOT updates."); + artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + } } artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 3502d3ad8c..b5beaaa69e 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -96,6 +96,8 @@ public class DefaultMavenExecutionRequest private boolean recursive; + private boolean noSnapshotUpdates; + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -198,6 +200,11 @@ public class DefaultMavenExecutionRequest return updateSnapshots; } + public boolean isNoSnapshotUpdates() + { + return noSnapshotUpdates; + } + public String getGlobalChecksumPolicy() { return globalChecksumPolicy; @@ -376,6 +383,13 @@ public class DefaultMavenExecutionRequest return this; } + public MavenExecutionRequest setNoSnapshotUpdates( boolean noSnapshotUpdates ) + { + this.noSnapshotUpdates = noSnapshotUpdates; + + return this; + } + public MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolicy ) { this.globalChecksumPolicy = globalChecksumPolicy; diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index b4a9a7fe1b..f35cc5f6bb 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -143,9 +143,13 @@ public interface MavenExecutionRequest boolean isUpdateSnapshots(); + MavenExecutionRequest setNoSnapshotUpdates( boolean noSnapshotUpdates ); + // Checksum policy MavenExecutionRequest setGlobalChecksumPolicy( String globalChecksumPolicy ); + boolean isNoSnapshotUpdates(); + String getGlobalChecksumPolicy(); // ----------------------------------------------------------------------------