Skip to content

Commit 296f33c

Browse files
zregvartolamy
authored andcommitted
report initialization of boot layer error messages (#54)
This adds support for reporting initialization of boot layer error messages that occur when the `javac` JVM cannot be started. In that case output will contain message like: ``` Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found ``` This message currently would be lost, i.e. the only message reported when used in `maven-compiler-plugin` would be: ``` [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project ...: Compilation failure -> [Help 1] ``` Now an `INFO` message would appear above this as: ``` [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ bom-generator-maven-plugin --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 5 source files to .../target/classes [INFO] Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found ``` Making the error message outputted by `javac` at least visible for troubleshooting.
1 parent ebf54e2 commit 296f33c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,17 @@ static List<CompilerMessage> parseModernStream( int exitCode, BufferedReader inp
679679
{
680680
// javac output not detected by other parsing
681681
// maybe better to ignore only the summary an mark the rest as error
682-
if (buffer.length() > 0 && buffer.toString().startsWith("javac:"))
682+
String bufferAsString = buffer.toString();
683+
if ( buffer.length() > 0 )
683684
{
684-
errors.add( new CompilerMessage( buffer.toString(), CompilerMessage.Kind.ERROR ) );
685+
if ( bufferAsString.startsWith("javac:"))
686+
{
687+
errors.add( new CompilerMessage( bufferAsString, CompilerMessage.Kind.ERROR ) );
688+
}
689+
else if ( bufferAsString.startsWith("Error occurred during initialization of boot layer"))
690+
{
691+
errors.add( new CompilerMessage( bufferAsString, CompilerMessage.Kind.OTHER ) );
692+
}
685693
}
686694
return errors;
687695
}

plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,18 @@ public final void testIssue37() throws IOException {
894894
".tools.javac.Main.main(Main.java:43)" + EOL));
895895
}
896896

897+
public void testJvmError() throws Exception
898+
{
899+
String out = "Error occurred during initialization of boot layer" + EOL +
900+
"java.lang.module.FindException: Module java.xml.bind not found";
901+
902+
List<CompilerMessage> compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) ));
903+
904+
assertNotNull( compilerErrors );
905+
906+
assertEquals( 1, compilerErrors.size() );
907+
}
908+
897909
private static void assertEquivalent(CompilerMessage expected, CompilerMessage actual){
898910
assertEquals("Message did not match", expected.getMessage(), actual.getMessage());
899911
assertEquals("Kind did not match", expected.getKind(), actual.getKind());

0 commit comments

Comments
 (0)