This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch maven-3.9.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.9.x by this push:
new 68aa8415bb [MNG-8370] Add maven.repo.local.head
68aa8415bb is described below
commit 68aa8415bb935032fe7343223835e890aa737921
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Sat Nov 16 17:39:55 2024 +0100
[MNG-8370] Add maven.repo.local.head
Based on: 1ab2ccf066ceb5a2a491c8a9779fef8c5e57bb22
https://issues.apache.org/jira/browse/MNG-8370
---
.../DefaultRepositorySystemSessionFactory.java | 60 ++++++++++++++++++----
1 file changed, 49 insertions(+), 11 deletions(-)
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 be06d58b02..bcdf438db2 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
@@ -21,6 +21,7 @@ package org.apache.maven.internal.aether;
import javax.inject.Inject;
import javax.inject.Named;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -66,8 +67,6 @@ import
org.eclipse.aether.util.repository.DefaultProxySelector;
import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
import org.eclipse.sisu.Nullable;
-import static java.util.stream.Collectors.toList;
-
/**
* @since 3.3.0
*/
@@ -82,6 +81,16 @@ public class DefaultRepositorySystemSessionFactory {
*/
private static final String MAVEN_REPO_LOCAL_TAIL =
"maven.repo.local.tail";
+ /**
+ * User property for chained LRM: the new "head" local repository to use,
and "push" the existing into tail.
+ * Similar to <code>maven.repo.local.tail</code>, this property may
contain comma separated list of paths to be
+ * used as local repositories (combine with chained local repository), but
while latter is "appending" this
+ * one is "prepending".
+ *
+ * @since 3.9.10
+ */
+ public static final String MAVEN_REPO_LOCAL_HEAD = "maven.repo.local.head";
+
/**
* 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.
@@ -363,25 +372,54 @@ public class DefaultRepositorySystemSessionFactory {
}
private void setUpLocalRepositoryManager(MavenExecutionRequest request,
DefaultRepositorySystemSession session) {
- LocalRepository localRepo =
- new LocalRepository(request.getLocalRepository().getBasedir());
+ List<String> paths = new ArrayList<>();
+ String localRepoHead = ConfigUtils.getString(session, null,
MAVEN_REPO_LOCAL_HEAD);
+ if (localRepoHead != null) {
+ Arrays.stream(localRepoHead.split(","))
+ .filter(p -> p != null && !p.trim().isEmpty())
+ .map(this::resolve)
+ .forEach(paths::add);
+ }
- LocalRepositoryManager lrm =
repoSystem.newLocalRepositoryManager(session, localRepo);
+ paths.add(request.getLocalRepository().getBasedir());
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(","))
+ Arrays.stream(localRepoTail.split(","))
.filter(p -> p != null && !p.trim().isEmpty())
- .collect(toList());
+ .map(this::resolve)
+ .forEach(paths::add);
+ }
+
+ LocalRepository localRepo = new LocalRepository(paths.remove(0));
+ LocalRepositoryManager lrm =
repoSystem.newLocalRepositoryManager(session, localRepo);
+
+ if (paths.isEmpty()) {
+ // we have only one local repo path
+ session.setLocalRepositoryManager(lrm);
+ } else {
+ List<LocalRepositoryManager> tail = new ArrayList<>();
for (String path : paths) {
tail.add(repoSystem.newLocalRepositoryManager(session, new
LocalRepository(path)));
}
+ boolean ignoreTailAvailability =
+ ConfigUtils.getBoolean(session, true,
MAVEN_REPO_LOCAL_TAIL_IGNORE_AVAILABILITY);
+
session.setLocalRepositoryManager(new
ChainedLocalRepositoryManager(lrm, tail, ignoreTailAvailability));
+ }
+ }
+
+ private String resolve(String string) {
+ if (string.startsWith("~/") || string.startsWith("~\\")) {
+ // resolve based on $HOME
+ return Paths.get(System.getProperty("user.home"))
+ .resolve(string.substring(2))
+ .normalize()
+ .toAbsolutePath()
+ .toString();
} else {
- session.setLocalRepositoryManager(lrm);
+ // resolve based on $CWD
+ return Paths.get(string).normalize().toAbsolutePath().toString();
}
}