Retrieve java compiler interfaces using Ivy

Previously the component compiler depended on a `componentID` added to
some interfaces to be able to compile the compiler interface. sbt's
launcher placed artifacts marked with this `componentID` in a special
directory that was then used by the ComponentCompiler to be able to
compile the compiler interface.

This commit modifies the ComponentCompiler so that it does not expect
these components to be already present in some directory, but instead
downloads it using Ivy when required.
This commit is contained in:
Martin Duhem 2015-09-11 13:53:51 +02:00
parent 0cc451b8b2
commit ce915b23ba
1 changed files with 20 additions and 1 deletions

View File

@ -101,6 +101,8 @@ private[compiler] class IvyComponentCompiler(compiler: RawCompiler, manager: Com
import ComponentCompiler._
private val incrementalCompilerOrg = xsbti.ArtifactInfo.SbtOrganization + ".incrementalcompiler"
private val xsbtiInterfaceModuleName = "interface"
private val xsbtiInterfaceID = s"interface-$incrementalVersion"
private val sbtOrgTemp = JsonUtil.sbtOrgTemp
private val modulePrefixTemp = "temp-module-"
private val ivySbt: IvySbt = new IvySbt(ivyConfiguration)
@ -121,7 +123,7 @@ private[compiler] class IvyComponentCompiler(compiler: RawCompiler, manager: Com
IO.withTemporaryDirectory { binaryDirectory =>
val targetJar = new File(binaryDirectory, s"$binID.jar")
val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail)
val xsbtiJars = manager.files(xsbtiInterfaceID)(new IfMissing.Define(true, getXsbtiInterface()))
buffered bufferQuietly {
@ -139,6 +141,23 @@ private[compiler] class IvyComponentCompiler(compiler: RawCompiler, manager: Com
}
}
private def getXsbtiInterface(): Unit =
buffered bufferQuietly {
IO withTemporaryDirectory { retrieveDirectory =>
val module = ModuleID(incrementalCompilerOrg, xsbtiInterfaceModuleName, incrementalVersion, Some("component"))
val jarName = s"$xsbtiInterfaceModuleName-$incrementalVersion.jar"
(update(getModule(module), retrieveDirectory)(_.getName == jarName)) match {
case Some(interface) =>
manager.define(xsbtiInterfaceID, interface)
case None =>
throw new InvalidComponent(s"Couldn't retrieve xsbti interface module: $xsbtiInterfaceModuleName")
}
}
}
/**
* Returns a dummy module that depends on `moduleID`.
* Note: Sbt's implementation of Ivy requires us to do this, because only the dependencies