More fixes from review.

* Fix regex for end of line.
* Rename NewJavaTool and friends to remove the New.
This commit is contained in:
Josh Suereth 2014-10-30 19:37:22 -04:00
parent 8d158e5ab6
commit 75402b26f2
8 changed files with 31 additions and 27 deletions

View File

@ -200,13 +200,14 @@ object AggressiveCompile {
b
}
}
@deprecated("0.13.8", "Deprecated in favor of new sbt.compiler.javac package.")
def directOrFork(instance: ScalaInstance, cpOptions: ClasspathOptions, javaHome: Option[File]): JavaTool =
if (javaHome.isDefined)
JavaCompiler.fork(cpOptions, instance)(forkJavac(javaHome))
else
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 =
{
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 {
import scala.collection.mutable.ListBuffer
import Level.{ Info, Warn, Error, Value => LogLevel }

View File

@ -11,7 +11,7 @@ import xsbti.{ Severity, Reporter }
* @param reporter
*/
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")
private def fixedDiagnosticMessage(d: Diagnostic[_ <: JavaFileObject]): String = {
def getRawMessage = d.getMessage(null)

View File

@ -63,11 +63,11 @@ object ForkedJava {
}
/** 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 =
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 =
ForkedJava.launch(javaHome, "javadoc", sources, options, log, reporter)
}

View File

@ -17,7 +17,7 @@ import xsbti.{ Severity, Reporter }
*/
sealed trait JavaTools {
/** The raw interface of the java compiler for direct access. */
def compiler: NewJavaTool
def compiler: JavaTool
/**
* This will run a java compiler.
*
@ -53,7 +53,7 @@ sealed trait IncrementalCompilerJavaTools extends JavaTools {
/** Factory methods for getting a java toolchain. */
object JavaTools {
/** Create a new aggregate tool from existing tools. */
def apply(c: NewJavaCompiler, docgen: NewJavadoc): JavaTools =
def apply(c: JavaCompiler, docgen: Javadoc): JavaTools =
new JavaTools {
override def compiler = c
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 = {
val (compiler, doc) = javaHome match {
case Some(_) => (NewJavaCompiler.fork(javaHome), NewJavadoc.fork(javaHome))
case Some(_) => (JavaCompiler.fork(javaHome), Javadoc.fork(javaHome))
case _ =>
val c = NewJavaCompiler.local.getOrElse(NewJavaCompiler.fork(None))
val d = NewJavadoc.local.getOrElse(NewJavadoc.fork())
val c = JavaCompiler.local.getOrElse(JavaCompiler.fork(None))
val d = Javadoc.local.getOrElse(Javadoc.fork())
(c, d)
}
val delegate = apply(compiler, doc)
@ -102,7 +102,7 @@ object JavaTools {
* - The all take sources and options and log error messages
* - They return success or failure.
*/
sealed trait NewJavaTool {
sealed trait JavaTool {
/**
* 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. */
trait NewJavaCompiler extends NewJavaTool {}
trait JavaCompiler extends JavaTool {}
/** Factory methods for constructing a java compiler. */
object NewJavaCompiler {
object JavaCompiler {
/** Returns a local compiler, if the current runtime supports it. */
def local: Option[NewJavaCompiler] =
def local: Option[JavaCompiler] =
for {
compiler <- Option(javax.tools.ToolProvider.getSystemJavaCompiler)
} yield new LocalJavaCompiler(compiler)
/** 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)
}
/** 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. */
object NewJavadoc {
object Javadoc {
/** 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
//Option(javax.tools.ToolProvider.getSystemDocumentationTool)
if (LocalJava.hasLocalJavadoc) Some(new LocalJavadoc)
else None
/** 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)
}

View File

@ -14,7 +14,7 @@ import xsbti.compile.{ MultipleOutput, SingleOutput, Output }
* 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 = {
// 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.

View File

@ -35,7 +35,7 @@ object LocalJava {
}
}
/** 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 = {
val cwd = new File(new File(".").getAbsolutePath).getCanonicalFile
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. */
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 = {
import collection.JavaConverters._
val logger = new LoggerWriter(log)

View File

@ -115,12 +115,12 @@ object NewJavaCompilerSpec extends Specification {
}
// TODO - Create one with known JAVA HOME.
def forked = JavaTools(NewJavaCompiler.fork(), NewJavadoc.fork())
def forked = JavaTools(JavaCompiler.fork(), Javadoc.fork())
def local =
JavaTools(
NewJavaCompiler.local.getOrElse(sys.error("This test cannot be run on a JRE, but only a JDK.")),
NewJavadoc.local.getOrElse(NewJavadoc.fork())
JavaCompiler.local.getOrElse(sys.error("This test cannot be run on a JRE, but only a JDK.")),
Javadoc.local.getOrElse(Javadoc.fork())
)
def cwd =

View File

@ -3,7 +3,7 @@
*/
package sbt
import sbt.compiler.javac.{ IncrementalCompilerJavaTools, NewJavaCompiler, JavaTools }
import sbt.compiler.javac.{ IncrementalCompilerJavaTools, JavaCompiler, JavaTools }
import xsbti.{ Logger => _, _ }
import xsbti.compile.{ CompileOrder, GlobalsCache }
import CompileOrder.{ JavaThenScala, Mixed, ScalaThenJava }
@ -60,11 +60,13 @@ object Compiler {
}
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)
}
@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 =
{
val scalac = scalaCompiler(instance, cpOptions)