You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2023/07/04 06:36:14 UTC
[maven] 01/05: Fix search for topDirectory when using -f / --file
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 08e996bb28266a5b1707f45d20809ba44117e16a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Jun 30 15:27:58 2023 +0200
Fix search for topDirectory when using -f / --file
---
.../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 5070deffa..a4ad1d23f 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
@@ -333,7 +333,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)) {
@@ -351,7 +351,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);
@@ -1616,6 +1616,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();