Merge pull request #162 from pvlugter/cached-resolution-plugin-cross-build

Include sbt plugin extra attributes in cached resolution
This commit is contained in:
eugene yokota 2017-08-26 14:26:19 -04:00 committed by GitHub
commit 0ae5f5df9e
3 changed files with 46 additions and 6 deletions

View File

@ -70,7 +70,7 @@ abstract class ModuleReportExtra {
reportStr("problem", problem) +
reportStr("homepage", homepage) +
reportStr(
"textraAttributes",
"extraAttributes",
if (extraAttributes.isEmpty) None
else { Some(extraAttributes.toString) }
) +

View File

@ -180,17 +180,25 @@ private[sbt] class CachedResolutionResolveCache {
): Either[ResolveException, UpdateReport] = {
import sbt.io.syntax._
val mrid = md.getResolvedModuleRevisionId
val (pathOrg, pathName, pathRevision) = md match {
def extraPath(id: ModuleRevisionId, key: String, pattern: String): String =
Option(id.getExtraAttribute(key)).fold(".")(pattern.format(_)) // "." has no affect on paths
def scalaVersion(id: ModuleRevisionId): String = extraPath(id, "e:scalaVersion", "scala_%s")
def sbtVersion(id: ModuleRevisionId): String = extraPath(id, "e:sbtVersion", "sbt_%s")
val (pathOrg, pathName, pathRevision, pathScalaVersion, pathSbtVersion) = md match {
case x: ArtificialModuleDescriptor =>
val tmrid = x.targetModuleRevisionId
(tmrid.getOrganisation, tmrid.getName, tmrid.getRevision + "_" + mrid.getName)
(tmrid.getOrganisation,
tmrid.getName,
tmrid.getRevision + "_" + mrid.getName,
scalaVersion(tmrid),
sbtVersion(tmrid))
case _ =>
(mrid.getOrganisation, mrid.getName, mrid.getRevision)
(mrid.getOrganisation, mrid.getName, mrid.getRevision, scalaVersion(mrid), sbtVersion(mrid))
}
val staticGraphDirectory = miniGraphPath / "static"
val dynamicGraphDirectory = miniGraphPath / "dynamic"
val staticGraphPath = staticGraphDirectory / pathOrg / pathName / pathRevision / "graphs" / "graph.json"
val dynamicGraphPath = dynamicGraphDirectory / todayStr / logicalClock.toString / pathOrg / pathName / pathRevision / "graphs" / "graph.json"
val staticGraphPath = staticGraphDirectory / pathScalaVersion / pathSbtVersion / pathOrg / pathName / pathRevision / "graphs" / "graph.json"
val dynamicGraphPath = dynamicGraphDirectory / todayStr / logicalClock.toString / pathScalaVersion / pathSbtVersion / pathOrg / pathName / pathRevision / "graphs" / "graph.json"
def cleanDynamicGraph(): Unit = {
val list = IO.listFiles(dynamicGraphDirectory, DirectoryFilter).toList
list filterNot { d =>

View File

@ -1,5 +1,6 @@
package sbt.internal.librarymanagement
import org.scalatest.LoneElement._
import sbt.util.ShowLines
import sbt.librarymanagement._
import sbt.librarymanagement.ivy.UpdateOptions
@ -7,6 +8,11 @@ import sbt.librarymanagement.ivy.UpdateOptions
class CachedResolutionSpec extends BaseIvySpecification {
import ShowLines._
override val resolvers = Vector(
Resolver.mavenCentral,
Resolver.sbtPluginRepo("releases")
)
"Resolving the same module twice" should "work" in {
cleanIvyCache()
val m = module(
@ -76,6 +82,30 @@ class CachedResolutionSpec extends BaseIvySpecification {
}))
}
"Resolving a module with sbt cross build" should "work" in {
cleanIvyCache()
val attributes013 = Map("e:sbtVersion" -> "0.13", "e:scalaVersion" -> "2.10")
val attributes10 = Map("e:sbtVersion" -> "1.0", "e:scalaVersion" -> "2.12")
val module013 = module(
ModuleID("com.example", "foo", "0.4.0").withConfigurations(Some("compile")),
Vector(sbtRelease.withExtraAttributes(attributes013)),
Some("2.10.6"),
UpdateOptions().withCachedResolution(true)
)
val module10 = module(
ModuleID("com.example", "foo", "0.4.0").withConfigurations(Some("compile")),
Vector(sbtRelease.withExtraAttributes(attributes10)),
Some("2.12.3"),
UpdateOptions().withCachedResolution(true)
)
ivyUpdate(module013).configurations.head.modules.map(_.toString).loneElement should include(
"com.github.gseitz:sbt-release:1.0.6 (scalaVersion=2.10, sbtVersion=0.13)"
)
ivyUpdate(module10).configurations.head.modules.map(_.toString).loneElement should include(
"com.github.gseitz:sbt-release:1.0.6 (scalaVersion=2.12, sbtVersion=1.0)"
)
}
def commonsIo13 = ModuleID("commons-io", "commons-io", "1.3").withConfigurations(Some("compile"))
def mavenCayennePlugin302 =
ModuleID("org.apache.cayenne.plugins", "maven-cayenne-plugin", "3.0.2").withConfigurations(
@ -85,6 +115,8 @@ class CachedResolutionSpec extends BaseIvySpecification {
ModuleID("com.linkedin.pegasus", "data-avro", "1.9.40").withConfigurations(Some("compile"))
def netty320 =
ModuleID("org.jboss.netty", "netty", "3.2.0.Final").withConfigurations(Some("compile"))
def sbtRelease =
ModuleID("com.github.gseitz", "sbt-release", "1.0.6").withConfigurations(Some("compile"))
def defaultOptions = EvictionWarningOptions.default
}