Skip to content

Commit

Permalink
[MNG-8159] Fix search for topDirectory when using -f / --file (#1589)
Browse files Browse the repository at this point in the history
Backport 08e996b

Co-authored-by: Guillaume Nodet <[email protected]>

---

https://issues.apache.org/jira/browse/MNG-8159
  • Loading branch information
gzm55 authored Jun 20, 2024
1 parent 1b3828e commit 6e8550c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void initialize(CliRequest cliRequest) throws ExitException {
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)) {
Expand All @@ -343,7 +343,7 @@ void initialize(CliRequest cliRequest) throws ExitException {
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);
Expand Down Expand Up @@ -1593,6 +1593,18 @@ public Object getValue(String expression) {
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();
Expand Down

0 comments on commit 6e8550c

Please sign in to comment.