This is an automated email from the ASF dual-hosted git repository. hepin pushed a commit to branch 1.3.x-sbtRc in repository https://gitbox.apache.org/repos/asf/pekko.git
commit 534b16463a19913d612f24e3b6369cbbf7c26489 Author: Philippus Baalman <[email protected]> AuthorDate: Sat Nov 8 00:49:44 2025 +0100 Compare required RC and M versions if present (#2441) (cherry picked from commit f86d79ba3cc363bae7b2e0ca57237eca1ecc64d0) --- .../scala/org/apache/pekko/PekkoVersionSpec.scala | 15 +++++++++ .../main/scala/org/apache/pekko/PekkoVersion.scala | 38 ++++++++++++++++------ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/actor-tests/src/test/scala/org/apache/pekko/PekkoVersionSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/PekkoVersionSpec.scala index 31be1f45a9..3e2fb926b9 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/PekkoVersionSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/PekkoVersionSpec.scala @@ -29,22 +29,37 @@ class PekkoVersionSpec extends AnyWordSpec with Matchers { "succeed if version is RC and ok" in { PekkoVersion.require("PekkoVersionSpec", "2.5.6", "2.5.7-RC10") PekkoVersion.require("PekkoVersionSpec", "2.6.0-RC1", "2.6.0-RC1") + PekkoVersion.require("PekkoVersionSpec", "2.6.0-RC1", "2.6.0-RC2") + PekkoVersion.require("PekkoVersionSpec", "2.6.0-RC1", "2.7.0") } "fail if version is RC and not ok" in { intercept[UnsupportedPekkoVersion] { PekkoVersion.require("PekkoVersionSpec", "2.5.6", "2.5.6-RC1") } + intercept[UnsupportedPekkoVersion] { + PekkoVersion.require("PekkoVersionSpec", "2.5.6-RC2", "2.5.6-RC1") + } } "succeed if version is milestone and ok" in { PekkoVersion.require("PekkoVersionSpec", "2.5.6", "2.5.7-M10") + PekkoVersion.require("PekkoVersionSpec", "2.5.7-M9", "2.5.7-M9") + PekkoVersion.require("PekkoVersionSpec", "2.5.7-M9", "2.5.7-M10") + PekkoVersion.require("PekkoVersionSpec", "2.5.7-M9", "2.5.8") + PekkoVersion.require("PekkoVersionSpec", "2.5.7-M9", "2.5.7-RC1") } "fail if version is milestone and not ok" in { intercept[UnsupportedPekkoVersion] { PekkoVersion.require("PekkoVersionSpec", "2.5.6", "2.5.6-M1") } + intercept[UnsupportedPekkoVersion] { + PekkoVersion.require("PekkoVersionSpec", "2.5.7-M10", "2.5.7-M9") + } + intercept[UnsupportedPekkoVersion] { + PekkoVersion.require("PekkoVersionSpec", "2.5.7-RC1", "2.5.7-M9") + } } "fail if major version is different" in { diff --git a/actor/src/main/scala/org/apache/pekko/PekkoVersion.scala b/actor/src/main/scala/org/apache/pekko/PekkoVersion.scala index c7fab1dcb2..d44c5a6d9a 100644 --- a/actor/src/main/scala/org/apache/pekko/PekkoVersion.scala +++ b/actor/src/main/scala/org/apache/pekko/PekkoVersion.scala @@ -39,20 +39,38 @@ object PekkoVersion { @InternalApi private[pekko] def require(libraryName: String, requiredVersion: String, currentVersion: String): Unit = { if (requiredVersion != currentVersion) { - val VersionPattern = """(\d+)\.(\d+)\.(\d+)(-(?:M|RC)\d+)?""".r + val VersionPattern = """(\d+)\.(\d+)\.(\d+)(?:-(M|RC)(\d+))?""".r currentVersion match { - case VersionPattern(currentMajorStr, currentMinorStr, currentPatchStr, mOrRc) => + case VersionPattern(currentMajorStr, currentMinorStr, currentPatchStr, mOrRc, mOrRcNrStr) => 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)) + case requiredVersion @ VersionPattern( + requiredMajorStr, + requiredMinorStr, + requiredPatchStr, + requiredMorRc, + requiredMOrRcNrStr) => + def throwUnsupported() = throw new UnsupportedPekkoVersion( s"Current version of Pekko is [$currentVersion], but $libraryName requires version [$requiredVersion]") + if (requiredMajorStr == currentMajorStr) { + if (requiredMinorStr == currentMinorStr) { + if (requiredPatchStr == currentPatchStr) { + if (requiredMorRc == null && mOrRc != null) + throwUnsupported() // require final but actual is M or RC + else if (requiredMorRc != null) { + (requiredMorRc, requiredMOrRcNrStr, mOrRc, mOrRcNrStr) match { + case ("M", reqN, "M", n) => if (reqN.toInt > n.toInt) throwUnsupported() + case ("M", _, "RC", _) => // RC > M, ok! + case ("RC", _, "M", _) => throwUnsupported() + case ("RC", reqN, "RC", n) => if (reqN.toInt > n.toInt) throwUnsupported() + case (_, _, null, _) => // requirement on RC or M but actual is final, ok! + case unexpected => + throw new IllegalArgumentException(s"Should never happen, comparing M/RC: $unexpected") + } + } // same versions, ok! + } else if (requiredPatchStr.toInt > currentPatchStr.toInt) throwUnsupported() + } else if (requiredMinorStr.toInt > currentMinorStr.toInt) throwUnsupported() + } else throwUnsupported() // major diff case _ => // SNAPSHOT or unknown - you're on your own } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
