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 = {
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue