This is an automated email from the ASF dual-hosted git repository.
cstamas 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 6e8550cd6a [MNG-8159] Fix search for topDirectory when using -f /
--file (#1589)
6e8550cd6a is described below
commit 6e8550cd6a71418a08c57e9055a6556f5d02f760
Author: James Z.M. Gao <[email protected]>
AuthorDate: Thu Jun 20 14:43:05 2024 +0800
[MNG-8159] Fix search for topDirectory when using -f / --file (#1589)
Backport 08e996bb28266a5b1707f45d20809ba44117e16a
Co-authored-by: Guillaume Nodet <[email protected]>
---
https://issues.apache.org/jira/browse/MNG-8159
---
.../src/main/java/org/apache/maven/cli/MavenCli.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 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 f04676d33a..b09a3611e4 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
@@ -325,7 +325,7 @@ public class MavenCli {
for (String arg : cliRequest.args) {
if (isAltFile) {
// this is the argument following -f/--file
- Path path = topDirectory.resolve(arg);
+ Path path =
topDirectory.resolve(stripLeadingAndTrailingQuotes(arg));
if (Files.isDirectory(path)) {
topDirectory = path;
} else if (Files.isRegularFile(path)) {
@@ -343,7 +343,7 @@ public class MavenCli {
break;
} else {
// Check if this is the -f/--file option
- isAltFile =
arg.equals(String.valueOf(CLIManager.ALTERNATE_POM_FILE)) || arg.equals("file");
+ isAltFile = arg.equals("-f") || arg.equals("--file");
}
}
topDirectory = getCanonicalPath(topDirectory);
@@ -1593,6 +1593,18 @@ public class MavenCli {
return interpolator;
}
+ private static String stripLeadingAndTrailingQuotes(String str) {
+ final int length = str.length();
+ if (length > 1
+ && str.startsWith("\"")
+ && str.endsWith("\"")
+ && str.substring(1, length - 1).indexOf('"') == -1) {
+ str = str.substring(1, length - 1);
+ }
+
+ return str;
+ }
+
private static Path getCanonicalPath(Path path) {
try {
return path.toRealPath();