Skip to content

Commit

Permalink
Merge pull request #3 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 ffd2d2a + a8aae41 commit db9b687
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
26 changes: 19 additions & 7 deletions src/main/scala/sbtcompatibility/DependencyCheckReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,34 @@ import scala.collection.mutable
(!direction.backward || backwardStatuses.forall(_._2.validated)) &&
(!direction.forward || forwardStatuses.forall(_._2.validated))

def errors(direction: Direction): Seq[String] = {
def errors(direction: Direction, ignored: Set[(String, String)] = Set.empty): (Seq[String], Seq[String]) = {

val backwardElems =
if (direction.backward) backwardStatuses else Map()
val forwardElems =
if (direction.forward) forwardStatuses else Map()

(backwardElems.iterator.map((_, true)) ++ forwardElems.iterator.map((_, false)))
val baseErrors = (backwardElems.iterator.map((_, true)) ++ forwardElems.iterator.map((_, false)))
.filter(!_._1._2.validated)
.toVector
.sortBy(_._1._1)
.collect {
case (((org, name), status), backward) =>
val direction = if (backward) "backward" else "forward"
s"$org:$name ($direction): ${status.message}"
}

def message(org: String, name: String, backward: Boolean, status: DependencyCheckReport.ModuleStatus): String = {
val direction = if (backward) "backward" else "forward"
s"$org:$name ($direction): ${status.message}"
}

val actualErrors = baseErrors.collect {
case ((orgName @ (org, name), status), backward) if !ignored(orgName) =>
message(org, name, backward, status)
}

val warnings = baseErrors.collect {
case ((orgName @ (org, name), status), backward) if ignored(orgName) =>
message(org, name, backward, status)
}

(warnings, actualErrors)
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/sbtcompatibility/SbtCompatibilityKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import lmcoursier.CoursierConfiguration
import lmcoursier.definitions.Reconciliation
import sbt._
import sbt.librarymanagement.{DependencyResolution, ScalaModuleInfo, UpdateConfiguration, UnresolvedWarningConfiguration}
import sbt.librarymanagement.DependencyBuilders.OrganizationArtifactName

trait SbtCompatibilityKeys {
final val compatibilityPreviousArtifacts = taskKey[Seq[ModuleID]]("")
final val compatibilityReportDependencyIssues = taskKey[Unit]("")
final val compatibilityCheck = taskKey[Unit]("Runs both compatibilityReportDependencyIssues and mimaReportBinaryIssues")

final val compatibilityReconciliations = taskKey[Seq[ModuleID]]("")
final val compatibilityIgnored = taskKey[Seq[OrganizationArtifactName]]("")
final val compatibilityDetailedReconciliations = taskKey[Seq[(lmcoursier.definitions.ModuleMatchers, Reconciliation)]]("")
final val compatibilityCheckDirection = taskKey[Direction]("")

Expand Down
21 changes: 18 additions & 3 deletions src/main/scala/sbtcompatibility/SbtCompatibilitySettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ object SbtCompatibilitySettings {

def updateSettings = Def.settings(
compatibilityCsrConfiguration := csrConfiguration.value
// TODO Make that a method on CoursierConfiguration
.withInterProjectDependencies(Vector.empty)
.withFallbackDependencies(Vector.empty)
.withSbtScalaOrganization(None)
.withSbtScalaVersion(None)
.withSbtScalaJars(Vector.empty)
.withExcludeDependencies(Vector.empty),
.withExcludeDependencies(Vector.empty)
.withForceVersions(Vector.empty)
.withReconciliation(Vector.empty),
compatibilityDependencyResolution := CoursierDependencyResolution(compatibilityCsrConfiguration.value),
compatibilityUpdateConfiguration := updateConfiguration.value,
compatibilityUnresolvedWarningConfiguration := unresolvedWarningConfiguration.in(update).value,
Expand All @@ -34,6 +38,7 @@ object SbtCompatibilitySettings {
compatibilityIgnoreSbtDefaultReconciliations := true,
compatibilityUseCsrConfigReconciliations := true,
compatibilityReconciliations := Seq.empty,
compatibilityIgnored := Seq.empty,
compatibilityDetailedReconciliations := {
val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value
Expand Down Expand Up @@ -93,7 +98,7 @@ object SbtCompatibilitySettings {
val warningConfig = compatibilityUnresolvedWarningConfiguration.value

val reconciliations = {
val csrConfig = compatibilityCsrConfiguration.value
val csrConfig = csrConfiguration.value
val useCsrConfigReconciliations = compatibilityUseCsrConfigReconciliations.value
val ignoreSbtDefaultReconciliations = compatibilityIgnoreSbtDefaultReconciliations.value

Expand Down Expand Up @@ -140,15 +145,25 @@ object SbtCompatibilitySettings {
},
compatibilityReportDependencyIssues := {
val log = streams.value.log
val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value
val direction = compatibilityCheckDirection.value
val reports = compatibilityFindDependencyIssues.value

if (reports.isEmpty)
log.warn(s"No dependency check reports found (empty compatibilityPreviousArtifacts?).")

val ignored = compatibilityIgnored.value
.map { orgName =>
val mod = orgName % "foo"
val name = CrossVersion(mod.crossVersion, sv, sbv).fold(mod.name)(_(mod.name))
(mod.organization, name)
}
.toSet

var anyError = false
for ((previousModule, report) <- reports) {
val errors = report.errors(direction)
val (warnings, errors) = report.errors(direction, ignored)
if (errors.nonEmpty) {
anyError = true
log.error(s"Incompatibilities with $previousModule")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ object DependencyCheck {
.filter(!_.evicted)
.map(_.module)
.map { mod =>
val version = CrossVersion(mod.crossVersion, scalaVersion, scalaBinaryVersion)
.fold(mod.revision)(_(mod.revision))
val name = CrossVersion(mod.crossVersion, scalaVersion, scalaBinaryVersion)
.fold(mod.name)(_(mod.name))
// TODO Check mod.explicitArtifacts too?
(mod.organization, mod.name) -> version
(mod.organization, name) -> mod.revision
}
.groupBy(_._1)
.map {
Expand Down
14 changes: 14 additions & 0 deletions src/sbt-test/sbt-compatibility/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ lazy val d = project
version := "0.1.1"
)

lazy val e = project
.settings(
shared,
name := "simple-test",
libraryDependencies ++= Seq(
"io.get-coursier" %% "coursier" % "2.0.0-RC6-18" % Provided
),
compatibilityIgnored ++= Seq(
"com.chuusai" %% "shapeless",
"org.typelevel" %% "macro-compat"
),
version := "0.1.1"
)

inThisBuild(List(
scalaVersion := "2.12.11",
organization := "io.github.alexarchambault.sbtcompatibility.test",
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/sbt-compatibility/simple/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
> b/compatibilityReportDependencyIssues
> c/check
> d/check
> e/compatibilityReportDependencyIssues

0 comments on commit db9b687

Please sign in to comment.