From d125a36b6c76a7fb8b67ebee533b1f6b4c7432e8 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Mon, 2 Nov 2015 14:08:06 +0100 Subject: [PATCH] Parse javac non-compile-errors in JavaErrorParser Upon startup, javac may report errors because (for instance) because it received incorrect flags. These errors were not correctly parsed by the JavaErrorParser and were never reported to the user. This commit fixes this problem by adding a new parsing rule in JavaErrorParser: errors that start with the prefix "javac:" are now correctly parsed and reported to the user. Fixes sbt/sbt#2256 --- .../scala/sbt/compiler/javac/JavaErrorParser.scala | 11 ++++++++++- .../sbt/compiler/javac/javaErrorParserSpec.scala | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/compile/src/main/scala/sbt/compiler/javac/JavaErrorParser.scala b/compile/src/main/scala/sbt/compiler/javac/JavaErrorParser.scala index 69218f159..690274a66 100644 --- a/compile/src/main/scala/sbt/compiler/javac/JavaErrorParser.scala +++ b/compile/src/main/scala/sbt/compiler/javac/JavaErrorParser.scala @@ -44,6 +44,7 @@ class JavaErrorParser(relativeDir: File = new File(new File(".").getAbsolutePath override val skipWhitespace = false + val JAVAC: Parser[String] = literal("javac") val CHARAT: Parser[String] = literal("^") val SEMICOLON: Parser[String] = literal(":") | literal("\uff1a") val SYMBOL: Parser[String] = allUntilChar(':') // We ignore whether it actually says "symbol" for i18n @@ -161,8 +162,16 @@ class JavaErrorParser(relativeDir: File = new File(new File(".").getAbsolutePath msg ) } + val javacError: Parser[Problem] = + JAVAC ~ SEMICOLON ~ restOfLine ^^ { + case _ ~ _ ~ error => + new JavaProblem( + JavaNoPosition, + Severity.Error, + s"javac:$error") + } - val potentialProblem: Parser[Problem] = warningMessage | errorMessage | noteMessage + val potentialProblem: Parser[Problem] = warningMessage | errorMessage | noteMessage | javacError val javacOutput: Parser[Seq[Problem]] = rep(potentialProblem) /** diff --git a/compile/src/test/scala/sbt/compiler/javac/javaErrorParserSpec.scala b/compile/src/test/scala/sbt/compiler/javac/javaErrorParserSpec.scala index aa3fa24c4..b7e088b2e 100644 --- a/compile/src/test/scala/sbt/compiler/javac/javaErrorParserSpec.scala +++ b/compile/src/test/scala/sbt/compiler/javac/javaErrorParserSpec.scala @@ -15,6 +15,7 @@ object JavaErrorParserSpec extends Specification { be able to parse linux errors $parseSampleLinux be able to parse windows file names $parseWindowsFile be able to parse windows errors $parseSampleWindows + be able to parse javac errors $parseSampleJavac """ def parseSampleLinux = { @@ -45,6 +46,15 @@ object JavaErrorParserSpec extends Specification { } } + def parseSampleJavac = { + val parser = new JavaErrorParser() + val logger = Logger.Null + val problems = parser.parseProblems(sampleJavacMessage, logger) + def rightSize = problems must haveSize(1) + def rightError = problems(0).message must beEqualTo(sampleJavacMessage) + rightSize and rightError + } + def sampleLinuxMessage = """ |/home/me/projects/sample/src/main/Test.java:4: cannot find symbol @@ -63,4 +73,6 @@ object JavaErrorParserSpec extends Specification { def windowsFile = """C:\Projects\sample\src\main\java\Test.java""" def windowsFileAndLine = s"""$windowsFile:4""" + + def sampleJavacMessage = "javac: invalid flag: -foobar" }