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 1e97f8e7..0255c2a7 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 @@ -638,6 +638,10 @@ private static CompilerResult compileInProcess0(Class javacClass, String[] ar private static final Pattern STACK_TRACE_OTHER_LINE = Pattern.compile("^(?:Caused by:\\s.*|\\s*at .*|\\s*\\.\\.\\.\\s\\d+\\smore)$"); + // Match generic javac errors with 'javac:' prefix, JMV init and boot layer init errors + private static final Pattern JAVAC_OR_JVM_ERROR = + Pattern.compile("^(?:javac:|Error occurred during initialization of (?:boot layer|VM)).*", Pattern.DOTALL); + /** * Parse the output from the compiler into a list of CompilerMessage objects * @@ -664,10 +668,8 @@ static List parseModernStream(int exitCode, BufferedReader inpu // maybe better to ignore only the summary and mark the rest as error String bufferAsString = buffer.toString(); if (buffer.length() > 0) { - if (bufferAsString.startsWith("javac:")) { + if (JAVAC_OR_JVM_ERROR.matcher(bufferAsString).matches()) { errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.ERROR)); - } else if (bufferAsString.startsWith("Error occurred during initialization of boot layer")) { - errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.OTHER)); } else if (hasPointer) { // A compiler message remains in buffer at end of parse stream errors.add(parseModernError(exitCode, bufferAsString)); diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java index d8f01590..5ab3c822 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java @@ -1010,7 +1010,7 @@ public void testIssue37() throws IOException { } @Test - public void testJvmError() throws Exception { + public void testJvmBootLayerInitializationError() throws Exception { String out = "Error occurred during initialization of boot layer" + EOL + "java.lang.module.FindException: Module java.xml.bind not found"; @@ -1018,8 +1018,21 @@ public void testJvmError() throws Exception { JavacCompiler.parseModernStream(1, new BufferedReader(new StringReader(out))); assertThat(compilerErrors, notNullValue()); + assertThat(compilerErrors.size(), is(1)); + assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR)); + } + + @Test + public void testJvmInitializationError() throws Exception { + String out = "Error occurred during initialization of VM" + EOL + + "Initial heap size set to a larger value than the maximum heap size"; + List compilerErrors = + JavacCompiler.parseModernStream(1, new BufferedReader(new StringReader(out))); + + assertThat(compilerErrors, notNullValue()); assertThat(compilerErrors.size(), is(1)); + assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR)); } @Test