Discovered that RC comparison was problematic in Akka HTTP

This commit is contained in:
Johan Andrén 2019-10-23 14:56:19 +02:00
parent 87ba57d42e
commit a613661075
2 changed files with 20 additions and 17 deletions

View file

@ -18,6 +18,7 @@ class AkkaVersionSpec extends WordSpec with Matchers {
"succeed if version is RC and ok" in {
AkkaVersion.require("AkkaVersionSpec", "2.5.6", "2.5.7-RC10")
AkkaVersion.require("AkkaVersionSpec", "2.6.0-RC1", "2.6.0-RC1")
}
"fail if version is RC and not ok" in {

View file

@ -29,24 +29,26 @@ object AkkaVersion {
*/
@InternalApi
private[akka] def require(libraryName: String, requiredVersion: String, currentVersion: String): Unit = {
val VersionPattern = """(\d+)\.(\d+)\.(\d+)(-(?:M|RC)\d+)?""".r
currentVersion match {
case VersionPattern(currentMajorStr, currentMinorStr, currentPatchStr, mOrRc) =>
requiredVersion match {
case requiredVersion @ VersionPattern(requiredMajorStr, requiredMinorStr, requiredPatchStr, _) =>
// a M or RC is basically in-between versions, so offset
val currentPatch =
if (mOrRc ne null) currentPatchStr.toInt - 1
else currentPatchStr.toInt
if (requiredMajorStr.toInt != currentMajorStr.toInt ||
requiredMinorStr.toInt > currentMinorStr.toInt ||
(requiredMinorStr == currentMinorStr && requiredPatchStr.toInt > currentPatch))
throw new UnsupportedAkkaVersion(
s"Current version of Akka is [$currentVersion], but $libraryName requires version [$requiredVersion]")
case _ => throw new IllegalArgumentException(s"Required version string is invalid: [$requiredVersion]")
}
if (requiredVersion != currentVersion) {
val VersionPattern = """(\d+)\.(\d+)\.(\d+)(-(?:M|RC)\d+)?""".r
currentVersion match {
case VersionPattern(currentMajorStr, currentMinorStr, currentPatchStr, mOrRc) =>
requiredVersion match {
case requiredVersion @ VersionPattern(requiredMajorStr, requiredMinorStr, requiredPatchStr, _) =>
// a M or RC is basically in-between versions, so offset
val currentPatch =
if (mOrRc ne null) currentPatchStr.toInt - 1
else currentPatchStr.toInt
if (requiredMajorStr.toInt != currentMajorStr.toInt ||
requiredMinorStr.toInt > currentMinorStr.toInt ||
(requiredMinorStr == currentMinorStr && requiredPatchStr.toInt > currentPatch))
throw new UnsupportedAkkaVersion(
s"Current version of Akka is [$currentVersion], but $libraryName requires version [$requiredVersion]")
case _ => throw new IllegalArgumentException(s"Required version string is invalid: [$requiredVersion]")
}
case _ => // SNAPSHOT or unknown - you're on your own
case _ => // SNAPSHOT or unknown - you're on your own
}
}
}