From 1bbc4719c68ab0eaa462bcf2404470ad23d1da67 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 9 Jun 2017 11:39:58 +0100 Subject: [PATCH 1/4] Cleanup CrossVersion code & tests --- .../cross/CrossVersionUtil.scala | 68 +++--- .../librarymanagement/CrossVersionExtra.scala | 19 +- .../src/test/scala/CrossVersionTest.scala | 203 +++++++++--------- 3 files changed, 139 insertions(+), 151 deletions(-) diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala index cebe00ac5..8c3bdaec0 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala @@ -13,79 +13,73 @@ object CrossVersionUtil { val TransitionSbtVersion = "0.12" def isFull(s: String): Boolean = (s == trueString) || (s == fullString) + def isDisabled(s: String): Boolean = (s == falseString) || (s == noneString) || (s == disabledString) + def isBinary(s: String): Boolean = (s == binaryString) - private lazy val intPattern = """\d{1,10}""" - private lazy val basicVersion = """(""" + intPattern + """)\.(""" + intPattern + """)\.(""" + intPattern + """)""" + private val intPattern = """\d{1,10}""" + private val basicVersion = raw"""($intPattern)\.($intPattern)\.($intPattern)""" + private val ReleaseV = raw"""$basicVersion(-\d+)?""".r + private val BinCompatV = raw"""$basicVersion-bin(-.*)?""".r + private val CandidateV = raw"""$basicVersion(-RC\d+)""".r + private val NonReleaseV_1 = raw"""$basicVersion([-\w+]*)""".r + private val NonReleaseV_2 = raw"""$basicVersion(-\w+)""".r + private[sbt] val PartialVersion = raw"""($intPattern)\.($intPattern)(?:\..+)?""".r private[sbt] def isSbtApiCompatible(v: String): Boolean = sbtApiVersion(v).isDefined /** * Returns sbt binary interface x.y API compatible with the given version string v. * RCs for x.y.0 are considered API compatible. - * Compatibile versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). + * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ - private[sbt] def sbtApiVersion(v: String): Option[(Int, Int)] = { - val ReleaseV = (basicVersion + """(-\d+)?""").r - val CandidateV = (basicVersion + """(-RC\d+)""").r - val NonReleaseV = (basicVersion + """([-\w+]*)""").r - v match { - case ReleaseV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case CandidateV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case NonReleaseV(x, y, z, ht) if z.toInt > 0 => Some((x.toInt, y.toInt)) - case _ => None - } + private[sbt] def sbtApiVersion(v: String): Option[(Int, Int)] = v match { + case ReleaseV(x, y, _, _) => Some((x.toInt, y.toInt)) + case CandidateV(x, y, _, _) => Some((x.toInt, y.toInt)) + case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) + case _ => None } + private[sbt] def isScalaApiCompatible(v: String): Boolean = scalaApiVersion(v).isDefined /** * Returns Scala binary interface x.y API compatible with the given version string v. - * Compatibile versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. + * Compatible versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. */ - private[sbt] def scalaApiVersion(v: String): Option[(Int, Int)] = { - val ReleaseV = (basicVersion + """(-\d+)?""").r - val BinCompatV = (basicVersion + """-bin(-.*)?""").r - val NonReleaseV = (basicVersion + """(-\w+)""").r - v match { - case ReleaseV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case BinCompatV(x, y, z, ht) => Some((x.toInt, y.toInt)) - case NonReleaseV(x, y, z, ht) if z.toInt > 0 => Some((x.toInt, y.toInt)) - case _ => None - } + private[sbt] def scalaApiVersion(v: String): Option[(Int, Int)] = v match { + case ReleaseV(x, y, _, _) => Some((x.toInt, y.toInt)) + case BinCompatV(x, y, _, _) => Some((x.toInt, y.toInt)) + case NonReleaseV_2(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) + case _ => None } - private[sbt] val PartialVersion = - ("""(""" + intPattern + """)\.(""" + intPattern + """)(?:\..+)?""").r + private[sbt] def partialVersion(s: String): Option[(Int, Int)] = s match { case PartialVersion(major, minor) => Some((major.toInt, minor.toInt)) case _ => None } - def binaryScalaVersion(full: String): String = { - val cutoff = - if (full.startsWith("0.")) - TransitionDottyVersion - else - TransitionScalaVersion + def binaryScalaVersion(full: String): String = { + val cutoff = if (full.startsWith("0.")) TransitionDottyVersion else TransitionScalaVersion binaryVersionWithApi(full, cutoff)(scalaApiVersion) } + def binarySbtVersion(full: String): String = binaryVersionWithApi(full, TransitionSbtVersion)(sbtApiVersion) - private[sbt] def binaryVersion(full: String, cutoff: String): String = - binaryVersionWithApi(full, cutoff)(scalaApiVersion) + private[this] def isNewer(major: Int, minor: Int, minMajor: Int, minMinor: Int): Boolean = major > minMajor || (major == minMajor && minor >= minMinor) + private[this] def binaryVersionWithApi(full: String, cutoff: String)( apiVersion: String => Option[(Int, Int)] ): String = { - def sub(major: Int, minor: Int) = major + "." + minor (apiVersion(full), partialVersion(cutoff)) match { - case (Some((major, minor)), None) => sub(major, minor) + case (Some((major, minor)), None) => s"$major.$minor" case (Some((major, minor)), Some((minMajor, minMinor))) if isNewer(major, minor, minMajor, minMinor) => - sub(major, minor) + s"$major.$minor" case _ => full } } diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index 29ef28327..df7278e8d 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -76,8 +76,8 @@ abstract class CrossVersionFunctions { cross: Option[String => String] ): Vector[Artifact] = cross match { - case None => artifacts - case Some(is) => substituteCrossA(artifacts, cross) + case None => artifacts + case Some(_) => substituteCrossA(artifacts, cross) } private[sbt] def applyCross(s: String, fopt: Option[String => String]): String = @@ -124,18 +124,12 @@ abstract class CrossVersionFunctions { m } - @deprecated("Use CrossVersion.isScalaApiCompatible or CrossVersion.isSbtApiCompatible", "0.13.0") - def isStable(v: String): Boolean = isScalaApiCompatible(v) - - @deprecated("Use CrossVersion.scalaApiVersion or CrossVersion.sbtApiVersion", "0.13.0") - def selectVersion(full: String, binary: String): String = if (isStable(full)) binary else full - def isSbtApiCompatible(v: String): Boolean = CrossVersionUtil.isSbtApiCompatible(v) /** * Returns sbt binary interface x.y API compatible with the given version string v. * RCs for x.y.0 are considered API compatible. - * Compatibile versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). + * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ def sbtApiVersion(v: String): Option[(Int, Int)] = CrossVersionUtil.sbtApiVersion(v) @@ -143,7 +137,7 @@ abstract class CrossVersionFunctions { /** * Returns Scala binary interface x.y API compatible with the given version string v. - * Compatibile versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. + * Compatible versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. */ def scalaApiVersion(v: String): Option[(Int, Int)] = CrossVersionUtil.scalaApiVersion(v) @@ -164,9 +158,4 @@ abstract class CrossVersionFunctions { * Full sbt versions earlier than [[sbt.librarymanagement.CrossVersion.TransitionSbtVersion]] are returned as is. */ def binarySbtVersion(full: String): String = CrossVersionUtil.binarySbtVersion(full) - - @deprecated("Use CrossVersion.scalaApiVersion or CrossVersion.sbtApiVersion", "0.13.0") - def binaryVersion(full: String, cutoff: String): String = - CrossVersionUtil.binaryVersion(full, cutoff) - } diff --git a/librarymanagement/src/test/scala/CrossVersionTest.scala b/librarymanagement/src/test/scala/CrossVersionTest.scala index 835ad1058..c6a7107a9 100644 --- a/librarymanagement/src/test/scala/CrossVersionTest.scala +++ b/librarymanagement/src/test/scala/CrossVersionTest.scala @@ -1,156 +1,161 @@ package sbt.librarymanagement import sbt.internal.util.UnitSpec +import CrossVersion._ class CrossVersionTest extends UnitSpec { - "Cross version" should "return sbt API for xyz as None" in { - CrossVersion.sbtApiVersion("xyz") shouldBe None + "sbtApiVersion" should "for xyz return None" in { + sbtApiVersion("xyz") shouldBe None } - it should "return sbt API for 0.12 as None" in { - CrossVersion.sbtApiVersion("0.12") shouldBe None + it should "for 0.12 return None" in { + sbtApiVersion("0.12") shouldBe None } - it should "return sbt API for 0.12.0-SNAPSHOT as None" in { - CrossVersion.sbtApiVersion("0.12.0-SNAPSHOT") shouldBe None + it should "for 0.12.0-SNAPSHOT return None" in { + sbtApiVersion("0.12.0-SNAPSHOT") shouldBe None } - it should "return sbt API for 0.12.0-RC1 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.0-RC1") shouldBe Some((0, 12)) + it should "for 0.12.0-RC1 return Some((0, 12))" in { + sbtApiVersion("0.12.0-RC1") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.0 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.0") shouldBe Some((0, 12)) + it should "for 0.12.0 return Some((0, 12))" in { + sbtApiVersion("0.12.0") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.1-SNAPSHOT as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.1-SNAPSHOT") shouldBe Some((0, 12)) + it should "for 0.12.1-SNAPSHOT return Some((0, 12))" in { + sbtApiVersion("0.12.1-SNAPSHOT") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.1-RC1 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.1-RC1") shouldBe Some((0, 12)) + it should "for 0.12.1-RC1 return Some((0, 12))" in { + sbtApiVersion("0.12.1-RC1") shouldBe Some((0, 12)) } - it should "return sbt API for 0.12.1 as Some((0, 12))" in { - CrossVersion.sbtApiVersion("0.12.1") shouldBe Some((0, 12)) + it should "for 0.12.1 return Some((0, 12))" in { + sbtApiVersion("0.12.1") shouldBe Some((0, 12)) } - it should "return sbt API compatibility for 0.12.0-M1 as false" in { - CrossVersion.isSbtApiCompatible("0.12.0-M1") shouldBe false + + "isSbtApiCompatible" should "for 0.12.0-M1 return false" in { + isSbtApiCompatible("0.12.0-M1") shouldBe false } - it should "return sbt API compatibility for 0.12.0-RC1 as true" in { - CrossVersion.isSbtApiCompatible("0.12.0-RC1") shouldBe true + it should "for 0.12.0-RC1 return true" in { + isSbtApiCompatible("0.12.0-RC1") shouldBe true } - it should "return sbt API compatibility for 0.12.1-RC1 as true" in { - CrossVersion.isSbtApiCompatible("0.12.1-RC1") shouldBe true + it should "for 0.12.1-RC1 return true" in { + isSbtApiCompatible("0.12.1-RC1") shouldBe true } - it should "return binary sbt version for 0.11.3 as 0.11.3" in { - CrossVersion.binarySbtVersion("0.11.3") shouldBe "0.11.3" + + "binarySbtVersion" should "for 0.11.3 return 0.11.3" in { + binarySbtVersion("0.11.3") shouldBe "0.11.3" } - it should "return binary sbt version for 0.12.0-M1 as 0.12.0-M1" in { - CrossVersion.binarySbtVersion("0.12.0-M1") shouldBe "0.12.0-M1" + it should "for 0.12.0-M1 return 0.12.0-M1" in { + binarySbtVersion("0.12.0-M1") shouldBe "0.12.0-M1" } - it should "return binary sbt version for 0.12.0-RC1 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.0-RC1") shouldBe "0.12" + it should "for 0.12.0-RC1 return 0.12" in { + binarySbtVersion("0.12.0-RC1") shouldBe "0.12" } - it should "return binary sbt version for 0.12.0 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.0") shouldBe "0.12" + it should "for 0.12.0 return 0.12" in { + binarySbtVersion("0.12.0") shouldBe "0.12" } - it should "return binary sbt version for 0.12.1-SNAPSHOT as 0.12" in { - CrossVersion.binarySbtVersion("0.12.1-SNAPSHOT") shouldBe "0.12" + it should "for 0.12.1-SNAPSHOT return 0.12" in { + binarySbtVersion("0.12.1-SNAPSHOT") shouldBe "0.12" } - it should "return binary sbt version for 0.12.1-RC1 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.1-RC1") shouldBe "0.12" + it should "for 0.12.1-RC1 return 0.12" in { + binarySbtVersion("0.12.1-RC1") shouldBe "0.12" } - it should "return binary sbt version for 0.12.1 as 0.12" in { - CrossVersion.binarySbtVersion("0.12.1") shouldBe "0.12" + it should "for 0.12.1 return 0.12" in { + binarySbtVersion("0.12.1") shouldBe "0.12" } - it should "return Scala API for xyz as None" in { - CrossVersion.scalaApiVersion("xyz") shouldBe None + + "scalaApiVersion" should "for xyz return None" in { + scalaApiVersion("xyz") shouldBe None } - it should "return Scala API for 2.10 as None" in { - CrossVersion.scalaApiVersion("2.10") shouldBe None + it should "for 2.10 return None" in { + scalaApiVersion("2.10") shouldBe None } - it should "return Scala API for 2.10.0-SNAPSHOT as None" in { - CrossVersion.scalaApiVersion("2.10.0-SNAPSHOT") shouldBe None + it should "for 2.10.0-SNAPSHOT return None" in { + scalaApiVersion("2.10.0-SNAPSHOT") shouldBe None } - it should "return Scala API for 2.10.0-RC1 as None" in { - CrossVersion.scalaApiVersion("2.10.0-RC1") shouldBe None + it should "for 2.10.0-RC1 return None" in { + scalaApiVersion("2.10.0-RC1") shouldBe None } - it should "return Scala API for 2.10.0 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.0") shouldBe Some((2, 10)) + it should "for 2.10.0 return Some((2, 10))" in { + scalaApiVersion("2.10.0") shouldBe Some((2, 10)) } - it should "return Scala API for 2.10.0-1 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.0-1") shouldBe Some((2, 10)) + it should "for 2.10.0-1 return Some((2, 10))" in { + scalaApiVersion("2.10.0-1") shouldBe Some((2, 10)) } - it should "return Scala API for 2.10.1-SNAPSHOT as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.1-SNAPSHOT") shouldBe Some((2, 10)) + it should "for 2.10.1-SNAPSHOT return Some((2, 10))" in { + scalaApiVersion("2.10.1-SNAPSHOT") shouldBe Some((2, 10)) } - it should "return Scala API for 2.10.1-RC1 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.1-RC1") shouldBe Some((2, 10)) + it should "for 2.10.1-RC1 return Some((2, 10))" in { + scalaApiVersion("2.10.1-RC1") shouldBe Some((2, 10)) } - it should "return Scala API for 2.10.1 as Some((2, 10))" in { - CrossVersion.scalaApiVersion("2.10.1") shouldBe Some((2, 10)) + it should "for 2.10.1 return Some((2, 10))" in { + scalaApiVersion("2.10.1") shouldBe Some((2, 10)) } - it should "return Scala API compatibility for 2.10.0-M1 as false" in { - CrossVersion.isScalaApiCompatible("2.10.0-M1") shouldBe false + + "isScalaApiCompatible" should "for 2.10.0-M1 return false" in { + isScalaApiCompatible("2.10.0-M1") shouldBe false } - it should "return Scala API compatibility for 2.10.0-RC1 as false" in { - CrossVersion.isScalaApiCompatible("2.10.0-RC1") shouldBe false + it should "for 2.10.0-RC1 return false" in { + isScalaApiCompatible("2.10.0-RC1") shouldBe false } - it should "return Scala API compatibility for 2.10.1-RC1 as false" in { - CrossVersion.isScalaApiCompatible("2.10.1-RC1") shouldBe true + it should "for 2.10.1-RC1 return false" in { + isScalaApiCompatible("2.10.1-RC1") shouldBe true } - it should "return binary Scala version for 2.9.2 as 2.9.2" in { - CrossVersion.binaryScalaVersion("2.9.2") shouldBe "2.9.2" + + "binaryScalaVersion" should "for 2.9.2 return 2.9.2" in { + binaryScalaVersion("2.9.2") shouldBe "2.9.2" } - it should "return binary Scala version for 2.10.0-M1 as 2.10.0-M1" in { - CrossVersion.binaryScalaVersion("2.10.0-M1") shouldBe "2.10.0-M1" + it should "for 2.10.0-M1 return 2.10.0-M1" in { + binaryScalaVersion("2.10.0-M1") shouldBe "2.10.0-M1" } - it should "return binary Scala version for 2.10.0-RC1 as 2.10.0-RC1" in { - CrossVersion.binaryScalaVersion("2.10.0-RC1") shouldBe "2.10.0-RC1" + it should "for 2.10.0-RC1 return 2.10.0-RC1" in { + binaryScalaVersion("2.10.0-RC1") shouldBe "2.10.0-RC1" } - it should "return binary Scala version for 2.10.0 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.0") shouldBe "2.10" + it should "for 2.10.0 return 2.10" in { + binaryScalaVersion("2.10.0") shouldBe "2.10" } - it should "return binary Scala version for 2.10.1-M1 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.1-M1") shouldBe "2.10" + it should "for 2.10.1-M1 return 2.10" in { + binaryScalaVersion("2.10.1-M1") shouldBe "2.10" } - it should "return binary Scala version for 2.10.1-RC1 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.1-RC1") shouldBe "2.10" + it should "for 2.10.1-RC1 return 2.10" in { + binaryScalaVersion("2.10.1-RC1") shouldBe "2.10" } - it should "return binary Scala version for 2.10.1 as 2.10" in { - CrossVersion.binaryScalaVersion("2.10.1") shouldBe "2.10" + it should "for 2.10.1 return 2.10" in { + binaryScalaVersion("2.10.1") shouldBe "2.10" } - it should "return binary Scala version for 2.20170314093845.0-87654321 as 2.20170314093845.0-87654321" in { - CrossVersion.binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845.0-87654321" + it should "for 2.20170314093845.0-87654321 return 2.20170314093845.0-87654321" in { + binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845.0-87654321" } - it should "return binary Scala version for Dotty 0.1.1 as 0.1" in { - CrossVersion.binaryScalaVersion("0.1.1") shouldBe "0.1" + it should "for Dotty 0.1.1 return 0.1" in { + binaryScalaVersion("0.1.1") shouldBe "0.1" } - 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") + + private def patchVersion(fullVersion: String) = + CrossVersion(CrossVersion.patch, fullVersion, "dummy") map (fn => fn("artefact")) + + "CrossVersion.patch" should "for 2.11.8 return 2.11.8" in { + patchVersion("2.11.8") 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 "for 2.11.8-M1 return 2.11.8-M1" in { + patchVersion("2.11.8-M1") 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 "for 2.11.8-RC1 return 2.11.8-RC1" in { + patchVersion("2.11.8-RC1") 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 "for 2.11.8-bin-extra return 2.11.8" in { + patchVersion("2.11.8-bin-extra") 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 "for 2.11.8-M1-bin-extra return 2.11.8-M1" in { + patchVersion("2.11.8-M1-bin-extra") 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 "for 2.11.8-RC1-bin-extra return 2.11.8-RC1" in { + patchVersion("2.11.8-RC1-bin-extra") shouldBe Some("artefact_2.11.8-RC1") } - it should "return disabled cross version as equal to a copy" in { + + "Disabled" should "have structural equality" in { Disabled() shouldBe Disabled() } - it should "return full cross version as equal to a copy" in { + "CrossVersion.full" should "have structural equality" in { CrossVersion.full shouldBe CrossVersion.full } - it should "return binary cross version as equal to a copy" in { + "CrossVersion.binary" should "have structural equality" in { CrossVersion.binary shouldBe CrossVersion.binary } } From f98ee86668d7065ffb49d541e81e303558cd6229 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 9 Jun 2017 11:49:12 +0100 Subject: [PATCH 2/4] Clarify NonRelease variants in CrossVersion --- .../librarymanagement/cross/CrossVersionUtil.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala index 8c3bdaec0..e2b9999fb 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala @@ -24,8 +24,8 @@ object CrossVersionUtil { private val ReleaseV = raw"""$basicVersion(-\d+)?""".r private val BinCompatV = raw"""$basicVersion-bin(-.*)?""".r private val CandidateV = raw"""$basicVersion(-RC\d+)""".r - private val NonReleaseV_1 = raw"""$basicVersion([-\w+]*)""".r - private val NonReleaseV_2 = raw"""$basicVersion(-\w+)""".r + private val NonReleaseV_n = raw"""$basicVersion([-\w]*)""".r // 0-n word suffixes, with leading dashes + private val NonReleaseV_1 = raw"""$basicVersion(-\w+)""".r // 1 word suffix, after a dash private[sbt] val PartialVersion = raw"""($intPattern)\.($intPattern)(?:\..+)?""".r private[sbt] def isSbtApiCompatible(v: String): Boolean = sbtApiVersion(v).isDefined @@ -38,7 +38,7 @@ object CrossVersionUtil { private[sbt] def sbtApiVersion(v: String): Option[(Int, Int)] = v match { case ReleaseV(x, y, _, _) => Some((x.toInt, y.toInt)) case CandidateV(x, y, _, _) => Some((x.toInt, y.toInt)) - case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) + case NonReleaseV_n(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) case _ => None } @@ -51,7 +51,7 @@ object CrossVersionUtil { private[sbt] def scalaApiVersion(v: String): Option[(Int, Int)] = v match { case ReleaseV(x, y, _, _) => Some((x.toInt, y.toInt)) case BinCompatV(x, y, _, _) => Some((x.toInt, y.toInt)) - case NonReleaseV_2(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) + case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) case _ => None } From 039e2e6b6ac3c8bd88bb140b6c77d3ef79135a17 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 9 Jun 2017 12:17:02 +0100 Subject: [PATCH 3/4] Change the sbt API/binary version for sbt 1.x to be 1.0 --- .../cross/CrossVersionUtil.scala | 14 +++- .../src/test/scala/CrossVersionTest.scala | 81 +++++++++++++++++++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala index e2b9999fb..26ea94460 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala @@ -36,12 +36,20 @@ object CrossVersionUtil { * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ private[sbt] def sbtApiVersion(v: String): Option[(Int, Int)] = v match { - case ReleaseV(x, y, _, _) => Some((x.toInt, y.toInt)) - case CandidateV(x, y, _, _) => Some((x.toInt, y.toInt)) - case NonReleaseV_n(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) + case ReleaseV(x, y, _, _) => Some(sbtApiVersion(x.toInt, y.toInt)) + case CandidateV(x, y, _, _) => Some(sbtApiVersion(x.toInt, y.toInt)) + case NonReleaseV_n(x, y, z, _) if z.toInt > 0 => Some(sbtApiVersion(x.toInt, y.toInt)) case _ => None } + private def sbtApiVersion(x: Int, y: Int) = { + // Prior to sbt 1 the "sbt api version" was the X.Y in the X.Y.Z version. + // For example for sbt 0.13.x releases, the sbt api version is 0.13 + // As of sbt 1 it is now X.0. + // This means, for example, that all versions of sbt 1.x have sbt api version 1.0 + if (x > 0) (x, 0) else (x, y) + } + private[sbt] def isScalaApiCompatible(v: String): Boolean = scalaApiVersion(v).isDefined /** diff --git a/librarymanagement/src/test/scala/CrossVersionTest.scala b/librarymanagement/src/test/scala/CrossVersionTest.scala index c6a7107a9..5db072909 100644 --- a/librarymanagement/src/test/scala/CrossVersionTest.scala +++ b/librarymanagement/src/test/scala/CrossVersionTest.scala @@ -28,6 +28,33 @@ class CrossVersionTest extends UnitSpec { it should "for 0.12.1 return Some((0, 12))" in { sbtApiVersion("0.12.1") shouldBe Some((0, 12)) } + it should "for 1.0.0-M6 return None" in { + sbtApiVersion("1.0.0-M6") shouldBe None + } + it should "for 1.0.0-RC1 return Some((1, 0))" in { + sbtApiVersion("1.0.0-RC1") shouldBe Some((1, 0)) + } + it should "for 1.0.0 return Some((1, 0))" in { + sbtApiVersion("1.0.0") shouldBe Some((1, 0)) + } + it should "for 1.0.2-M1 return Some((1, 0))" in { + sbtApiVersion("1.0.2-M1") shouldBe Some((1, 0)) + } + it should "for 1.0.2-RC1 return Some((1, 0))" in { + sbtApiVersion("1.0.2-RC1") shouldBe Some((1, 0)) + } + it should "for 1.0.2 return Some((1, 0))" in { + sbtApiVersion("1.0.2") shouldBe Some((1, 0)) + } + it should "for 1.3.0 return Some((1, 0))" in { + sbtApiVersion("1.3.0") shouldBe Some((1, 0)) + } + it should "for 1.10.0 return Some((1, 0))" in { + sbtApiVersion("1.10.0") shouldBe Some((1, 0)) + } + it should "for 2.0.0 return Some((2, 0))" in { + sbtApiVersion("2.0.0") shouldBe Some((2, 0)) + } "isSbtApiCompatible" should "for 0.12.0-M1 return false" in { isSbtApiCompatible("0.12.0-M1") shouldBe false @@ -38,6 +65,33 @@ class CrossVersionTest extends UnitSpec { it should "for 0.12.1-RC1 return true" in { isSbtApiCompatible("0.12.1-RC1") shouldBe true } + it should "for 1.0.0-M6 return false" in { + isSbtApiCompatible("1.0.0-M6") shouldBe false + } + it should "for 1.0.0-RC1 return true" in { + isSbtApiCompatible("1.0.0-RC1") shouldBe true + } + it should "for 1.0.0 return true" in { + isSbtApiCompatible("1.0.0") shouldBe true + } + it should "for 1.0.2-M1 return true" in { + isSbtApiCompatible("1.0.2-M1") shouldBe true + } + it should "for 1.0.2-RC1 return true" in { + isSbtApiCompatible("1.0.2-RC1") shouldBe true + } + it should "for 1.0.2 return true" in { + isSbtApiCompatible("1.0.2") shouldBe true + } + it should "for 1.3.0 return true" in { + isSbtApiCompatible("1.3.0") shouldBe true + } + it should "for 1.10.0 return true" in { + isSbtApiCompatible("1.10.0") shouldBe true + } + it should "for 2.0.0 return true" in { + isSbtApiCompatible("2.0.0") shouldBe true + } "binarySbtVersion" should "for 0.11.3 return 0.11.3" in { binarySbtVersion("0.11.3") shouldBe "0.11.3" @@ -60,6 +114,33 @@ class CrossVersionTest extends UnitSpec { it should "for 0.12.1 return 0.12" in { binarySbtVersion("0.12.1") shouldBe "0.12" } + it should "for 1.0.0-M6 return 1.0.0-M6" in { + binarySbtVersion("1.0.0-M6") shouldBe "1.0.0-M6" + } + it should "for 1.0.0-RC1 return 1.0" in { + binarySbtVersion("1.0.0-RC1") shouldBe "1.0" + } + it should "for 1.0.0 return 1.0" in { + binarySbtVersion("1.0.0") shouldBe "1.0" + } + it should "for 1.0.2-M1 return 1.0" in { + binarySbtVersion("1.0.2-M1") shouldBe "1.0" + } + it should "for 1.0.2-RC1 return 1.0" in { + binarySbtVersion("1.0.2-RC1") shouldBe "1.0" + } + it should "for 1.0.2 return 1.0" in { + binarySbtVersion("1.0.2") shouldBe "1.0" + } + it should "for 1.3.0 return 1.0" in { + binarySbtVersion("1.3.0") shouldBe "1.0" + } + it should "for 1.10.0 return 1.0" in { + binarySbtVersion("1.10.0") shouldBe "1.0" + } + it should "for 2.0.0 return 2.0" in { + binarySbtVersion("2.0.0") shouldBe "2.0" + } "scalaApiVersion" should "for xyz return None" in { scalaApiVersion("xyz") shouldBe None From e45d9a254b1cd1e1173b57d2d215958bd8489225 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 9 Jun 2017 15:36:06 +0100 Subject: [PATCH 4/4] Switch version patterns to Long instead of Int For sbt/sbt#3011 reasons. --- .../cross/CrossVersionUtil.scala | 34 +++++++++---------- .../librarymanagement/CrossVersionExtra.scala | 6 ++-- .../src/test/scala/CrossVersionTest.scala | 4 +-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala index 26ea94460..b9d4cc2dd 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala @@ -19,14 +19,14 @@ object CrossVersionUtil { def isBinary(s: String): Boolean = (s == binaryString) - private val intPattern = """\d{1,10}""" - private val basicVersion = raw"""($intPattern)\.($intPattern)\.($intPattern)""" + private val longPattern = """\d{1,19}""" + private val basicVersion = raw"""($longPattern)\.($longPattern)\.($longPattern)""" private val ReleaseV = raw"""$basicVersion(-\d+)?""".r private val BinCompatV = raw"""$basicVersion-bin(-.*)?""".r private val CandidateV = raw"""$basicVersion(-RC\d+)""".r private val NonReleaseV_n = raw"""$basicVersion([-\w]*)""".r // 0-n word suffixes, with leading dashes private val NonReleaseV_1 = raw"""$basicVersion(-\w+)""".r // 1 word suffix, after a dash - private[sbt] val PartialVersion = raw"""($intPattern)\.($intPattern)(?:\..+)?""".r + private[sbt] val PartialVersion = raw"""($longPattern)\.($longPattern)(?:\..+)?""".r private[sbt] def isSbtApiCompatible(v: String): Boolean = sbtApiVersion(v).isDefined @@ -35,19 +35,19 @@ object CrossVersionUtil { * RCs for x.y.0 are considered API compatible. * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ - private[sbt] def sbtApiVersion(v: String): Option[(Int, Int)] = v match { - case ReleaseV(x, y, _, _) => Some(sbtApiVersion(x.toInt, y.toInt)) - case CandidateV(x, y, _, _) => Some(sbtApiVersion(x.toInt, y.toInt)) - case NonReleaseV_n(x, y, z, _) if z.toInt > 0 => Some(sbtApiVersion(x.toInt, y.toInt)) + private[sbt] def sbtApiVersion(v: String): Option[(Long, Long)] = v match { + case ReleaseV(x, y, _, _) => Some(sbtApiVersion(x.toLong, y.toLong)) + case CandidateV(x, y, _, _) => Some(sbtApiVersion(x.toLong, y.toLong)) + case NonReleaseV_n(x, y, z, _) if z.toInt > 0 => Some(sbtApiVersion(x.toLong, y.toLong)) case _ => None } - private def sbtApiVersion(x: Int, y: Int) = { + private def sbtApiVersion(x: Long, y: Long) = { // Prior to sbt 1 the "sbt api version" was the X.Y in the X.Y.Z version. // For example for sbt 0.13.x releases, the sbt api version is 0.13 // As of sbt 1 it is now X.0. // This means, for example, that all versions of sbt 1.x have sbt api version 1.0 - if (x > 0) (x, 0) else (x, y) + if (x > 0) (x, 0L) else (x, y) } private[sbt] def isScalaApiCompatible(v: String): Boolean = scalaApiVersion(v).isDefined @@ -56,16 +56,16 @@ object CrossVersionUtil { * Returns Scala binary interface x.y API compatible with the given version string v. * Compatible versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. */ - private[sbt] def scalaApiVersion(v: String): Option[(Int, Int)] = v match { - case ReleaseV(x, y, _, _) => Some((x.toInt, y.toInt)) - case BinCompatV(x, y, _, _) => Some((x.toInt, y.toInt)) - case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toInt, y.toInt)) + private[sbt] def scalaApiVersion(v: String): Option[(Long, Long)] = v match { + case ReleaseV(x, y, _, _) => Some((x.toLong, y.toLong)) + case BinCompatV(x, y, _, _) => Some((x.toLong, y.toLong)) + case NonReleaseV_1(x, y, z, _) if z.toInt > 0 => Some((x.toLong, y.toLong)) case _ => None } - private[sbt] def partialVersion(s: String): Option[(Int, Int)] = + private[sbt] def partialVersion(s: String): Option[(Long, Long)] = s match { - case PartialVersion(major, minor) => Some((major.toInt, minor.toInt)) + case PartialVersion(major, minor) => Some((major.toLong, minor.toLong)) case _ => None } @@ -77,11 +77,11 @@ object CrossVersionUtil { def binarySbtVersion(full: String): String = binaryVersionWithApi(full, TransitionSbtVersion)(sbtApiVersion) - private[this] def isNewer(major: Int, minor: Int, minMajor: Int, minMinor: Int): Boolean = + private[this] def isNewer(major: Long, minor: Long, minMajor: Long, minMinor: Long): Boolean = major > minMajor || (major == minMajor && minor >= minMinor) private[this] def binaryVersionWithApi(full: String, cutoff: String)( - apiVersion: String => Option[(Int, Int)] + apiVersion: String => Option[(Long, Long)] ): String = { (apiVersion(full), partialVersion(cutoff)) match { case (Some((major, minor)), None) => s"$major.$minor" diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index df7278e8d..c7e8fecc8 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -131,7 +131,7 @@ abstract class CrossVersionFunctions { * RCs for x.y.0 are considered API compatible. * Compatible versions include 0.12.0-1 and 0.12.0-RC1 for Some(0, 12). */ - def sbtApiVersion(v: String): Option[(Int, Int)] = CrossVersionUtil.sbtApiVersion(v) + def sbtApiVersion(v: String): Option[(Long, Long)] = CrossVersionUtil.sbtApiVersion(v) def isScalaApiCompatible(v: String): Boolean = CrossVersionUtil.isScalaApiCompatible(v) @@ -139,13 +139,13 @@ abstract class CrossVersionFunctions { * Returns Scala binary interface x.y API compatible with the given version string v. * Compatible versions include 2.10.0-1 and 2.10.1-M1 for Some(2, 10), but not 2.10.0-RC1. */ - def scalaApiVersion(v: String): Option[(Int, Int)] = CrossVersionUtil.scalaApiVersion(v) + def scalaApiVersion(v: String): Option[(Long, Long)] = CrossVersionUtil.scalaApiVersion(v) /** Regular expression that extracts the major and minor components of a version into matched groups 1 and 2.*/ val PartialVersion = CrossVersionUtil.PartialVersion /** Extracts the major and minor components of a version string `s` or returns `None` if the version is improperly formatted. */ - def partialVersion(s: String): Option[(Int, Int)] = CrossVersionUtil.partialVersion(s) + def partialVersion(s: String): Option[(Long, Long)] = CrossVersionUtil.partialVersion(s) /** * Computes the binary Scala version from the `full` version. diff --git a/librarymanagement/src/test/scala/CrossVersionTest.scala b/librarymanagement/src/test/scala/CrossVersionTest.scala index 5db072909..b65c9a11b 100644 --- a/librarymanagement/src/test/scala/CrossVersionTest.scala +++ b/librarymanagement/src/test/scala/CrossVersionTest.scala @@ -201,8 +201,8 @@ class CrossVersionTest extends UnitSpec { it should "for 2.10.1 return 2.10" in { binaryScalaVersion("2.10.1") shouldBe "2.10" } - it should "for 2.20170314093845.0-87654321 return 2.20170314093845.0-87654321" in { - binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845.0-87654321" + it should "for 2.20170314093845.0-87654321 return 2.20170314093845" in { + binaryScalaVersion("2.20170314093845.0-87654321") shouldBe "2.20170314093845" } it should "for Dotty 0.1.1 return 0.1" in { binaryScalaVersion("0.1.1") shouldBe "0.1"