Skip to content

Commit

Permalink
Path.relativize() may throw exception if source and build directories…
Browse files Browse the repository at this point in the history
… are on different Windows drives

Closes #364
  • Loading branch information
slachiewicz committed Feb 23, 2024
1 parent 2248255 commit 57dfc26
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,31 @@ private static String getCanonicalPath(File origFile) throws CompilerException {

protected void logCompiling(String[] sourceFiles, CompilerConfiguration config) {
if (log.isInfoEnabled()) {
String to = (config.getWorkingDirectory() == null)
? config.getOutputLocation()
: config.getWorkingDirectory()
.toPath()
.relativize(new File(config.getOutputLocation()).toPath())
.toString();
log.info("Compiling "
+ (sourceFiles == null
? ""
: (sourceFiles.length + " source file" + (sourceFiles.length == 1 ? " " : "s ")))
+ "with "
+ getCompilerId() + " [" + config.describe() + "]" + " to "
+ to);
+ getRelativeWorkingDirectory(config));
}
}

private static String getRelativeWorkingDirectory(CompilerConfiguration config) {
String to;
if (config.getWorkingDirectory() == null) {
to = config.getOutputLocation();
} else {
try {
to = config.getWorkingDirectory()
.toPath()
.relativize(new File(config.getOutputLocation()).toPath())
.toString();
} catch (IllegalArgumentException e) {
// may happen on Windows if the working directory is on a different drive
to = config.getOutputLocation();
}
}
return to;
}
}

0 comments on commit 57dfc26

Please sign in to comment.