diff --git a/compile/ivy/ComponentCompiler.scala b/compile/ivy/ComponentCompiler.scala index e4431c127..f4732aabf 100644 --- a/compile/ivy/ComponentCompiler.scala +++ b/compile/ivy/ComponentCompiler.scala @@ -17,7 +17,7 @@ object ComponentCompiler def interfaceProvider(manager: ComponentManager): CompilerInterfaceProvider = new CompilerInterfaceProvider { - def apply(scalaInstance: ScalaInstance, log: Logger): File = + def apply(scalaInstance: xsbti.compile.ScalaInstance, log: Logger): File = { // this is the instance used to compile the interface component val componentCompiler = new ComponentCompiler(new RawCompiler(scalaInstance, ClasspathOptions.auto, log), manager) @@ -32,7 +32,6 @@ object ComponentCompiler class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager) { import ComponentCompiler._ - import sbt.IO.{copy, createDirectory, zip, jars, unzip, withTemporaryDirectory} def apply(id: String): File = try { getPrecompiled(id) } catch { case _: InvalidComponent => getLocallyCompiled(id) } @@ -56,37 +55,11 @@ class ComponentCompiler(compiler: RawCompiler, manager: ComponentManager) protected def compileAndInstall(id: String, binID: String) { val srcID = id + srcExtension - withTemporaryDirectory { binaryDirectory => + IO.withTemporaryDirectory { binaryDirectory => val targetJar = new File(binaryDirectory, id + ".jar") - compileSources(manager.files(srcID)(IfMissing.Fail), targetJar, id) + 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)) } } - /** Extract sources from source jars, compile them with the xsbti interfaces on the classpath, and package the compiled classes and - * any resources from the source jars into a final jar.*/ - private def compileSources(sourceJars: Iterable[File], targetJar: File, id: String) - { - val isSource = (f: File) => isSourceName(f.getName) - def keepIfSource(files: Set[File]): Set[File] = if(files.exists(isSource)) files else Set() - - withTemporaryDirectory { dir => - val extractedSources = (Set[File]() /: sourceJars) { (extracted, sourceJar)=> extracted ++ keepIfSource(unzip(sourceJar, dir)) } - val (sourceFiles, resources) = extractedSources.partition(isSource) - withTemporaryDirectory { outputDirectory => - val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail) - manager.log.info("'" + id + "' not yet compiled for Scala " + compiler.scalaInstance.actualVersion + ". Compiling...") - val start = System.currentTimeMillis - try - { - compiler(sourceFiles.toSeq, xsbtiJars.toSeq ++ sourceJars, outputDirectory, "-nowarn" :: Nil) - manager.log.info(" Compilation completed in " + (System.currentTimeMillis - start) / 1000.0 + " s") - } - catch { case e: xsbti.CompileFailed => throw new CompileFailed(e.arguments, "Error compiling sbt component '" + id + "'") } - import sbt.Path._ - copy(resources x rebase(dir, outputDirectory)) - zip((outputDirectory ***) x_! relativeTo(outputDirectory), targetJar) - } - } - } - private def isSourceName(name: String): Boolean = name.endsWith(".scala") || name.endsWith(".java") } \ No newline at end of file