fport: CrossVersion.patch

CrossVersion.full strips off -bin-suffix.
Ref https://github.com/sbt/sbt/pull/2757
This commit is contained in:
Miles Sabin 2017-01-15 07:55:18 -05:00 committed by Eugene Yokota
parent 3afc15d075
commit f495291edd
3 changed files with 42 additions and 0 deletions

View File

@ -144,6 +144,16 @@
],
"type": "record"
},
{
"name": "Patch",
"namespace": "sbt.librarymanagement",
"target": "Scala",
"doc": [
"Cross-versions a module by stripping off -bin-suffix.",
"This is intented for patch-version compatible alternative replacements."
],
"type": "record"
},
{
"name": "Full",
"namespace": "sbt.librarymanagement",

View File

@ -18,6 +18,19 @@ abstract class CrossVersionFunctions {
/** Cross-versions a module with the binary version (typically the binary Scala version). */
def binary: CrossVersion = Binary()
/**
* Cross-versions a module with the full Scala version excluding any `-bin` suffix.
*/
def patch: CrossVersion = Patch()
private[sbt] def patchFun(fullVersion: String): String = {
val BinCompatV = """(\d+)\.(\d+)\.(\d+)(-\w+)??-bin(-.*)?""".r
fullVersion match {
case BinCompatV(x, y, z, w, _) => s"""$x.$y.$z${if (w == null) "" else w}"""
case other => other
}
}
private[sbt] def append(s: String): Option[String => String] = Some(x => crossName(x, s))
/**
@ -29,6 +42,7 @@ abstract class CrossVersionFunctions {
cross match {
case _: Disabled => None
case _: Binary => append(binaryVersion)
case _: Patch => append(patchFun(fullVersion))
case _: Full => append(fullVersion)
}

View File

@ -114,6 +114,24 @@ class CrossVersionTest extends UnitSpec {
it should "return binary Scala version for 2.10.1 as 2.10" in {
CrossVersion.binaryScalaVersion("2.10.1") shouldBe "2.10"
}
it should "return patch Scala version for 2.11.8 as 2.11.8" in {
CrossVersion(CrossVersion.patch, "2.11.8", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8")
}
it should "return patch Scala version for 2.11.8-M1 as 2.11.8-M1" in {
CrossVersion(CrossVersion.patch, "2.11.8-M1", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-M1")
}
it should "return patch Scala version for 2.11.8-RC1 as 2.11.8-RC1" in {
CrossVersion(CrossVersion.patch, "2.11.8-RC1", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-RC1")
}
it should "return patch Scala version for 2.11.8-bin-extra as 2.11.8" in {
CrossVersion(CrossVersion.patch, "2.11.8-bin-extra", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8")
}
it should "return patch Scala version for 2.11.8-M1-bin-extra as 2.11.8-M1" in {
CrossVersion(CrossVersion.patch, "2.11.8-M1-bin-extra", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-M1")
}
it should "return patch Scala version for 2.11.8-RC1-bin-extra as 2.11.8-RC1" in {
CrossVersion(CrossVersion.patch, "2.11.8-RC1-bin-extra", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-RC1")
}
it should "return disabled cross version as equal to a copy" in {
Disabled() shouldBe Disabled()
}