Skip to content

Commit 57dfc26

Browse files
committed
Path.relativize() may throw exception if source and build directories are on different Windows drives
Closes #364
1 parent 2248255 commit 57dfc26

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,31 @@ private static String getCanonicalPath(File origFile) throws CompilerException {
268268

269269
protected void logCompiling(String[] sourceFiles, CompilerConfiguration config) {
270270
if (log.isInfoEnabled()) {
271-
String to = (config.getWorkingDirectory() == null)
272-
? config.getOutputLocation()
273-
: config.getWorkingDirectory()
274-
.toPath()
275-
.relativize(new File(config.getOutputLocation()).toPath())
276-
.toString();
277271
log.info("Compiling "
278272
+ (sourceFiles == null
279273
? ""
280274
: (sourceFiles.length + " source file" + (sourceFiles.length == 1 ? " " : "s ")))
281275
+ "with "
282276
+ getCompilerId() + " [" + config.describe() + "]" + " to "
283-
+ to);
277+
+ getRelativeWorkingDirectory(config));
284278
}
285279
}
280+
281+
private static String getRelativeWorkingDirectory(CompilerConfiguration config) {
282+
String to;
283+
if (config.getWorkingDirectory() == null) {
284+
to = config.getOutputLocation();
285+
} else {
286+
try {
287+
to = config.getWorkingDirectory()
288+
.toPath()
289+
.relativize(new File(config.getOutputLocation()).toPath())
290+
.toString();
291+
} catch (IllegalArgumentException e) {
292+
// may happen on Windows if the working directory is on a different drive
293+
to = config.getOutputLocation();
294+
}
295+
}
296+
return to;
297+
}
286298
}

0 commit comments

Comments
 (0)