Skip to content

[fport] CrossVersion.patch #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions librarymanagement/src/main/contraband/librarymanagement.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

/**
Expand All @@ -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)
}

Expand Down
18 changes: 18 additions & 0 deletions librarymanagement/src/test/scala/CrossVersionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down