Switch version patterns to Long instead of Int

For sbt/sbt#3011 reasons.
This commit is contained in:
Dale Wijnand 2017-06-09 15:36:06 +01:00
parent 039e2e6b6a
commit e45d9a254b
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 22 additions and 22 deletions

View File

@ -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"

View File

@ -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.

View File

@ -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"