mirror of https://github.com/sbt/sbt.git
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
This commit is contained in:
parent
7af0fea54e
commit
d125a36b6c
|
|
@ -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)
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue