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-7796] Be lenient when using toRealPath #1130

Merged
merged 1 commit into from
May 31, 2023
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
15 changes: 9 additions & 6 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,7 @@ void initialize(CliRequest cliRequest) throws ExitException {
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);
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 rely on the JDK services to eventually lookup a custom RootLocator.
Expand Down Expand Up @@ -1589,6 +1584,14 @@ public Object getValue(String expression) {
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;

Expand Down