mirror of https://github.com/sbt/sbt.git
Depend more on ComponentManager to get sources
This commit is contained in:
parent
e9b2ac99d7
commit
5557de4fe4
|
|
@ -113,18 +113,30 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com
|
||||||
|
|
||||||
private def compileAndInstall(id: String, binID: String): Unit = {
|
private def compileAndInstall(id: String, binID: String): Unit = {
|
||||||
val srcID = id + srcExtension
|
val srcID = id + srcExtension
|
||||||
def interfaceSources(moduleVersions: Seq[String]): File =
|
def interfaceSources(moduleVersions: Seq[String]): Iterable[File] =
|
||||||
moduleVersions match {
|
moduleVersions match {
|
||||||
case Seq() =>
|
case Seq() =>
|
||||||
log.debug(s"Fetching default sources: $id")
|
|
||||||
val jarName = s"$srcID-$sbtVersion.jar"
|
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 =>
|
case version +: rest =>
|
||||||
val moduleName = s"${id}_$version"
|
val moduleName = s"${id}_$version"
|
||||||
val jarName = s"${srcID}_$version-$sbtVersion.jar"
|
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'")
|
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 =>
|
IO.withTemporaryDirectory { binaryDirectory =>
|
||||||
|
|
||||||
|
|
@ -132,7 +144,7 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com
|
||||||
val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail)
|
val xsbtiJars = manager.files(xsbtiID)(IfMissing.Fail)
|
||||||
|
|
||||||
val sourceModuleVersions = cascadingSourceModuleVersions(compiler.scalaInstance.actualVersion)
|
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))
|
manager.define(binID, Seq(targetJar))
|
||||||
|
|
||||||
|
|
@ -173,7 +185,7 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com
|
||||||
s"unknown"
|
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 retrieveDirectory = new File(ivyConfiguration.baseDirectory, "component")
|
||||||
val retrieveConfiguration = new RetrieveConfiguration(retrieveDirectory, Resolver.defaultRetrievePattern, false)
|
val retrieveConfiguration = new RetrieveConfiguration(retrieveDirectory, Resolver.defaultRetrievePattern, false)
|
||||||
|
|
@ -192,7 +204,8 @@ private[compiler] class NewComponentCompiler(compiler: RawCompiler, manager: Com
|
||||||
(_, f) <- m.artifacts
|
(_, f) <- m.artifacts
|
||||||
if predicate(f)
|
if predicate(f)
|
||||||
} yield f
|
} yield f
|
||||||
files.headOption
|
if (files.isEmpty) None
|
||||||
|
else Some(files)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ class ComponentManager(globalLock: xsbti.GlobalLock, provider: xsbti.ComponentPr
|
||||||
d()
|
d()
|
||||||
if (d.cache) cache(id)
|
if (d.cache) cache(id)
|
||||||
getOrElse(notFound)
|
getOrElse(notFound)
|
||||||
|
case f: IfMissing.Fallback =>
|
||||||
|
f()
|
||||||
}
|
}
|
||||||
|
|
||||||
lockLocalCache { getOrElse(fromGlobal) }
|
lockLocalCache { getOrElse(fromGlobal) }
|
||||||
|
|
@ -73,6 +75,7 @@ sealed trait IfMissing extends NotNull
|
||||||
object IfMissing {
|
object IfMissing {
|
||||||
object Fail extends IfMissing
|
object Fail extends IfMissing
|
||||||
final class Define(val cache: Boolean, define: => Unit) extends IfMissing { def apply() = define }
|
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 {
|
object ComponentManager {
|
||||||
lazy val (version, timestamp) =
|
lazy val (version, timestamp) =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue