diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java index f25e099b..aa403820 100644 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java @@ -56,8 +56,13 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.Deque; import java.util.HashSet; import java.util.List; @@ -545,6 +550,14 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin try { returnCode = CommandLineUtils.executeCommandLine(cli, out, out); + Path logsDir = config.getBuildDirectory().toPath().resolve("compiler-logs"); + if (!Files.exists(logsDir)) { + Files.createDirectories(logsDir); + } + SimpleDateFormat dateFormat = new SimpleDateFormat("'javac'_yyyy-MM-dd'T'HH_mm_ss.'log'"); + String logFileName = dateFormat.format(new Date()); + Files.write(logsDir.resolve(logFileName), out.getOutput().getBytes(StandardCharsets.UTF_8)); + messages = parseModernStream(returnCode, new BufferedReader(new StringReader(out.getOutput()))); } catch (CommandLineException | IOException e) { throw new CompilerException("Error while executing the external compiler.", e);