Don't pass `-J<flag>` option to local Java compiler

These options can only be given to a forked Java compiler. If we run a
local java compiler, we filter these options out and emit a warning.

Fixes sbt/sbt#1968
This commit is contained in:
Martin Duhem 2015-10-30 19:18:12 +01:00
parent 33478132c5
commit 7af0fea54e
1 changed files with 9 additions and 1 deletions

View File

@ -66,6 +66,14 @@ 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()
// 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", ", ", ""))
}
compiler.getTask(logWriter, fileManager, diagnostics, cleanedOptions.asJava, null, jfiles).call()
}
}