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 f685c24d..9297d3d4 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 @@ -755,6 +755,10 @@ else if ( hasPointer ) errors.add( new CompilerMessage( buffer.toString(), CompilerMessage.Kind.ERROR ) ); return errors; } + else if ( line.startsWith( "An annotation processor threw an uncaught exception." ) ) { + CompilerMessage annotationProcessingError = parseAnnotationProcessorStream( input ); + errors.add( annotationProcessingError ); + } // new error block? if ( !line.startsWith( " " ) && hasPointer ) @@ -800,6 +804,23 @@ else if ( ( buffer.length() == 0 ) && isMisc( line ) ) } } + private static CompilerMessage parseAnnotationProcessorStream( final BufferedReader input ) + throws IOException + { + String line = input.readLine(); + final StringBuilder buffer = new StringBuilder(); + + while (line != null) { + if (!line.startsWith( "Consult the following stack trace for details." )) { + buffer.append(line); + buffer.append(EOL); + } + line = input.readLine(); + } + + return new CompilerMessage( buffer.toString(), CompilerMessage.Kind.ERROR ); + } + private static boolean isMisc( String line ) { return startsWithPrefix( line, MISC_PREFIXES ); diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java index 1830ef69..4fbcff48 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java @@ -1,6 +1,15 @@ package org.codehaus.plexus.compiler.javac; +import org.codehaus.plexus.compiler.CompilerMessage; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -33,4 +42,36 @@ public void setUp() super.setUp(); setForceJavacCompilerUse( true ); } + + @Test + void parseModernStream_withAnnotationProcessingErrors() throws IOException + { + String input = + "\n" + + "\n" + + "An annotation processor threw an uncaught exception.\n" + + "Consult the following stack trace for details.\n" + + "java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x1da51a35) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x1da51a35\n" + + "\tat lombok.javac.apt.LombokProcessor.getJavacProcessingEnvironment(LombokProcessor.java:433)\n" + + "\tat lombok.javac.apt.LombokProcessor.init(LombokProcessor.java:92)\n" + + "\tat lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:160)\n" + + "\tat lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:213)\n" + + "\tat lombok.launch.AnnotationProcessorHider$AnnotationProcessor.init(AnnotationProcessor.java:64)\n" + + "\tat jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.(JavacProcessingEnvironment.java:702)\n" + + "\tat jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:829)\n" + + "\tat jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:925)\n" + + "\tat jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1269)\n" + + "\tat jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1384)\n" + + "\tat jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1261)\n" + + "\tat jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:935)\n" + + "\tat jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)\n" + + "\tat jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)\n" + + "\tat jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)\n" + + "\tat jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)\n"; + + List compilerMessages = JavacCompiler.parseModernStream( 1, + new BufferedReader( new StringReader( input ) ) ); + + assertThat( compilerMessages ).hasSize( 1 ); + } }