Skip to content

Commit f495291

Browse files
milessabineed3si9n
authored andcommitted
fport: CrossVersion.patch
CrossVersion.full strips off -bin-suffix. Ref sbt/sbt#2757
1 parent 3afc15d commit f495291

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

librarymanagement/src/main/contraband/librarymanagement.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@
144144
],
145145
"type": "record"
146146
},
147+
{
148+
"name": "Patch",
149+
"namespace": "sbt.librarymanagement",
150+
"target": "Scala",
151+
"doc": [
152+
"Cross-versions a module by stripping off -bin-suffix.",
153+
"This is intented for patch-version compatible alternative replacements."
154+
],
155+
"type": "record"
156+
},
147157
{
148158
"name": "Full",
149159
"namespace": "sbt.librarymanagement",

librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ abstract class CrossVersionFunctions {
1818
/** Cross-versions a module with the binary version (typically the binary Scala version). */
1919
def binary: CrossVersion = Binary()
2020

21+
/**
22+
* Cross-versions a module with the full Scala version excluding any `-bin` suffix.
23+
*/
24+
def patch: CrossVersion = Patch()
25+
26+
private[sbt] def patchFun(fullVersion: String): String = {
27+
val BinCompatV = """(\d+)\.(\d+)\.(\d+)(-\w+)??-bin(-.*)?""".r
28+
fullVersion match {
29+
case BinCompatV(x, y, z, w, _) => s"""$x.$y.$z${if (w == null) "" else w}"""
30+
case other => other
31+
}
32+
}
33+
2134
private[sbt] def append(s: String): Option[String => String] = Some(x => crossName(x, s))
2235

2336
/**
@@ -29,6 +42,7 @@ abstract class CrossVersionFunctions {
2942
cross match {
3043
case _: Disabled => None
3144
case _: Binary => append(binaryVersion)
45+
case _: Patch => append(patchFun(fullVersion))
3246
case _: Full => append(fullVersion)
3347
}
3448

librarymanagement/src/test/scala/CrossVersionTest.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ class CrossVersionTest extends UnitSpec {
114114
it should "return binary Scala version for 2.10.1 as 2.10" in {
115115
CrossVersion.binaryScalaVersion("2.10.1") shouldBe "2.10"
116116
}
117+
it should "return patch Scala version for 2.11.8 as 2.11.8" in {
118+
CrossVersion(CrossVersion.patch, "2.11.8", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8")
119+
}
120+
it should "return patch Scala version for 2.11.8-M1 as 2.11.8-M1" in {
121+
CrossVersion(CrossVersion.patch, "2.11.8-M1", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-M1")
122+
}
123+
it should "return patch Scala version for 2.11.8-RC1 as 2.11.8-RC1" in {
124+
CrossVersion(CrossVersion.patch, "2.11.8-RC1", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-RC1")
125+
}
126+
it should "return patch Scala version for 2.11.8-bin-extra as 2.11.8" in {
127+
CrossVersion(CrossVersion.patch, "2.11.8-bin-extra", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8")
128+
}
129+
it should "return patch Scala version for 2.11.8-M1-bin-extra as 2.11.8-M1" in {
130+
CrossVersion(CrossVersion.patch, "2.11.8-M1-bin-extra", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-M1")
131+
}
132+
it should "return patch Scala version for 2.11.8-RC1-bin-extra as 2.11.8-RC1" in {
133+
CrossVersion(CrossVersion.patch, "2.11.8-RC1-bin-extra", "dummy").map(_("artefact")) shouldBe Some("artefact_2.11.8-RC1")
134+
}
117135
it should "return disabled cross version as equal to a copy" in {
118136
Disabled() shouldBe Disabled()
119137
}

0 commit comments

Comments
 (0)