From 5557de4fe4e06fdca255db06d5e24261a24c564e Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Mon, 13 Jul 2015 15:51:07 +0200 Subject: [PATCH] Depend more on ComponentManager to get sources --- .../sbt/compiler/ComponentCompiler.scala | 27 ++++++++++++++----- ivy/src/main/scala/sbt/ComponentManager.scala | 5 +++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala b/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala index 89282885d..630f7c268 100644 --- a/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala +++ b/compile/ivy/src/main/scala/sbt/compiler/ComponentCompiler.scala @@ -113,18 +113,30 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com private def compileAndInstall(id: String, binID: String): Unit = { val srcID = id + srcExtension - def interfaceSources(moduleVersions: Seq[String]): File = + def interfaceSources(moduleVersions: Seq[String]): Iterable[File] = moduleVersions match { case Seq() => - log.debug(s"Fetching default sources: $id") val jarName = s"$srcID-$sbtVersion.jar" - update(getModule(id))(_.getName == jarName) getOrElse (throw new InvalidComponent(s"Couldn't retrieve default sources: file '$jarName' in module '$id'")) + def getAndDefineDefaultSources() = + update(getModule(id))(_.getName == jarName) map { sourcesJar => + manager.define(id, sourcesJar) + sourcesJar + } getOrElse (throw new InvalidComponent(s"Couldn't retrieve default sources: file '$jarName' in module '$id'")) + + log.debug(s"Fetching default sources: file '$jarName' in module '$id'") + manager.files(id)(new IfMissing.Fallback(getAndDefineDefaultSources())) case version +: rest => val moduleName = s"${id}_$version" val jarName = s"${srcID}_$version-$sbtVersion.jar" + def getAndDefineVersionSpecificSources() = + update(getModule(moduleName))(_.getName == jarName) map { sourcesJar => + manager.define(moduleName, sourcesJar) + sourcesJar + } getOrElse interfaceSources(rest) + log.debug(s"Fetching version-specific sources: file '$jarName' in module '$moduleName'") - update(getModule(moduleName))(_.getName == jarName) getOrElse interfaceSources(rest) + manager.files(moduleName)(new IfMissing.Fallback(getAndDefineVersionSpecificSources())) } IO.withTemporaryDirectory { binaryDirectory => @@ -132,7 +144,7 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail) val sourceModuleVersions = cascadingSourceModuleVersions(compiler.scalaInstance.actualVersion) - AnalyzingCompiler.compileSources(Seq(interfaceSources(sourceModuleVersions)), targetJar, xsbtiJars, id, compiler, log) + AnalyzingCompiler.compileSources(interfaceSources(sourceModuleVersions), targetJar, xsbtiJars, id, compiler, log) manager.define(binID, Seq(targetJar)) @@ -173,7 +185,7 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com s"unknown" } - private def update(module: ivySbt.Module)(predicate: File => Boolean): Option[File] = { + private def update(module: ivySbt.Module)(predicate: File => Boolean): Option[Seq[File]] = { val retrieveDirectory = new File(ivyConfiguration.baseDirectory, "component") val retrieveConfiguration = new RetrieveConfiguration(retrieveDirectory, Resolver.defaultRetrievePattern, false) @@ -192,7 +204,8 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com (_, f) <- m.artifacts if predicate(f) } yield f - files.headOption + if (files.isEmpty) None + else Some(files) } } diff --git a/ivy/src/main/scala/sbt/ComponentManager.scala b/ivy/src/main/scala/sbt/ComponentManager.scala index 2d6c5a447..bdf78b9ec 100644 --- a/ivy/src/main/scala/sbt/ComponentManager.scala +++ b/ivy/src/main/scala/sbt/ComponentManager.scala @@ -39,6 +39,8 @@ class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentPr d() if (d.cache) cache(id) getOrElse(notFound) + case f: IfMissing.Fallback => + f() } lockLocalCache { getOrElse(fromGlobal) } @@ -73,6 +75,7 @@ sealed trait IfMissing extends NotNull object IfMissing { object Fail extends IfMissing final class Define(val cache: Boolean, define: => Unit) extends IfMissing { def apply() = define } + final class Fallback(f: => Iterable[File]) extends IfMissing { def apply() = f } } object ComponentManager { lazy val (version, timestamp) = @@ -86,4 +89,4 @@ object ComponentManager { import java.net.URL private def versionResource: URL = getClass.getResource("/xsbt.version.properties") -} \ No newline at end of file +}