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

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 92d53cb707 Remove use of toRealPath (#11250)
92d53cb707 is described below

commit 92d53cb7075d4ff62fff0a05c7bc6b1d51566db8
Author: Tamas Cservenak <[email protected]>
AuthorDate: Mon Oct 13 20:30:29 2025 +0200

    Remove use of toRealPath (#11250)
    
    As this makes us "escape" from paths that are symbolic links, and
    also causes inconsistencies among paths (like maven home,
    and system settings and system toolchains).
---
 .../src/main/java/org/apache/maven/cli/MavenCli.java    |  6 +-----
 .../java/org/apache/maven/cling/invoker/CliUtils.java   |  7 +------
 .../java/org/apache/maven/api/cli/ExecutorRequest.java  | 17 ++++++++---------
 .../cling/executor/embedded/EmbeddedMavenExecutor.java  |  6 ++++--
 .../maven/cling/executor/internal/HelperImpl.java       |  4 +---
 .../impl/model/rootlocator/DefaultRootLocator.java      |  6 +-----
 .../apache/maven/it/MavenITmng8181CentralRepoTest.java  | 11 ++++++++---
 7 files changed, 24 insertions(+), 33 deletions(-)

diff --git 
a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java 
b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 9e1d1a1932..33d0649777 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -1720,11 +1720,7 @@ private static String 
stripLeadingAndTrailingQuotes(String str) {
     }
 
     private static Path getCanonicalPath(Path path) {
-        try {
-            return path.toRealPath();
-        } catch (IOException e) {
-            return 
getCanonicalPath(path.getParent()).resolve(path.getFileName());
-        }
+        return path.toAbsolutePath().normalize();
     }
 
     static class ExitException extends Exception {
diff --git 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CliUtils.java 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CliUtils.java
index 503ee85908..834f017b2e 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CliUtils.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CliUtils.java
@@ -18,7 +18,6 @@
  */
 package org.apache.maven.cling.invoker;
 
-import java.io.IOException;
 import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.Map;
@@ -60,11 +59,7 @@ public static String stripLeadingAndTrailingQuotes(String 
str) {
     @Nonnull
     public static Path getCanonicalPath(Path path) {
         requireNonNull(path, "path");
-        try {
-            return path.toRealPath();
-        } catch (IOException e) {
-            return 
getCanonicalPath(path.getParent()).resolve(path.getFileName());
-        }
+        return path.toAbsolutePath().normalize();
     }
 
     @Nonnull
diff --git 
a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java
 
b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java
index 406e1a4404..b056c0f845 100644
--- 
a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java
+++ 
b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.maven.api.cli;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.file.Path;
@@ -401,9 +400,13 @@ private Impl(
                 this.cwd = getCanonicalPath(requireNonNull(cwd));
                 this.installationDirectory = 
getCanonicalPath(requireNonNull(installationDirectory));
                 this.userHomeDirectory = 
getCanonicalPath(requireNonNull(userHomeDirectory));
-                this.jvmSystemProperties = jvmSystemProperties != null ? 
Map.copyOf(jvmSystemProperties) : null;
-                this.environmentVariables = environmentVariables != null ? 
Map.copyOf(environmentVariables) : null;
-                this.jvmArguments = jvmArguments != null ? 
List.copyOf(jvmArguments) : null;
+                this.jvmSystemProperties = jvmSystemProperties != null && 
!jvmSystemProperties.isEmpty()
+                        ? Map.copyOf(jvmSystemProperties)
+                        : null;
+                this.environmentVariables = environmentVariables != null && 
!environmentVariables.isEmpty()
+                        ? Map.copyOf(environmentVariables)
+                        : null;
+                this.jvmArguments = jvmArguments != null && 
!jvmArguments.isEmpty() ? List.copyOf(jvmArguments) : null;
                 this.stdIn = stdIn;
                 this.stdOut = stdOut;
                 this.stdErr = stdErr;
@@ -510,10 +513,6 @@ static Path discoverUserHomeDirectory() {
     @Nonnull
     static Path getCanonicalPath(Path path) {
         requireNonNull(path, "path");
-        try {
-            return path.toRealPath();
-        } catch (IOException e) {
-            return 
getCanonicalPath(path.getParent()).resolve(path.getFileName());
-        }
+        return path.toAbsolutePath().normalize();
     }
 }
diff --git 
a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java
 
b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java
index 07194c2798..fff8226bea 100644
--- 
a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java
+++ 
b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java
@@ -208,10 +208,12 @@ protected Context doCreate(Path mavenHome, 
ExecutorRequest executorRequest) {
                     getClass().getSimpleName() + " does not support command " 
+ executorRequest.command());
         }
         if (executorRequest.environmentVariables().isPresent()) {
-            throw new IllegalArgumentException(getClass().getSimpleName() + " 
does not support environment variables");
+            throw new IllegalArgumentException(getClass().getSimpleName() + " 
does not support environment variables: "
+                    + executorRequest.environmentVariables().get());
         }
         if (executorRequest.jvmArguments().isPresent()) {
-            throw new IllegalArgumentException(getClass().getSimpleName() + " 
does not support jvmArguments");
+            throw new IllegalArgumentException(getClass().getSimpleName() + " 
does not support jvmArguments: "
+                    + executorRequest.jvmArguments().get());
         }
         Path boot = mavenHome.resolve("boot");
         Path m2conf = mavenHome.resolve("bin/m2.conf");
diff --git 
a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java
 
b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java
index 9a94ddc2dd..8ba932cabf 100644
--- 
a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java
+++ 
b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java
@@ -19,7 +19,6 @@
 package org.apache.maven.cling.executor.internal;
 
 import java.nio.file.Path;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -94,8 +93,7 @@ protected Executor getExecutor(Mode mode, ExecutorRequest 
request) throws Execut
     }
 
     private Executor getExecutorByRequest(ExecutorRequest request) {
-        if 
(request.environmentVariables().orElse(Collections.emptyMap()).isEmpty()
-                && 
request.jvmArguments().orElse(Collections.emptyList()).isEmpty()) {
+        if (request.environmentVariables().isEmpty() && 
request.jvmArguments().isEmpty()) {
             return getExecutor(Mode.EMBEDDED, request);
         } else {
             return getExecutor(Mode.FORKED, request);
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
index bd224dcafc..8902529fae 100644
--- 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
+++ 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/rootlocator/DefaultRootLocator.java
@@ -98,10 +98,6 @@ protected Optional<Path> getRootDirectoryFallback() {
     }
 
     protected Path getCanonicalPath(Path path) {
-        try {
-            return path.toRealPath();
-        } catch (IOException e) {
-            return 
getCanonicalPath(path.getParent()).resolve(path.getFileName());
-        }
+        return path.toAbsolutePath().normalize();
     }
 }
diff --git 
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8181CentralRepoTest.java
 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8181CentralRepoTest.java
index 30ffdcbec9..a03d057027 100644
--- 
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8181CentralRepoTest.java
+++ 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8181CentralRepoTest.java
@@ -47,10 +47,15 @@ public void testitModel() throws Exception {
         verifier.addCliArgument("--settings=settings.xml");
         verifier.addCliArgument("-Dmaven.repo.local=" + 
testDir.toPath().resolve("target/local-repo"));
         verifier.addCliArgument("-Dmaven.repo.local.tail=target/null");
-        
verifier.addCliArgument("-Dmaven.repo.central=http://repo1.maven.org/";);
+        // note: intentionally bad URL, we just want tu ensure that this bad 
URL is used
+        
verifier.addCliArgument("-Dmaven.repo.central=https://repo1.maven.org";);
         verifier.addCliArgument("validate");
-        verifier.setHandleLocalRepoTail(false); // we want isolation to have 
Maven fail due non-HTTPS repo
+        verifier.setHandleLocalRepoTail(false); // we want isolation to have 
Maven fail due bad URL
         assertThrows(VerificationException.class, verifier::execute);
-        verifier.verifyTextInLog("central (http://repo1.maven.org/, default, 
releases)");
+        // error is
+        // PluginResolutionException: Plugin 
eu.maveniverse.maven.mimir:extension3:XXX or one of its dependencies could
+        // not be resolved:
+        //      Could not find artifact 
eu.maveniverse.maven.mimir:extension3:jar:XXX in central 
(https://repo1.maven.org)
+        verifier.verifyTextInLog("central (https://repo1.maven.org)");
     }
 }

Reply via email to