mirror of https://github.com/sbt/sbt.git
Report failed compilation if errors are registered.
In some cases, the local java compiler may report compilation errors, but succeed in compiling the source files (for instance, if there are encoding problems in the source). However, the command line javac will report a failed compilation on the same input. To have the local java compiler behave like the forked java compiler, we now report the compilation as failed if error messages have been registered during compilation. Fixes sbt/sbt#2228
This commit is contained in:
parent
33478132c5
commit
4a4a3ca94e
|
|
@ -14,6 +14,10 @@ import javax.tools.Diagnostic.NOPOS
|
|||
final class DiagnosticsReporter(reporter: Reporter) extends DiagnosticListener[JavaFileObject] {
|
||||
val END_OF_LINE_MATCHER = "(\r\n)|[\r]|[\n]"
|
||||
val EOL = System.getProperty("line.separator")
|
||||
|
||||
private[this] var errorEncountered = false
|
||||
def hasErrors: Boolean = errorEncountered
|
||||
|
||||
private def fixedDiagnosticMessage(d: Diagnostic[_ <: JavaFileObject]): String = {
|
||||
def getRawMessage = d.getMessage(null)
|
||||
def fixWarnOrErrorMessage = {
|
||||
|
|
@ -110,6 +114,7 @@ final class DiagnosticsReporter(reporter: Reporter) extends DiagnosticListener[J
|
|||
if (sourceUri.isDefined) s"${sourceUri.get}:${if (line.isDefined) line.get else -1}"
|
||||
else ""
|
||||
}
|
||||
if (severity == Severity.Error) errorEncountered = true
|
||||
reporter.log(pos, msg, severity)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ 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)
|
||||
compiler.getTask(logWriter, fileManager, diagnostics, options.asJava, null, jfiles).call()
|
||||
val success = compiler.getTask(logWriter, fileManager, diagnostics, options.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.
|
||||
success && !diagnostics.hasErrors
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue