From f391ba6ccd6465810ad5100f0436615b90aee7a9 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 19 Apr 2024 11:37:25 +0200 Subject: [PATCH] [MNG-8030] Backport itr: ignore transitive repositories Backport of the Maven4 feature: ignore transitive repositories. --- https://issues.apache.org/jira/browse/MNG-8030 --- .../execution/DefaultMavenExecutionRequest.java | 14 ++++++++++++++ .../maven/execution/MavenExecutionRequest.java | 10 ++++++++++ .../DefaultRepositorySystemSessionFactory.java | 2 ++ .../main/java/org/apache/maven/cli/CLIManager.java | 6 ++++++ .../main/java/org/apache/maven/cli/MavenCli.java | 1 + 5 files changed, 33 insertions(+) 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 92d2324c9a28..cefb2c3fe6f7 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 @@ -65,6 +65,8 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest { private boolean cacheNotFound; + private boolean ignoreTransitiveRepositories; + private List proxies; private List servers; @@ -169,6 +171,7 @@ public static MavenExecutionRequest copy(MavenExecutionRequest original) { copy.setOffline(original.isOffline()); copy.setInteractiveMode(original.isInteractiveMode()); copy.setCacheNotFound(original.isCacheNotFound()); + copy.setIgnoreTransitiveRepositories(original.isIgnoreTransitiveRepositories()); copy.setCacheTransferError(original.isCacheTransferError()); copy.setProxies(original.getProxies()); copy.setServers(original.getServers()); @@ -1018,6 +1021,17 @@ public MavenExecutionRequest setCacheNotFound(boolean cacheNotFound) { return this; } + @Override + public boolean isIgnoreTransitiveRepositories() { + return ignoreTransitiveRepositories; + } + + @Override + public MavenExecutionRequest setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories) { + this.ignoreTransitiveRepositories = ignoreTransitiveRepositories; + return this; + } + @Override public boolean isUseLegacyLocalRepository() { return this.useLegacyLocalRepositoryManager; 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 41ec50117879..b074eea348de 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 @@ -252,6 +252,16 @@ public interface MavenExecutionRequest { MavenExecutionRequest setCacheNotFound(boolean cacheNotFound); + /** + * @since 3.9.7 + */ + boolean isIgnoreTransitiveRepositories(); + + /** + * @since 3.9.7 + */ + MavenExecutionRequest setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories); + // Profiles List getProfiles(); diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index d3066c070678..be06d58b0245 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -341,6 +341,8 @@ public DefaultRepositorySystemSession newRepositorySession(MavenExecutionRequest session.setRepositoryListener(eventSpyDispatcher.chainListener(new LoggingRepositoryListener(logger))); + session.setIgnoreArtifactDescriptorRepositories(request.isIgnoreTransitiveRepositories()); + boolean recordReverseTree = ConfigUtils.getBoolean(session, false, MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE); if (recordReverseTree) { session.setRepositoryListener(new ChainedRepositoryListener( 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 bc62f64b7af6..23a5b769cca6 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 @@ -107,6 +107,8 @@ public class CLIManager { public static final String COLOR = "color"; + public static final String IGNORE_TRANSITIVE_REPOSITORIES = "itr"; + protected Options options; @SuppressWarnings({"checkstyle:linelength", "checkstyle:MethodLength"}) @@ -261,6 +263,10 @@ public CLIManager() { .longOpt("no-transfer-progress") .desc("Do not display transfer progress when downloading or uploading") .build()); + options.addOption(Option.builder(IGNORE_TRANSITIVE_REPOSITORIES) + .longOpt("ignore-transitive-repositories") + .desc("If set, Maven will ignore remote repositories introduced by transitive dependencies.") + .build()); // Adding this back in for compatibility with the verifier that hard codes this option. options.addOption(Option.builder("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 5932741a5106..080cc20ff671 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 @@ -1409,6 +1409,7 @@ private MavenExecutionRequest populateRequest(CliRequest cliRequest, MavenExecut request.setCacheNotFound(true); request.setCacheTransferError(false); + request.setIgnoreTransitiveRepositories(commandLine.hasOption(CLIManager.IGNORE_TRANSITIVE_REPOSITORIES)); // // Builder, concurrency and parallelism