From 69ef6a61ba1f01be58346e0a4e65ccc07f4477e1 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 1 Dec 2022 19:53:00 +0100 Subject: [PATCH] [MNG-7612] Chained LRM Adds new feature: Chained Local Repository Manager. Cherry-pick 2dc7a356d3912a92af2c6e5e23604b084f5ca748 --- https://issues.apache.org/jira/browse/MNG-7612 --- ...DefaultRepositorySystemSessionFactory.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) 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 c7d04734a6..73b351458d 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 @@ -18,10 +18,13 @@ */ package org.apache.maven.internal.aether; +import static java.util.stream.Collectors.toList; + import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -60,6 +63,7 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.SessionData; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.NoLocalRepositoryManagerException; import org.eclipse.aether.repository.RepositoryPolicy; import org.eclipse.aether.repository.WorkspaceReader; @@ -67,7 +71,9 @@ import org.eclipse.aether.resolution.ResolutionErrorPolicy; import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory; import org.eclipse.aether.transform.FileTransformer; import org.eclipse.aether.transform.TransformException; +import org.eclipse.aether.util.ConfigUtils; import org.eclipse.aether.util.repository.AuthenticationBuilder; +import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; import org.eclipse.aether.util.repository.DefaultAuthenticationSelector; import org.eclipse.aether.util.repository.DefaultMirrorSelector; import org.eclipse.aether.util.repository.DefaultProxySelector; @@ -81,6 +87,23 @@ import org.slf4j.LoggerFactory; */ @Named public class DefaultRepositorySystemSessionFactory { + /** + * User property for chained LRM: list of "tail" local repository paths (separated by comma), to be used with + * {@link ChainedLocalRepositoryManager}. + * Default value: {@code null}, no chained LRM is used. + * + * @since 3.9.0 + */ + private static final String MAVEN_REPO_LOCAL_TAIL = "maven.repo.local.tail"; + + /** + * User property for chained LRM: should artifact availability be ignored in tail local repositories or not. + * Default: {@code true}, will ignore availability from tail local repositories. + * + * @since 3.9.0 + */ + private static final String MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY = "maven.repo.local.tail.ignoreAvailability"; + private static final String MAVEN_RESOLVER_TRANSPORT_KEY = "maven.resolver.transport"; private static final String MAVEN_RESOLVER_TRANSPORT_DEFAULT = "default"; @@ -356,7 +379,23 @@ public class DefaultRepositorySystemSessionFactory { session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo)); } } else { - session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo)); + LocalRepositoryManager lrm = repoSystem.newLocalRepositoryManager(session, localRepo); + + String localRepoTail = ConfigUtils.getString(session, null, MAVEN_REPO_LOCAL_TAIL); + if (localRepoTail != null) { + boolean ignoreTailAvailability = + ConfigUtils.getBoolean(session, true, MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY); + List tail = new ArrayList<>(); + List paths = Arrays.stream(localRepoTail.split(",")) + .filter(p -> p != null && !p.trim().isEmpty()) + .collect(toList()); + for (String path : paths) { + tail.add(repoSystem.newLocalRepositoryManager(session, new LocalRepository(path))); + } + session.setLocalRepositoryManager(new ChainedLocalRepositoryManager(lrm, tail, ignoreTailAvailability)); + } else { + session.setLocalRepositoryManager(lrm); + } } }