From eb95419d2977ad6c636689bfe71c2da3edd8c296 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 6 Jul 2023 11:22:14 +0200 Subject: [PATCH] Write raw javac output to a log file --- .../plexus/compiler/javac/JavacCompiler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 8650d3cb..77f07621 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 @@ -53,8 +53,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.List; import java.util.Map; import java.util.NoSuchElementException; @@ -634,6 +639,14 @@ protected CompilerResult compileOutOfProcess( CompilerConfiguration config, Stri 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_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() ) ) ); }