Merge pull request #2272 from Duhemm/fix-1968

Don't pass `-J<flag>` to local java, improve javac's error parsing
This commit is contained in:
eugene yokota 2015-11-27 15:37:16 -05:00
commit c5b7fc1d9c
5 changed files with 60 additions and 8 deletions

View File

@ -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)
/**

View File

@ -66,7 +66,16 @@ final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends JavaCo
val diagnostics = new DiagnosticsReporter(reporter)
val fileManager = compiler.getStandardFileManager(diagnostics, null, null)
val jfiles = fileManager.getJavaFileObjectsFromFiles(sources.asJava)
val success = compiler.getTask(logWriter, fileManager, diagnostics, options.asJava, null, jfiles).call()
// Local Java compiler doesn't accept `-J<flag>` options. We emit a warning if we find
// such options and don't pass them to the compiler.
val (invalidOptions, cleanedOptions) = options partition (_ startsWith "-J")
if (invalidOptions.nonEmpty) {
log.warn("Javac is running in 'local' mode. These flags have been removed:")
log.warn(invalidOptions.mkString("\t", ", ", ""))
}
val success = compiler.getTask(logWriter, fileManager, diagnostics, cleanedOptions.asJava, null, jfiles).call()
// The local compiler may report a successful compilation even though there are errors (e.g. encoding problems in the
// source files). In a similar situation, command line javac reports a failed compilation. To have the local java compiler
// stick to javac's behavior, we report a failed compilation if there have been errors.

View File

@ -15,9 +15,10 @@ 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 = {
def parseSampleLinux: MatchResult[_] = {
val parser = new JavaErrorParser()
val logger = Logger.Null
val problems = parser.parseProblems(sampleLinuxMessage, logger)
@ -26,7 +27,7 @@ object JavaErrorParserSpec extends Specification {
rightSize and rightFile
}
def parseSampleWindows = {
def parseSampleWindows: MatchResult[_] = {
val parser = new JavaErrorParser()
val logger = Logger.Null
val problems = parser.parseProblems(sampleWindowsMessage, logger)
@ -45,7 +46,16 @@ object JavaErrorParserSpec extends Specification {
}
}
def sampleLinuxMessage =
def parseSampleJavac: MatchResult[_] = {
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: String =
"""
|/home/me/projects/sample/src/main/Test.java:4: cannot find symbol
|symbol : method baz()
@ -53,7 +63,7 @@ object JavaErrorParserSpec extends Specification {
|return baz();
""".stripMargin
def sampleWindowsMessage =
def sampleWindowsMessage: String =
s"""
|$windowsFile:4: cannot find symbol
|symbol : method baz()
@ -61,6 +71,8 @@ object JavaErrorParserSpec extends Specification {
|return baz();
""".stripMargin
def windowsFile = """C:\Projects\sample\src\main\java\Test.java"""
def windowsFileAndLine = s"""$windowsFile:4"""
def windowsFile: String = """C:\Projects\sample\src\main\java\Test.java"""
def windowsFileAndLine: String = s"""$windowsFile:4"""
def sampleJavacMessage = "javac: invalid flag: -foobar"
}

View File

@ -0,0 +1,11 @@
[@Duhemm]: http://github.com/Duhemm
[1968]: https://github.com/sbt/sbt/issues/1968
[2272]: https://github.com/sbt/sbt/pull/2272
### Fixes with compatibility implications
### Improvements
### Bug fixes
- Don't pass `-J<flag>` options to the local java compiler (issue [#1968][1968]) [#2272][2272] by [@Duhemm][@Duhemm]

View File

@ -0,0 +1,11 @@
[@Duhemm]: http://github.com/Duhemm
[2256]: https://github.com/sbt/sbt/issues/2256
[2272]: https://github.com/sbt/sbt/pull/2272
### Fixes with compatibility implications
### Improvements
### Bug fixes
- Improve `JavaErrorParser` to parse non-compile-errors (issue [#2256][2256]) [#2272][2272] by [@Duhemm][@Duhemm]