diff --git a/src/main/scala/sbtcompatibility/DependencyCheckReport.scala b/src/main/scala/sbtcompatibility/DependencyCheckReport.scala index 9091148..6549634 100644 --- a/src/main/scala/sbtcompatibility/DependencyCheckReport.scala +++ b/src/main/scala/sbtcompatibility/DependencyCheckReport.scala @@ -1,16 +1,9 @@ package sbtcompatibility -import java.util.regex.Pattern - import dataclass.data import lmcoursier.definitions._ -import lmcoursier.definitions.Reconciliation.Default -import lmcoursier.definitions.Reconciliation.Relaxed -import lmcoursier.definitions.Reconciliation.SemVer import sbtcompatibility.version.Version -import scala.collection.mutable - @data class DependencyCheckReport( backwardStatuses: Map[(String, String), DependencyCheckReport.ModuleStatus], forwardStatuses: Map[(String, String), DependencyCheckReport.ModuleStatus] @@ -100,7 +93,7 @@ object DependencyCheckReport { rec } .getOrElse(defaultReconciliation) - if (compatible(reconciliation, ver, currentVersion)) + if (Version.compatible(reconciliation, ver, currentVersion)) CompatibleVersion(currentVersion, ver, reconciliation) else IncompatibleVersion(currentVersion, ver, reconciliation) @@ -108,18 +101,4 @@ object DependencyCheckReport { orgName -> status } - - private def compatible(reconciliation: Reconciliation, version: String, otherVersion: String): Boolean = - reconciliation match { - case lmcoursier.definitions.Reconciliation.Strict => version == otherVersion - case Relaxed => true - case Default | SemVer => - version == otherVersion || { - val comparisonOpt = for { - prefix0 <- Version.prefix(version) - otherPrefix <- Version.prefix(otherVersion) - } yield prefix0 == otherPrefix - comparisonOpt.exists(identity) - } - } } diff --git a/src/main/scala/sbtcompatibility/version/Version.scala b/src/main/scala/sbtcompatibility/version/Version.scala index 0b2812f..df33cd2 100644 --- a/src/main/scala/sbtcompatibility/version/Version.scala +++ b/src/main/scala/sbtcompatibility/version/Version.scala @@ -2,6 +2,8 @@ package sbtcompatibility.version import java.util.regex.Pattern +import lmcoursier.definitions.Reconciliation + object Version { private val tagPattern = "-[A-Za-z]".r @@ -40,4 +42,18 @@ object Version { Some((majStr.toInt, minStr.toInt)) } + def compatible(reconciliation: Reconciliation, version: String, otherVersion: String): Boolean = + reconciliation match { + case lmcoursier.definitions.Reconciliation.Strict => version == otherVersion + case Reconciliation.Relaxed => true + case Reconciliation.Default | Reconciliation.SemVer => + version == otherVersion || { + val comparisonOpt = for { + prefix0 <- Version.prefix(version.takeWhile(_ != '+')) + otherPrefix <- Version.prefix(otherVersion.takeWhile(_ != '+')) + } yield prefix0 == otherPrefix + comparisonOpt.exists(identity) + } + } + } diff --git a/src/sbt-test/sbt-compatibility/simple/build.sbt b/src/sbt-test/sbt-compatibility/simple/build.sbt index b14a01d..1fbfe80 100644 --- a/src/sbt-test/sbt-compatibility/simple/build.sbt +++ b/src/sbt-test/sbt-compatibility/simple/build.sbt @@ -8,6 +8,14 @@ lazy val a = project version := "0.1.0" ) +lazy val a1 = project + .dependsOn(a) + .settings( + shared, + name := "simple-test-foo", + version := "0.1.0" + ) + lazy val b = project .settings( shared, @@ -18,6 +26,14 @@ lazy val b = project version := "0.1.1" ) +lazy val b1 = project + .dependsOn(b) + .settings( + shared, + name := "simple-test-foo", + version := "0.1.1" + ) + lazy val c = project .settings( shared, diff --git a/src/sbt-test/sbt-compatibility/simple/test b/src/sbt-test/sbt-compatibility/simple/test index 387c62c..4b646b1 100644 --- a/src/sbt-test/sbt-compatibility/simple/test +++ b/src/sbt-test/sbt-compatibility/simple/test @@ -1,5 +1,7 @@ > a/publishLocal +> a1/publishLocal > b/compatibilityReportDependencyIssues +> b1/compatibilityReportDependencyIssues > c/check > d/check > e/compatibilityReportDependencyIssues diff --git a/src/test/scala/sbtcompatibility/VersionsTests.scala b/src/test/scala/sbtcompatibility/VersionsTests.scala index dd45768..32cd213 100644 --- a/src/test/scala/sbtcompatibility/VersionsTests.scala +++ b/src/test/scala/sbtcompatibility/VersionsTests.scala @@ -1,5 +1,6 @@ package sbtcompatibility +import lmcoursier.definitions.Reconciliation import sbtcompatibility.version.Version import utest._ @@ -24,6 +25,13 @@ object VersionsTests extends TestSuite { * - checkEmpty("1.0-RC2") * - checkEmpty("1.0-RC2+43") } + + "compatible" - { + * - { + val compatible = Version.compatible(Reconciliation.SemVer, "0.1.0", "0.1.0+foo") + assert(compatible) + } + } } }