mirror of https://github.com/sbt/sbt.git
Merge pull request #2501 from dansanduleac/feature/branches
Add Ivy `branch` support to ModuleID [1.0.x] + fix CacheIvy
This commit is contained in:
commit
2474f81f67
|
|
@ -115,9 +115,9 @@ object CacheIvy {
|
|||
private[this] val crossToInt = (c: CrossVersion) => c match { case Disabled => 0; case b: Binary => BinaryValue; case f: Full => FullValue }
|
||||
|
||||
implicit def moduleIDFormat(implicit sf: Format[String], bf: Format[Boolean]): Format[ModuleID] =
|
||||
wrap[ModuleID, ((String, String, String, Option[String]), (Boolean, Boolean, Boolean, Seq[Artifact], Seq[ExclusionRule], Seq[InclusionRule], Map[String, String], CrossVersion))](
|
||||
m => ((m.organization, m.name, m.revision, m.configurations), (m.isChanging, m.isTransitive, m.isForce, m.explicitArtifacts, m.exclusions, m.inclusions, m.extraAttributes, m.crossVersion)),
|
||||
{ case ((o, n, r, cs), (ch, t, f, as, excl, incl, x, cv)) => ModuleID(o, n, r, cs, ch, t, f, as, excl, incl, x, cv) }
|
||||
wrap[ModuleID, ((String, String, String, Option[String], Option[String]), (Boolean, Boolean, Boolean, Seq[Artifact], Seq[InclusionRule], Seq[ExclusionRule], Map[String, String], CrossVersion))](
|
||||
m => ((m.organization, m.name, m.revision, m.configurations, m.branchName), (m.isChanging, m.isTransitive, m.isForce, m.explicitArtifacts, m.inclusions, m.exclusions, m.extraAttributes, m.crossVersion)),
|
||||
{ case ((o, n, r, cs, br), (ch, t, f, as, incl, excl, x, cv)) => ModuleID(o, n, r, cs, ch, t, f, as, incl, excl, x, cv, br) }
|
||||
)
|
||||
// For some reason sbinary seems to detect unserialized instance Set[ModuleID] to be not equal. #1620
|
||||
implicit def moduleSetIC: InputCache[Set[ModuleID]] =
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
package sbt
|
||||
|
||||
import org.scalacheck._
|
||||
import org.scalacheck.Arbitrary._
|
||||
import Prop._
|
||||
import sbt.librarymanagement._
|
||||
|
||||
class CacheIvyTest extends Properties("CacheIvy") {
|
||||
import CacheIvy._
|
||||
import sbinary.Operations._
|
||||
import sbinary._
|
||||
import sbinary.DefaultProtocol._
|
||||
|
||||
private def cachePreservesEquality[T: Format](m: T, eq: (T, T) => Prop, str: T => String): Prop = {
|
||||
val out = fromByteArray[T](toByteArray(m))
|
||||
eq(out, m) :| s"Expected: ${str(m)}" :| s"Got: ${str(out)}"
|
||||
}
|
||||
|
||||
implicit val arbExclusionRule: Arbitrary[ExclusionRule] = Arbitrary(
|
||||
for {
|
||||
o <- Gen.alphaStr
|
||||
n <- Gen.alphaStr
|
||||
a <- Gen.alphaStr
|
||||
cs <- arbitrary[List[String]]
|
||||
} yield ExclusionRule(o, n, a, cs)
|
||||
)
|
||||
|
||||
implicit val arbCrossVersion: Arbitrary[CrossVersion] = Arbitrary {
|
||||
// Actual functions don't matter, just Disabled vs Binary vs Full
|
||||
import CrossVersion._
|
||||
Gen.oneOf(Disabled, new Binary(identity), new Full(identity))
|
||||
}
|
||||
|
||||
implicit val arbArtifact: Arbitrary[Artifact] = Arbitrary {
|
||||
for {
|
||||
(n, t, e, cls) <- arbitrary[(String, String, String, String)]
|
||||
} yield Artifact(n, t, e, cls) // keep it simple
|
||||
}
|
||||
|
||||
implicit val arbModuleID: Arbitrary[ModuleID] = Arbitrary {
|
||||
for {
|
||||
o <- Gen.identifier
|
||||
n <- Gen.identifier
|
||||
r <- for { n <- Gen.numChar; ns <- Gen.numStr } yield n + ns
|
||||
cs <- arbitrary[Option[String]]
|
||||
branch <- arbitrary[Option[String]]
|
||||
isChanging <- arbitrary[Boolean]
|
||||
isTransitive <- arbitrary[Boolean]
|
||||
isForce <- arbitrary[Boolean]
|
||||
explicitArtifacts <- Gen.listOf(arbitrary[Artifact])
|
||||
exclusions <- Gen.listOf(arbitrary[ExclusionRule])
|
||||
inclusions <- Gen.listOf(arbitrary[InclusionRule])
|
||||
extraAttributes <- Gen.mapOf(arbitrary[(String, String)])
|
||||
crossVersion <- arbitrary[CrossVersion]
|
||||
} yield ModuleID(
|
||||
organization = o, name = n, revision = r, configurations = cs, isChanging = isChanging, isTransitive = isTransitive,
|
||||
isForce = isForce, explicitArtifacts = explicitArtifacts, inclusions = inclusions, exclusions = exclusions,
|
||||
extraAttributes = extraAttributes, crossVersion = crossVersion, branchName = branch)
|
||||
}
|
||||
|
||||
property("moduleIDFormat") = forAll { (m: ModuleID) =>
|
||||
def str(m: ModuleID) = {
|
||||
import m._
|
||||
s"ModuleID($organization, ${m.name}, $revision, $configurations, $isChanging, $isTransitive, $isForce, $explicitArtifacts, $exclusions, " +
|
||||
s"$inclusions, $extraAttributes, $crossVersion, $branchName)"
|
||||
}
|
||||
def eq(a: ModuleID, b: ModuleID): Prop = {
|
||||
import CrossVersion._
|
||||
def rest = a.copy(crossVersion = b.crossVersion) == b
|
||||
(a.crossVersion, b.crossVersion) match {
|
||||
case (Disabled, Disabled) => rest
|
||||
case (_: Binary, _: Binary) => rest
|
||||
case (_: Full, _: Full) => rest
|
||||
case (a, b) => Prop(false) :| s"CrossVersions don't match: $a vs $b"
|
||||
}
|
||||
|
||||
}
|
||||
cachePreservesEquality(m, eq _, str)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue