mirror of https://github.com/sbt/sbt.git
Merge branch 'wip/incremental-compiler-javac-cleanup' of https://github.com/jsuereth/xsbt into wip/incremental-compiler-javac-cleanup
This commit is contained in:
commit
3876082172
|
|
@ -200,13 +200,14 @@ object AggressiveCompile {
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@deprecated("0.13.8", "Deprecated in favor of new sbt.compiler.javac package.")
|
||||||
def directOrFork(instance: ScalaInstance, cpOptions: ClasspathOptions, javaHome: Option[File]): JavaTool =
|
def directOrFork(instance: ScalaInstance, cpOptions: ClasspathOptions, javaHome: Option[File]): JavaTool =
|
||||||
if (javaHome.isDefined)
|
if (javaHome.isDefined)
|
||||||
JavaCompiler.fork(cpOptions, instance)(forkJavac(javaHome))
|
JavaCompiler.fork(cpOptions, instance)(forkJavac(javaHome))
|
||||||
else
|
else
|
||||||
JavaCompiler.directOrFork(cpOptions, instance)(forkJavac(None))
|
JavaCompiler.directOrFork(cpOptions, instance)(forkJavac(None))
|
||||||
|
|
||||||
|
@deprecated("0.13.8", "Deprecated in favor of new sbt.compiler.javac package.")
|
||||||
def forkJavac(javaHome: Option[File]): JavaCompiler.Fork =
|
def forkJavac(javaHome: Option[File]): JavaCompiler.Fork =
|
||||||
{
|
{
|
||||||
import Path._
|
import Path._
|
||||||
|
|
@ -225,6 +226,7 @@ object AggressiveCompile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@deprecated("0.13.8", "Deprecated in favor of new sbt.compiler.javac package.")
|
||||||
private[sbt] class JavacLogger(log: Logger) extends ProcessLogger {
|
private[sbt] class JavacLogger(log: Logger) extends ProcessLogger {
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
import Level.{ Info, Warn, Error, Value => LogLevel }
|
import Level.{ Info, Warn, Error, Value => LogLevel }
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import xsbti.{ Severity, Reporter }
|
||||||
* @param reporter
|
* @param reporter
|
||||||
*/
|
*/
|
||||||
final class DiagnosticsReporter(reporter: Reporter) extends DiagnosticListener[JavaFileObject] {
|
final class DiagnosticsReporter(reporter: Reporter) extends DiagnosticListener[JavaFileObject] {
|
||||||
val END_OF_LINE_MATCHER = "[\r\n]|[\r]|[\n]"
|
val END_OF_LINE_MATCHER = "(\r\n)|[\r]|[\n]"
|
||||||
val EOL = System.getProperty("line.separator")
|
val EOL = System.getProperty("line.separator")
|
||||||
private def fixedDiagnosticMessage(d: Diagnostic[_ <: JavaFileObject]): String = {
|
private def fixedDiagnosticMessage(d: Diagnostic[_ <: JavaFileObject]): String = {
|
||||||
def getRawMessage = d.getMessage(null)
|
def getRawMessage = d.getMessage(null)
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ object ForkedJava {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An implementation of compiling java which forks a Javac instance. */
|
/** An implementation of compiling java which forks a Javac instance. */
|
||||||
final class ForkedJavaCompiler(javaHome: Option[File]) extends NewJavaCompiler {
|
final class ForkedJavaCompiler(javaHome: Option[File]) extends JavaCompiler {
|
||||||
def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean =
|
def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean =
|
||||||
ForkedJava.launch(javaHome, "javac", sources, options, log, reporter)
|
ForkedJava.launch(javaHome, "javac", sources, options, log, reporter)
|
||||||
}
|
}
|
||||||
final class ForkedJavadoc(javaHome: Option[File]) extends NewJavadoc {
|
final class ForkedJavadoc(javaHome: Option[File]) extends Javadoc {
|
||||||
def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean =
|
def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean =
|
||||||
ForkedJava.launch(javaHome, "javadoc", sources, options, log, reporter)
|
ForkedJava.launch(javaHome, "javadoc", sources, options, log, reporter)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import xsbti.{ Severity, Reporter }
|
||||||
*/
|
*/
|
||||||
sealed trait JavaTools {
|
sealed trait JavaTools {
|
||||||
/** The raw interface of the java compiler for direct access. */
|
/** The raw interface of the java compiler for direct access. */
|
||||||
def compiler: NewJavaTool
|
def compiler: JavaTool
|
||||||
/**
|
/**
|
||||||
* This will run a java compiler.
|
* This will run a java compiler.
|
||||||
*
|
*
|
||||||
|
|
@ -53,7 +53,7 @@ sealed trait IncrementalCompilerJavaTools extends JavaTools {
|
||||||
/** Factory methods for getting a java toolchain. */
|
/** Factory methods for getting a java toolchain. */
|
||||||
object JavaTools {
|
object JavaTools {
|
||||||
/** Create a new aggregate tool from existing tools. */
|
/** Create a new aggregate tool from existing tools. */
|
||||||
def apply(c: NewJavaCompiler, docgen: NewJavadoc): JavaTools =
|
def apply(c: JavaCompiler, docgen: Javadoc): JavaTools =
|
||||||
new JavaTools {
|
new JavaTools {
|
||||||
override def compiler = c
|
override def compiler = c
|
||||||
def compile(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean =
|
def compile(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean =
|
||||||
|
|
@ -77,10 +77,10 @@ object JavaTools {
|
||||||
*/
|
*/
|
||||||
def directOrFork(instance: xsbti.compile.ScalaInstance, cpOptions: xsbti.compile.ClasspathOptions, javaHome: Option[File]): IncrementalCompilerJavaTools = {
|
def directOrFork(instance: xsbti.compile.ScalaInstance, cpOptions: xsbti.compile.ClasspathOptions, javaHome: Option[File]): IncrementalCompilerJavaTools = {
|
||||||
val (compiler, doc) = javaHome match {
|
val (compiler, doc) = javaHome match {
|
||||||
case Some(_) => (NewJavaCompiler.fork(javaHome), NewJavadoc.fork(javaHome))
|
case Some(_) => (JavaCompiler.fork(javaHome), Javadoc.fork(javaHome))
|
||||||
case _ =>
|
case _ =>
|
||||||
val c = NewJavaCompiler.local.getOrElse(NewJavaCompiler.fork(None))
|
val c = JavaCompiler.local.getOrElse(JavaCompiler.fork(None))
|
||||||
val d = NewJavadoc.local.getOrElse(NewJavadoc.fork())
|
val d = Javadoc.local.getOrElse(Javadoc.fork())
|
||||||
(c, d)
|
(c, d)
|
||||||
}
|
}
|
||||||
val delegate = apply(compiler, doc)
|
val delegate = apply(compiler, doc)
|
||||||
|
|
@ -102,7 +102,7 @@ object JavaTools {
|
||||||
* - The all take sources and options and log error messages
|
* - The all take sources and options and log error messages
|
||||||
* - They return success or failure.
|
* - They return success or failure.
|
||||||
*/
|
*/
|
||||||
sealed trait NewJavaTool {
|
sealed trait JavaTool {
|
||||||
/**
|
/**
|
||||||
* This will run a java compiler / or other like tool (e.g. javadoc).
|
* This will run a java compiler / or other like tool (e.g. javadoc).
|
||||||
*
|
*
|
||||||
|
|
@ -117,34 +117,34 @@ sealed trait NewJavaTool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Interface we use to compile java code. This is mostly a tag over the raw JavaTool interface. */
|
/** Interface we use to compile java code. This is mostly a tag over the raw JavaTool interface. */
|
||||||
trait NewJavaCompiler extends NewJavaTool {}
|
trait JavaCompiler extends JavaTool {}
|
||||||
/** Factory methods for constructing a java compiler. */
|
/** Factory methods for constructing a java compiler. */
|
||||||
object NewJavaCompiler {
|
object JavaCompiler {
|
||||||
/** Returns a local compiler, if the current runtime supports it. */
|
/** Returns a local compiler, if the current runtime supports it. */
|
||||||
def local: Option[NewJavaCompiler] =
|
def local: Option[JavaCompiler] =
|
||||||
for {
|
for {
|
||||||
compiler <- Option(javax.tools.ToolProvider.getSystemJavaCompiler)
|
compiler <- Option(javax.tools.ToolProvider.getSystemJavaCompiler)
|
||||||
} yield new LocalJavaCompiler(compiler)
|
} yield new LocalJavaCompiler(compiler)
|
||||||
|
|
||||||
/** Returns a local compiler that will fork javac when needed. */
|
/** Returns a local compiler that will fork javac when needed. */
|
||||||
def fork(javaHome: Option[File] = None): NewJavaCompiler =
|
def fork(javaHome: Option[File] = None): JavaCompiler =
|
||||||
new ForkedJavaCompiler(javaHome)
|
new ForkedJavaCompiler(javaHome)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Interface we use to document java code. This is a tag over the raw JavaTool interface. */
|
/** Interface we use to document java code. This is a tag over the raw JavaTool interface. */
|
||||||
trait NewJavadoc extends NewJavaTool {}
|
trait Javadoc extends JavaTool {}
|
||||||
/** Factory methods for constructing a javadoc. */
|
/** Factory methods for constructing a javadoc. */
|
||||||
object NewJavadoc {
|
object Javadoc {
|
||||||
/** Returns a local compiler, if the current runtime supports it. */
|
/** Returns a local compiler, if the current runtime supports it. */
|
||||||
def local: Option[NewJavadoc] =
|
def local: Option[Javadoc] =
|
||||||
// TODO - javax doc tool not supported in JDK6
|
// TODO - javax doc tool not supported in JDK6
|
||||||
//Option(javax.tools.ToolProvider.getSystemDocumentationTool)
|
//Option(javax.tools.ToolProvider.getSystemDocumentationTool)
|
||||||
if (LocalJava.hasLocalJavadoc) Some(new LocalJavadoc)
|
if (LocalJava.hasLocalJavadoc) Some(new LocalJavadoc)
|
||||||
else None
|
else None
|
||||||
|
|
||||||
/** Returns a local compiler that will fork javac when needed. */
|
/** Returns a local compiler that will fork javac when needed. */
|
||||||
def fork(javaHome: Option[File] = None): NewJavadoc =
|
def fork(javaHome: Option[File] = None): Javadoc =
|
||||||
new ForkedJavadoc(javaHome)
|
new ForkedJavadoc(javaHome)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ import xsbti.compile.{ MultipleOutput, SingleOutput, Output }
|
||||||
* wrapper around running Javac (forked or direct) into the interfaces used by incremental compiler.
|
* wrapper around running Javac (forked or direct) into the interfaces used by incremental compiler.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class JavaCompilerAdapter(delegate: NewJavaTool, scalaInstance: xsbti.compile.ScalaInstance, cpOptions: xsbti.compile.ClasspathOptions) extends xsbti.compile.JavaCompiler {
|
class JavaCompilerAdapter(delegate: JavaTool, scalaInstance: xsbti.compile.ScalaInstance, cpOptions: xsbti.compile.ClasspathOptions) extends xsbti.compile.JavaCompiler {
|
||||||
override final def compile(sources: Array[File], classpath: Array[File], output: Output, options: Array[String], log: xsbti.Logger): Unit = {
|
override final def compile(sources: Array[File], classpath: Array[File], output: Output, options: Array[String], log: xsbti.Logger): Unit = {
|
||||||
// TODO - 5 max errors ok? We're not expecting this code path to be called, ever. This is only for clients who try to use the xsbti.compile.JavaCompiler interface
|
// TODO - 5 max errors ok? We're not expecting this code path to be called, ever. This is only for clients who try to use the xsbti.compile.JavaCompiler interface
|
||||||
// outside of the incremental compiler, for some reason.
|
// outside of the incremental compiler, for some reason.
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ object LocalJava {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Implementation of javadoc tool which attempts to run it locally (in-class). */
|
/** Implementation of javadoc tool which attempts to run it locally (in-class). */
|
||||||
final class LocalJavadoc() extends NewJavadoc {
|
final class LocalJavadoc() extends Javadoc {
|
||||||
override def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean = {
|
override def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean = {
|
||||||
val cwd = new File(new File(".").getAbsolutePath).getCanonicalFile
|
val cwd = new File(new File(".").getAbsolutePath).getCanonicalFile
|
||||||
val (jArgs, nonJArgs) = options.partition(_.startsWith("-J"))
|
val (jArgs, nonJArgs) = options.partition(_.startsWith("-J"))
|
||||||
|
|
@ -57,7 +57,7 @@ final class LocalJavadoc() extends NewJavadoc {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An implementation of compiling java which delegates to the JVM resident java compiler. */
|
/** An implementation of compiling java which delegates to the JVM resident java compiler. */
|
||||||
final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends NewJavaCompiler {
|
final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends JavaCompiler {
|
||||||
override def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean = {
|
override def run(sources: Seq[File], options: Seq[String])(implicit log: Logger, reporter: Reporter): Boolean = {
|
||||||
import collection.JavaConverters._
|
import collection.JavaConverters._
|
||||||
val logger = new LoggerWriter(log)
|
val logger = new LoggerWriter(log)
|
||||||
|
|
|
||||||
|
|
@ -115,12 +115,12 @@ object JavaCompilerSpec extends Specification {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Create one with known JAVA HOME.
|
// TODO - Create one with known JAVA HOME.
|
||||||
def forked = JavaTools(NewJavaCompiler.fork(), NewJavadoc.fork())
|
def forked = JavaTools(JavaCompiler.fork(), Javadoc.fork())
|
||||||
|
|
||||||
def local =
|
def local =
|
||||||
JavaTools(
|
JavaTools(
|
||||||
NewJavaCompiler.local.getOrElse(sys.error("This test cannot be run on a JRE, but only a JDK.")),
|
JavaCompiler.local.getOrElse(sys.error("This test cannot be run on a JRE, but only a JDK.")),
|
||||||
NewJavadoc.local.getOrElse(NewJavadoc.fork())
|
Javadoc.local.getOrElse(Javadoc.fork())
|
||||||
)
|
)
|
||||||
|
|
||||||
def cwd =
|
def cwd =
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import sbt.compiler.javac.{ IncrementalCompilerJavaTools, NewJavaCompiler, JavaTools }
|
import sbt.compiler.javac.{ IncrementalCompilerJavaTools, JavaCompiler, JavaTools }
|
||||||
import xsbti.{ Logger => _, _ }
|
import xsbti.{ Logger => _, _ }
|
||||||
import xsbti.compile.{ CompileOrder, GlobalsCache }
|
import xsbti.compile.{ CompileOrder, GlobalsCache }
|
||||||
import CompileOrder.{ JavaThenScala, Mixed, ScalaThenJava }
|
import CompileOrder.{ JavaThenScala, Mixed, ScalaThenJava }
|
||||||
|
|
@ -60,11 +60,13 @@ object Compiler {
|
||||||
}
|
}
|
||||||
compilers(instance, cpOptions, CheaterJavaTool(javac2, javac))
|
compilers(instance, cpOptions, CheaterJavaTool(javac2, javac))
|
||||||
}
|
}
|
||||||
def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions, javac: JavaCompiler.Fork)(implicit app: AppConfiguration, log: Logger): Compilers =
|
@deprecated("0.13.8", "Deprecated in favor of new sbt.compiler.javac package.")
|
||||||
|
def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions, javac: sbt.compiler.JavaCompiler.Fork)(implicit app: AppConfiguration, log: Logger): Compilers =
|
||||||
{
|
{
|
||||||
val javaCompiler = JavaCompiler.fork(cpOptions, instance)(javac)
|
val javaCompiler = sbt.compiler.JavaCompiler.fork(cpOptions, instance)(javac)
|
||||||
compilers(instance, cpOptions, javaCompiler)
|
compilers(instance, cpOptions, javaCompiler)
|
||||||
}
|
}
|
||||||
|
@deprecated("0.13.8", "Deprecated in favor of new sbt.compiler.javac package.")
|
||||||
def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions, javac: JavaTool)(implicit app: AppConfiguration, log: Logger): Compilers =
|
def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions, javac: JavaTool)(implicit app: AppConfiguration, log: Logger): Compilers =
|
||||||
{
|
{
|
||||||
val scalac = scalaCompiler(instance, cpOptions)
|
val scalac = scalaCompiler(instance, cpOptions)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue