Skip to content

Commit

Permalink
Merge pull request #4 from alexarchambault/develop
Browse files Browse the repository at this point in the history
Tweaking
  • Loading branch information
alexarchambault authored May 27, 2020
2 parents db9b687 + 944b4ed commit fc06eb8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
23 changes: 1 addition & 22 deletions src/main/scala/sbtcompatibility/DependencyCheckReport.scala
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -100,26 +93,12 @@ 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)
}

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)
}
}
}
16 changes: 16 additions & 0 deletions src/main/scala/sbtcompatibility/version/Version.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

}
16 changes: 16 additions & 0 deletions src/sbt-test/sbt-compatibility/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-compatibility/simple/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
> a/publishLocal
> a1/publishLocal
> b/compatibilityReportDependencyIssues
> b1/compatibilityReportDependencyIssues
> c/check
> d/check
> e/compatibilityReportDependencyIssues
8 changes: 8 additions & 0 deletions src/test/scala/sbtcompatibility/VersionsTests.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sbtcompatibility

import lmcoursier.definitions.Reconciliation
import sbtcompatibility.version.Version
import utest._

Expand All @@ -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)
}
}
}

}

0 comments on commit fc06eb8

Please sign in to comment.