From ce915b23ba762dad04aeb6868802f179f6124419 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Fri, 11 Sep 2015 13:53:51 +0200 Subject: [PATCH] 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. --- .../sbt/compiler/ComponentCompiler.scala | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/compile-ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala b/internal/compile-ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala index ec36c4416..e6ed305c9 100644 --- a/internal/compile-ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala +++ b/internal/compile-ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala @@ -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