From 27f8b0f81af3bf49cba251e2e857a7e67562132f Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 1 Feb 2013 00:35:46 +0100 Subject: [PATCH] [MNG-5185] [MNG-5181] add cli flag to be able to remove use of EnhancedLocalRepositoryManager. --- .../java/org/apache/maven/DefaultMaven.java | 23 ++++++++++++++++++- .../DefaultMavenExecutionRequest.java | 12 ++++++++++ .../execution/MavenExecutionRequest.java | 10 ++++++++ .../java/org/apache/maven/cli/CLIManager.java | 3 +++ .../java/org/apache/maven/cli/MavenCli.java | 10 ++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) 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 e80185bbda..a6e11e8c3e 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -85,8 +85,10 @@ import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.repository.Authentication; import org.sonatype.aether.repository.LocalRepository; +import org.sonatype.aether.repository.NoLocalRepositoryManagerException; import org.sonatype.aether.repository.RepositoryPolicy; import org.sonatype.aether.repository.WorkspaceReader; +import org.sonatype.aether.spi.localrepo.LocalRepositoryManagerFactory; import org.sonatype.aether.util.DefaultRepositorySystemSession; import org.sonatype.aether.util.repository.ChainedWorkspaceReader; import org.sonatype.aether.util.repository.DefaultAuthenticationSelector; @@ -128,6 +130,9 @@ public class DefaultMaven @Requirement private RepositorySystem repoSystem; + @Requirement (optional = true, hint = "simple") + private LocalRepositoryManagerFactory simpleLocalRepositoryManagerFactory; + @Requirement private SettingsDecrypter settingsDecrypter; @@ -352,7 +357,23 @@ public class DefaultMaven session.setArtifactTypeRegistry( RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager ) ); LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() ); - session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) ); + + if (request.isUseSimpleLocalRepostoryManager()) + { + try + { + session.setLocalRepositoryManager( simpleLocalRepositoryManagerFactory.newInstance( localRepo ) ); + } + catch ( NoLocalRepositoryManagerException e ) + { + + logger.warn( "fail to configure simple local repository manager back to default" ); + session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) ); + } + } + else { + session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) ); + } if ( request.getWorkspaceReader() != null ) { 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 78436be6b5..313984622e 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 @@ -143,6 +143,8 @@ public class DefaultMavenExecutionRequest */ private boolean noSnapshotUpdates; + private boolean useSimpleLocalRepostoryManager = false; + public DefaultMavenExecutionRequest() { } @@ -1076,4 +1078,14 @@ public class DefaultMavenExecutionRequest return this; } + public boolean isUseSimpleLocalRepostoryManager() + { + return this.useSimpleLocalRepostoryManager; + } + + public MavenExecutionRequest setUseSimpleLocalRepostoryManager( boolean useSimpleLocalRepostoryManager ) + { + this.useSimpleLocalRepostoryManager = useSimpleLocalRepostoryManager; + return this; + } } 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 ef88a1769f..5ab11b3cae 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 @@ -283,4 +283,14 @@ public interface MavenExecutionRequest ProjectBuildingRequest getProjectBuildingRequest(); + /** + * @since 3.1 + */ + boolean isUseSimpleLocalRepostoryManager(); + + /** + * @since 3.1 + */ + MavenExecutionRequest setUseSimpleLocalRepostoryManager(boolean useSimpleLocalRepostoryManager); + } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index 0e7f2b622a..32c1bb2758 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -97,6 +97,8 @@ public class CLIManager public static final String THREADS = "T"; + public static final String SIMPLE_LOCAL_REPOSITORY_MANAGER ="slrm"; + protected Options options; @SuppressWarnings( "static-access" ) @@ -134,6 +136,7 @@ public class CLIManager options.addOption( OptionBuilder.withLongOpt( "encrypt-password" ).hasArg().withDescription( "Encrypt server password" ).create( ENCRYPT_PASSWORD ) ); options.addOption( OptionBuilder.withLongOpt( "threads" ).hasArg().withDescription( "Thread count, for instance 2.0C where C is core multiplied" ).create( THREADS ) ); + options.addOption( OptionBuilder.withLongOpt( "simple-local-repository-manager" ).withDescription( "Use a simple local Repository Manager (no use of _maven.repositories)" ).create( SIMPLE_LOCAL_REPOSITORY_MANAGER ) ); // Adding this back in for compatibility with the verifier that hard codes this option. options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription( "Ineffective, only kept for backward compatibility" ).create( "npr" ) ); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 5a4710fd04..dd42ba6924 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -210,6 +210,7 @@ public class MavenCli settings( cliRequest ); populateRequest( cliRequest ); encryption( cliRequest ); + repository( cliRequest ); return execute( cliRequest ); } catch ( ExitException e ) @@ -538,6 +539,15 @@ public class MavenCli } } + private void repository( CliRequest cliRequest ) + throws Exception + { + if ( cliRequest.commandLine.hasOption( CLIManager.SIMPLE_LOCAL_REPOSITORY_MANAGER ) ) + { + cliRequest.request.setUseSimpleLocalRepostoryManager( true ); + } + } + private int execute( CliRequest cliRequest ) { eventSpyDispatcher.onEvent( cliRequest.request );