mirror of https://github.com/sbt/sbt.git
rework again configurations management
This commit is contained in:
parent
eeddaa3f5d
commit
1951da25bb
|
|
@ -0,0 +1,18 @@
|
|||
package coursier
|
||||
|
||||
import java.io.File
|
||||
|
||||
object SbtBootJars {
|
||||
def apply(
|
||||
scalaOrg: String,
|
||||
scalaVersion: String,
|
||||
jars: Seq[File]
|
||||
): Map[(Module, String), File] =
|
||||
jars.collect {
|
||||
case jar if jar.getName.endsWith(".jar") =>
|
||||
val name = jar.getName.stripSuffix(".jar")
|
||||
val mod = Module(scalaOrg, name)
|
||||
|
||||
(mod, scalaVersion) -> jar
|
||||
}.toMap
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ private[sbt] class CoursierDependencyResolution(coursierConfiguration: CoursierC
|
|||
}
|
||||
|
||||
val dependencies = module.directDependencies.map(toCoursierDependency).flatten.toSet
|
||||
val start = Resolution(dependencies)
|
||||
val start = Resolution(dependencies.map(_._1))
|
||||
val authentication = None // TODO: get correct value
|
||||
val ivyConfiguration = ivyProperties // TODO: is it enough?
|
||||
|
||||
|
|
@ -191,7 +191,10 @@ private[sbt] class CoursierDependencyResolution(coursierConfiguration: CoursierC
|
|||
.unsafeRun()
|
||||
.toMap
|
||||
|
||||
toUpdateReport(resolution, module0.configurations, localArtifacts, log)
|
||||
toUpdateReport(resolution,
|
||||
(module0.configurations ++ dependencies.map(_._2)).distinct,
|
||||
localArtifacts,
|
||||
log)
|
||||
}
|
||||
|
||||
if (resolution.isDone &&
|
||||
|
|
@ -221,7 +224,7 @@ private[sbt] class CoursierDependencyResolution(coursierConfiguration: CoursierC
|
|||
t
|
||||
}
|
||||
|
||||
private def toCoursierDependency(moduleID: ModuleID): Seq[Dependency] = {
|
||||
private def toCoursierDependency(moduleID: ModuleID) = {
|
||||
val attributes =
|
||||
if (moduleID.explicitArtifacts.isEmpty)
|
||||
Seq(Attributes("", ""))
|
||||
|
|
@ -234,21 +237,23 @@ private[sbt] class CoursierDependencyResolution(coursierConfiguration: CoursierC
|
|||
|
||||
val mapping = moduleID.configurations.getOrElse("compile")
|
||||
|
||||
// import _root_.coursier.ivy.IvyXml.{ mappings => ivyXmlMappings }
|
||||
// val allMappings = ivyXmlMappings(mapping)
|
||||
import _root_.coursier.ivy.IvyXml.{ mappings => ivyXmlMappings }
|
||||
val allMappings = ivyXmlMappings(mapping)
|
||||
|
||||
for {
|
||||
(from, to) <- allMappings
|
||||
attr <- attributes
|
||||
} yield {
|
||||
Dependency(
|
||||
Module(moduleID.organization, moduleID.name, extraAttrs),
|
||||
moduleID.revision,
|
||||
configuration = mapping,
|
||||
configuration = to,
|
||||
attributes = attr,
|
||||
exclusions = moduleID.exclusions.map { rule =>
|
||||
(rule.organization, rule.name)
|
||||
}.toSet,
|
||||
transitive = moduleID.isTransitive
|
||||
)
|
||||
) -> from
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,16 +279,17 @@ private[sbt] class CoursierDependencyResolution(coursierConfiguration: CoursierC
|
|||
|
||||
val depsByConfig = {
|
||||
val deps = resolution.dependencies.toVector
|
||||
(configurations ++
|
||||
Seq(ScalaTool, CompilerPlugin, Component).map(_.name)).map((_, deps)).toMap
|
||||
configurations
|
||||
.map((_, deps))
|
||||
.toMap
|
||||
}
|
||||
|
||||
val configurations0 = extractConfigurationTree
|
||||
val configurations0 = extractConfigurationTree(configurations)
|
||||
|
||||
val configResolutions =
|
||||
(depsByConfig.keys ++ configurations0.keys).map(k => (k, resolution)).toMap
|
||||
|
||||
val sbtBootJarOverrides = Map.empty[(Module, String), File] // TODO: get correct values
|
||||
val sbtBootJarOverrides = Map.empty[(Module, String), File]
|
||||
val classifiers = None // TODO: get correct values
|
||||
|
||||
if (artifactErrors.isEmpty) {
|
||||
|
|
@ -315,10 +321,11 @@ private[sbt] class CoursierDependencyResolution(coursierConfiguration: CoursierC
|
|||
|
||||
// Key is the name of the configuration (i.e. `compile`) and the values are the name itself plus the
|
||||
// names of the configurations that this one depends on.
|
||||
private val extractConfigurationTree: ConfigurationDependencyTree = {
|
||||
private def extractConfigurationTree(available: Seq[String]): ConfigurationDependencyTree = {
|
||||
(Configurations.default ++
|
||||
Configurations.defaultInternal ++
|
||||
Seq(ScalaTool, CompilerPlugin, Component))
|
||||
.filter(c => available.contains(c.name))
|
||||
.map(c => (c.name, c.extendsConfigs.map(_.name) :+ c.name))
|
||||
.toMap
|
||||
.mapValues(_.toSet)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class ResolutionSpec extends BaseCoursierSpecification {
|
|||
|
||||
resolution should be('right)
|
||||
val r = resolution.right.get
|
||||
r.configurations.map(_.configuration) should have size 11
|
||||
r.configurations.map(_.configuration) should have size 3
|
||||
|
||||
val compileConfig = r.configurations.find(_.configuration == Compile.toConfigRef).get
|
||||
compileConfig.modules should have size 2
|
||||
|
|
@ -55,24 +55,23 @@ class ResolutionSpec extends BaseCoursierSpecification {
|
|||
val r = resolution.right.get
|
||||
|
||||
val componentConfig = r.configurations.find(_.configuration == Component.toConfigRef).get
|
||||
componentConfig.modules should have size 1
|
||||
componentConfig.modules should have size 2
|
||||
componentConfig.modules.head.artifacts should have size 1
|
||||
componentConfig.modules.head.artifacts.head._1.classifier should contain("sources")
|
||||
}
|
||||
|
||||
// TODO: fix this test
|
||||
// it should "resolve sbt jars" in {
|
||||
// val dependencies =
|
||||
// Vector(("org.scala-sbt" % "sbt" % "1.1.0" % "provided"))
|
||||
// val coursierModule = module(stubModule, dependencies, Some("2.12.4"))
|
||||
// val resolution =
|
||||
// lmEngine.update(coursierModule, UpdateConfiguration(), UnresolvedWarningConfiguration(), log)
|
||||
it should "resolve sbt jars" in {
|
||||
val dependencies =
|
||||
Vector(("org.scala-sbt" % "sbt" % "1.1.0" % "provided"))
|
||||
val coursierModule = module(stubModule, dependencies, Some("2.12.4"))
|
||||
val resolution =
|
||||
lmEngine.update(coursierModule, UpdateConfiguration(), UnresolvedWarningConfiguration(), log)
|
||||
|
||||
// val r = resolution.right.get
|
||||
val r = resolution.right.get
|
||||
|
||||
// val modules = r.configurations.flatMap(_.modules)
|
||||
// modules.map(_.module.name) should contain("main_2.12")
|
||||
// }
|
||||
val modules = r.configurations.flatMap(_.modules)
|
||||
modules.map(_.module.name) should contain("main_2.12")
|
||||
}
|
||||
|
||||
it should "resolve with default resolvers" in {
|
||||
val dependencies =
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
{
|
||||
def writePluginsSbt(str: String) = {
|
||||
val pluginsSbt = file(".") / "project" / "plugins.sbt"
|
||||
if (!pluginsSbt.exists)
|
||||
IO.write(
|
||||
pluginsSbt,
|
||||
str
|
||||
)
|
||||
}
|
||||
val dr = sys.props.get("dependency.resolution") match {
|
||||
case Some("ivy") =>
|
||||
"""dependencyResolution := sbt.librarymanagement.ivy.IvyDependencyResolution(ivyConfiguration.value)"""
|
||||
case Some("coursier") =>
|
||||
"""dependencyResolution := sbt.librarymanagement.coursier.CoursierDependencyResolution(sbt.librarymanagement.coursier.CoursierConfiguration())"""
|
||||
case _ => sys.error("""|The system property 'dependency.resolution' is not defined.
|
||||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
|
||||
}
|
||||
|
||||
writePluginsSbt(dr)
|
||||
addCommandAlias(
|
||||
"setDependencyResolution",
|
||||
s"""set $dr"""
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import sbt._
|
||||
import Keys._
|
||||
|
||||
object Dependencies {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
> reload
|
||||
Loading…
Reference in New Issue