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 81ec24ce..cdfda1d0 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 @@ -956,11 +956,14 @@ static CompilerMessage parseModernError(int exitCode, String error) { final StringBuilder msgBuffer = new StringBuilder(); String msg = tokens.nextToken(EOL).substring(2); - // Remove the 'warning: ' prefix - final String warnPrefix = getWarningPrefix(msg); - if (warnPrefix != null) { + // Remove "error: " and "warning: " prefixes + String prefix; + if ((prefix = getErrorPrefix(msg)) != null) { + messageKind = ERROR; + msg = msg.substring(prefix.length()); + } else if ((prefix = getWarningPrefix(msg)) != null) { messageKind = WARNING; - msg = msg.substring(warnPrefix.length()); + msg = msg.substring(prefix.length()); } msgBuffer.append(msg).append(EOL); @@ -999,15 +1002,23 @@ static CompilerMessage parseModernError(int exitCode, String error) { } } - private static String getWarningPrefix(String msg) { - for (String warningPrefix : WARNING_PREFIXES) { - if (msg.startsWith(warningPrefix)) { - return warningPrefix; + private static String getMessagePrefix(String message, String[] prefixes) { + for (String prefix : prefixes) { + if (message.startsWith(prefix)) { + return prefix; } } return null; } + private static String getWarningPrefix(String message) { + return getMessagePrefix(message, WARNING_PREFIXES); + } + + private static String getErrorPrefix(String message) { + return getMessagePrefix(message, ERROR_PREFIXES); + } + /** * put args into a temp file to be referenced using the @ option in javac command line * 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 8ac5ddff..ad707f4e 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 @@ -753,8 +753,7 @@ public void testJava7Error() throws Exception { assertThat( message1.getMessage(), - is("error: cannot find symbol" + EOL + " symbol: class Properties" + EOL - + " location: class Error")); + is("cannot find symbol" + EOL + " symbol: class Properties" + EOL + " location: class Error")); assertThat(message1.getStartColumn(), is(16)); @@ -770,8 +769,7 @@ public void testJava7Error() throws Exception { assertThat( message2.getMessage(), - is("error: cannot find symbol" + EOL + " symbol: class Properties" + EOL - + " location: class Error")); + is("cannot find symbol" + EOL + " symbol: class Properties" + EOL + " location: class Error")); assertThat(message2.getStartColumn(), is(35)); @@ -1259,7 +1257,7 @@ public void testWarningFollowedByBadSourceFileError() throws Exception { private void validateBadSourceFile(CompilerMessage message) { assertThat("Is an Error", message.getKind(), is(CompilerMessage.Kind.ERROR)); assertThat("On Correct File", message.getFile(), is("/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java")); - assertThat("Message starts with access Error", message.getMessage(), startsWith("error: cannot access Cls2")); + assertThat("Message starts with access Error", message.getMessage(), startsWith("cannot access Cls2")); } private static void assertEquivalent(CompilerMessage expected, CompilerMessage actual) {