Skip to content

Commit

Permalink
Parse javac non-compile-errors in JavaErrorParser
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Duhemm committed Nov 27, 2015
1 parent 40892a5 commit 8b5d891
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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
Expand Down Expand Up @@ -165,8 +166,17 @@ 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)
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class JavaErrorParserSpec extends UnitSpec {
"The JavaErrorParser" should "be able to parse linux errors" in parseSampleLinux()
it should "be able to parse windows file names" in parseWindowsFile()
it should "be able to parse windows errors" in parseSampleWindows()
it should "be able to parse javac errors" in parseSampleJavac()

def parseSampleLinux() = {
val parser = new JavaErrorParser()
Expand Down Expand Up @@ -43,6 +44,14 @@ class JavaErrorParserSpec extends UnitSpec {
}
}

def parseSampleJavac() = {
val parser = new JavaErrorParser()
val logger = Logger.Null
val problems = parser.parseProblems(sampleJavacMessage, logger)
problems should have size (1)
problems(0).message shouldBe (sampleJavacMessage)
}

def sampleLinuxMessage =
"""
|/home/me/projects/sample/src/main/Test.java:4: cannot find symbol
Expand All @@ -61,4 +70,6 @@ class JavaErrorParserSpec extends UnitSpec {

def windowsFile = """C:\Projects\sample\src\main\java\Test.java"""
def windowsFileAndLine = s"""$windowsFile:4"""

def sampleJavacMessage = "javac: invalid flag: -foobar"
}

0 comments on commit 8b5d891

Please sign in to comment.