added scalariform

This commit is contained in:
Eugene Yokota 2014-05-01 12:50:07 -04:00
parent 62fcc2a9b3
commit 2b526e6aa7
1 changed files with 55 additions and 53 deletions

View File

@ -6,60 +6,62 @@ package compiler
import java.io.File import java.io.File
object ComponentCompiler object ComponentCompiler {
{ val xsbtiID = "xsbti"
val xsbtiID = "xsbti" val srcExtension = "-src"
val srcExtension = "-src" val binSeparator = "-bin_"
val binSeparator = "-bin_" val compilerInterfaceID = "compiler-interface"
val compilerInterfaceID = "compiler-interface" val compilerInterfaceSrcID = compilerInterfaceID + srcExtension
val compilerInterfaceSrcID = compilerInterfaceID + srcExtension val javaVersion = System.getProperty("java.class.version")
val javaVersion = System.getProperty("java.class.version")
def interfaceProvider(manager: ComponentManager): CompilerInterfaceProvider = new CompilerInterfaceProvider def interfaceProvider(manager: ComponentManager): CompilerInterfaceProvider = new CompilerInterfaceProvider {
{ def apply(scalaInstance: xsbti.compile.ScalaInstance, log: Logger): File =
def apply(scalaInstance: xsbti.compile.ScalaInstance, log: Logger): File = {
{ // this is the instance used to compile the interface component
// this is the instance used to compile the interface component val componentCompiler = new ComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager)
val componentCompiler = new ComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager) log.debug("Getting " + compilerInterfaceID + " from component compiler for Scala " + scalaInstance.version)
log.debug("Getting " + compilerInterfaceID + " from component compiler for Scala " + scalaInstance.version) componentCompiler(compilerInterfaceID)
componentCompiler(compilerInterfaceID) }
} }
}
} }
/** This class provides source components compiled with the provided RawCompiler. /**
* The compiled classes are cached using the provided component manager according * This class provides source components compiled with the provided RawCompiler.
* to the actualVersion field of the RawCompiler.*/ * The compiled classes are cached using the provided component manager according
class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager) * to the actualVersion field of the RawCompiler.
{ */
import ComponentCompiler._ class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager) {
def apply(id: String): File = import ComponentCompiler._
try { getPrecompiled(id) } def apply(id: String): File =
catch { case _: InvalidComponent => getLocallyCompiled(id) } try { getPrecompiled(id) }
catch { case _: InvalidComponent => getLocallyCompiled(id) }
/** Gets the precompiled (distributed with sbt) component with the given 'id' /**
* If the component has not been precompiled, this throws InvalidComponent. */ * Gets the precompiled (distributed with sbt) component with the given 'id'
def getPrecompiled(id: String): File = manager.file( binaryID(id, false) )(IfMissing.Fail) * If the component has not been precompiled, this throws InvalidComponent.
/** Get the locally compiled component with the given 'id' or compiles it if it has not been compiled yet. */
* If the component does not exist, this throws InvalidComponent. */ def getPrecompiled(id: String): File = manager.file(binaryID(id, false))(IfMissing.Fail)
def getLocallyCompiled(id: String): File = /**
{ * Get the locally compiled component with the given 'id' or compiles it if it has not been compiled yet.
val binID = binaryID(id, true) * If the component does not exist, this throws InvalidComponent.
manager.file(binID)( new IfMissing.Define(true, compileAndInstall(id, binID)) ) */
} def getLocallyCompiled(id: String): File =
def clearCache(id: String): Unit = manager.clearCache(binaryID(id, true)) {
protected def binaryID(id: String, withJavaVersion: Boolean) = val binID = binaryID(id, true)
{ manager.file(binID)(new IfMissing.Define(true, compileAndInstall(id, binID)))
val base = id + binSeparator + compiler.scalaInstance.actualVersion }
if(withJavaVersion) base + "__" + javaVersion else base def clearCache(id: String): Unit = manager.clearCache(binaryID(id, true))
} protected def binaryID(id: String, withJavaVersion: Boolean) =
protected def compileAndInstall(id: String, binID: String) {
{ val base = id + binSeparator + compiler.scalaInstance.actualVersion
val srcID = id + srcExtension if (withJavaVersion) base + "__" + javaVersion else base
IO.withTemporaryDirectory { binaryDirectory => }
val targetJar = new File(binaryDirectory, id + ".jar") protected def compileAndInstall(id: String, binID: String) {
val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail) val srcID = id + srcExtension
AnalyzingCompiler.compileSources(manager.files(srcID)(IfMissing.Fail), targetJar, xsbtiJars, id, compiler, manager.log) IO.withTemporaryDirectory { binaryDirectory =>
manager.define(binID, Seq(targetJar)) val targetJar = new File(binaryDirectory, id + ".jar")
} val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail)
} AnalyzingCompiler.compileSources(manager.files(srcID)(IfMissing.Fail), targetJar, xsbtiJars, id, compiler, manager.log)
manager.define(binID, Seq(targetJar))
}
}
} }