From dd1922bd2481bd3077bb22c605d0d0d8261a5d29 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 31 May 2023 09:40:48 +0200 Subject: [PATCH] [MNG-7796] Be lenient when using toRealPath (#1131) --- .../main/java/org/apache/maven/cli/MavenCli.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 08187d1522..11053828af 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 @@ -349,12 +349,7 @@ public class MavenCli { isAltFile = arg.equals(String.valueOf(CLIManager.ALTERNATE_POM_FILE)) || arg.equals("file"); } } - try { - topDirectory = topDirectory.toAbsolutePath().toRealPath(); - } catch (IOException e) { - System.err.println("Error computing real path from " + topDirectory + ": " + e.getMessage()); - throw new ExitException(1); - } + topDirectory = getCanonicalPath(topDirectory); cliRequest.topDirectory = topDirectory; // We're very early in the process and we don't have the container set up yet, // so we on searchAcceptableRootDirectory method to find us acceptable directory. @@ -1602,6 +1597,14 @@ public class MavenCli { return interpolator; } + private static Path getCanonicalPath(Path path) { + try { + return path.toRealPath(); + } catch (IOException e) { + return getCanonicalPath(path.getParent()).resolve(path.getFileName()); + } + } + static class ExitException extends Exception { int exitCode;