Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8159] Fix search for topDirectory when using -f / --file #1589

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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