You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/12/02 19:43:05 UTC

[maven] branch MNG-7612 created (now cfe503f58)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch MNG-7612
in repository https://gitbox.apache.org/repos/asf/maven.git


      at cfe503f58 [MNG-7612] Chained LRM

This branch includes the following new commits:

     new cfe503f58 [MNG-7612] Chained LRM

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 01/01: [MNG-7612] Chained LRM

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MNG-7612
in repository https://gitbox.apache.org/repos/asf/maven.git

commit cfe503f58a2b34a1d58a549bba0e066605a9805e
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Dec 1 19:53:00 2022 +0100

    [MNG-7612] Chained LRM
    
    Adds new feature: Chained Local Repository Manager.
    
    Cherry-pick f8f56b33c0585638723a20d71eb848d40a1f44e0
    
    ---
    
    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 c7d04734a..73b351458 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<LocalRepositoryManager> tail = new ArrayList<>();
+                List<String> 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);
+            }
         }
     }