From fdb519b9e2a7aca05b72786ef29b8c4778b89659 Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Sat, 16 Sep 2023 13:09:07 +0100 Subject: [PATCH] Avoid repeating versions in Eviction warning message As with https://github.com/sbt/librarymanagement/pull/386, which dealt with Eviction *errors*, this fixes the way Eviction *warnings* report the list of evicted versions - removing duplicate versions - and does a refactor so that both `EvictionError` & `EvictionWarning` are using the same logic to generate the revision string. The logic for the revisions string is moved to the new field `EvictionPair.evictedRevs`. Without this fix, we see Eviction warnings like this: ``` * org.scala-lang.modules:scala-java8-compat_2.13:1.0.2 is selected over {1.0.0, 1.0.0} ``` --- .../main/scala/sbt/librarymanagement/EvictionError.scala | 5 +---- .../scala/sbt/librarymanagement/EvictionWarning.scala | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/scala/sbt/librarymanagement/EvictionError.scala b/core/src/main/scala/sbt/librarymanagement/EvictionError.scala index 3e73e37c..3662127b 100644 --- a/core/src/main/scala/sbt/librarymanagement/EvictionError.scala +++ b/core/src/main/scala/sbt/librarymanagement/EvictionError.scala @@ -158,9 +158,6 @@ final class EvictionError private[sbt] ( out += "found version conflict(s) in library dependencies; some are suspected to be binary incompatible:" out += "" evictions.foreach({ case (a, scheme) => - val revs = a.evicteds map { _.module.revision } - val revsStr = - if (revs.size <= 1) revs.mkString else "{" + revs.distinct.mkString(", ") + "}" val seen: mutable.Set[ModuleID] = mutable.Set() val callers: List[String] = (a.evicteds.toList ::: a.winner.toList) flatMap { r => val rev = r.module.revision @@ -174,7 +171,7 @@ final class EvictionError private[sbt] ( } val que = if (assumed) "?" else "" val winnerRev = a.winner match { - case Some(r) => s":${r.module.revision} ($scheme$que) is selected over ${revsStr}" + case Some(r) => s":${r.module.revision} ($scheme$que) is selected over ${a.evictedRevs}" case _ => " is evicted for all versions" } val title = s"\t* ${a.organization}:${a.name}$winnerRev" diff --git a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala index df70eeff..a7179c30 100644 --- a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala +++ b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala @@ -191,6 +191,11 @@ final class EvictionPair private[sbt] ( val includesDirect: Boolean, val showCallers: Boolean ) { + val evictedRevs: String = { + val revs = evicteds map { _.module.revision } + if (revs.size <= 1) revs.mkString else revs.distinct.mkString("{", ", ", "}") + } + override def toString: String = EvictionPair.evictionPairLines.showLines(this).mkString override def equals(o: Any): Boolean = o match { @@ -209,8 +214,6 @@ final class EvictionPair private[sbt] ( object EvictionPair { implicit val evictionPairLines: ShowLines[EvictionPair] = ShowLines { (a: EvictionPair) => - val revs = a.evicteds map { _.module.revision } - val revsStr = if (revs.size <= 1) revs.mkString else "{" + revs.mkString(", ") + "}" val seen: mutable.Set[ModuleID] = mutable.Set() val callers: List[String] = (a.evicteds.toList ::: a.winner.toList) flatMap { r => val rev = r.module.revision @@ -223,7 +226,7 @@ object EvictionPair { } } val winnerRev = a.winner match { - case Some(r) => s":${r.module.revision} is selected over ${revsStr}" + case Some(r) => s":${r.module.revision} is selected over ${a.evictedRevs}" case _ => " is evicted for all versions" } val title = s"\t* ${a.organization}:${a.name}$winnerRev"