From 631b5c7c7a9b531a60ee53610770a837d68381cf Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Tue, 23 May 2017 02:42:59 -0400 Subject: [PATCH] Improve the eviction warning presentation. Fixes sbt/sbt#2699 Before: [warn] There may be incompatibilities among your library dependencies. [warn] Here are some of the libraries that were evicted: [warn] * com.google.code.findbugs:jsr305:2.0.1 -> 3.0.0 [warn] Run 'evicted' to see detailed eviction warnings After: [warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible: [warn] [warn] * com.typesafe.akka:akka-actor_2.12:2.5.0 is selected over 2.4.17 [warn] +- de.heikoseeberger:akka-log4j_2.12:1.4.0 (depends on 2.5.0) [warn] +- com.typesafe.akka:akka-parsing_2.12:10.0.6 (depends on 2.4.17) [warn] +- com.typesafe.akka:akka-stream_2.12:2.4.17 () (depends on 2.4.17) [warn] [warn] Run 'evicted' to see detailed eviction warnings --- ivy/src/main/scala/sbt/EvictionWarning.scala | 38 +++++++----- ivy/src/test/scala/EvictionWarningSpec.scala | 63 ++++++++++++++------ 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/ivy/src/main/scala/sbt/EvictionWarning.scala b/ivy/src/main/scala/sbt/EvictionWarning.scala index 83360b222..b777f35cd 100644 --- a/ivy/src/main/scala/sbt/EvictionWarning.scala +++ b/ivy/src/main/scala/sbt/EvictionWarning.scala @@ -120,18 +120,24 @@ 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 winnerRev = (a.winner map { r => - val callers: String = - if (a.showCallers) - r.callers match { - case Seq() => "" - case cs => (cs map { _.caller.toString }).mkString(" (caller: ", ", ", ")") - } - else "" - r.module.revision + callers - }) map { " -> " + _ } getOrElse "" - Seq(s"\t* ${a.organization}:${a.name}:${revsStr}$winnerRev") + 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 + r.callers.toList flatMap { caller => + if (seen(caller.caller)) Nil + else { + seen += caller.caller + List(f"\t +- ${caller}%-50s (depends on $rev)") + } + } + } + val winnerRev = a.winner match { + case Some(r) => s":${r.module.revision} is selected over ${revsStr}" + case _ => " is evicted completely" + } + val title = s"\t* ${a.organization}:${a.name}$winnerRev" + title :: (if (a.showCallers) callers.reverse else Nil) ::: List("") } } @@ -227,13 +233,13 @@ object EvictionWarning { } if (a.directEvictions.nonEmpty || a.transitiveEvictions.nonEmpty) { - out += "There may be incompatibilities among your library dependencies." - out += "Here are some of the libraries that were evicted:" + out += "Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:" + out += "" out ++= (a.directEvictions flatMap { _.lines }) out ++= (a.transitiveEvictions flatMap { _.lines }) } - if (a.allEvictions.nonEmpty && a.reportedEvictions.nonEmpty && !a.options.showCallers) { + if (a.allEvictions.nonEmpty && a.reportedEvictions.nonEmpty) { out += "Run 'evicted' to see detailed eviction warnings" } @@ -254,6 +260,6 @@ object EvictionWarning { } } if (out.isEmpty) Nil - else List("Here are other libraries that were evicted:") ::: out.toList + else List("Here are other depedency conflicts that were resolved:", "") ::: out.toList } else Nil } diff --git a/ivy/src/test/scala/EvictionWarningSpec.scala b/ivy/src/test/scala/EvictionWarningSpec.scala index 80c65b211..2fe035daf 100644 --- a/ivy/src/test/scala/EvictionWarningSpec.scala +++ b/ivy/src/test/scala/EvictionWarningSpec.scala @@ -87,7 +87,8 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, defaultOptions.withShowCallers(false), report, log).lines must_== List("Scala version was updated by one of library dependencies:", - "\t* org.scala-lang:scala-library:2.10.2 -> 2.10.3", + "\t* org.scala-lang:scala-library:2.10.3 is selected over 2.10.2", + "", "To force scalaVersion, add the following:", "\tivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }", "Run 'evicted' to see detailed eviction warnings") @@ -98,9 +99,13 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, defaultOptions, report, log).lines must_== List("Scala version was updated by one of library dependencies:", - "\t* org.scala-lang:scala-library:2.10.2 -> 2.10.3 (caller: com.typesafe.akka:akka-actor_2.10:2.3.0, com.example:foo:0.1.0)", + "\t* org.scala-lang:scala-library:2.10.3 is selected over 2.10.2", + "\t +- com.typesafe.akka:akka-actor_2.10:2.3.0 (depends on 2.10.3)", + "\t +- com.example:foo:0.1.0 (depends on 2.10.2)", + "", "To force scalaVersion, add the following:", - "\tivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }") + "\tivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }", + "Run 'evicted' to see detailed eviction warnings") } def scalaVersionWarn5 = { @@ -137,18 +142,24 @@ class EvictionWarningSpec extends BaseIvySpecification { val m = module(defaultModuleId, javaLibDirectDeps, Some("2.10.3")) val report = ivyUpdate(m) EvictionWarning(m, defaultOptions, report, log).lines must_== - List("There may be incompatibilities among your library dependencies.", - "Here are some of the libraries that were evicted:", - "\t* commons-io:commons-io:1.4 -> 2.4 (caller: com.example:foo:0.1.0)") + List("Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:", + "", + "\t* commons-io:commons-io:2.4 is selected over 1.4", + "\t +- com.example:foo:0.1.0 (depends on 1.4)", + "", + "Run 'evicted' to see detailed eviction warnings") } def javaLibWarn4 = { val m = module(defaultModuleId, javaLibDirectDeps, Some("2.10.3")) val report = ivyUpdate(m) EvictionWarning(m, defaultOptions.withShowCallers(true), report, log).lines must_== - List("There may be incompatibilities among your library dependencies.", - "Here are some of the libraries that were evicted:", - "\t* commons-io:commons-io:1.4 -> 2.4 (caller: com.example:foo:0.1.0)") + List("Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:", + "", + "\t* commons-io:commons-io:2.4 is selected over 1.4", + "\t +- com.example:foo:0.1.0 (depends on 1.4)", + "", + "Run 'evicted' to see detailed eviction warnings") } def javaLibNoWarn1 = { @@ -177,9 +188,13 @@ class EvictionWarningSpec extends BaseIvySpecification { val m = module(defaultModuleId, javaLibTransitiveDeps, Some("2.10.3")) val report = ivyUpdate(m) EvictionWarning(m, defaultOptions, report, log).lines must_== - List("There may be incompatibilities among your library dependencies.", - "Here are some of the libraries that were evicted:", - "\t* commons-io:commons-io:1.4 -> 2.4 (caller: ca.gobits.bnf:bnfparser:1.0, net.databinder:unfiltered-uploads_2.10:0.8.0)") + List("Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:", + "", + "\t* commons-io:commons-io:2.4 is selected over 1.4", + "\t +- ca.gobits.bnf:bnfparser:1.0 (depends on 2.4)", + "\t +- net.databinder:unfiltered-uploads_2.10:0.8.0 (depends on 1.4)", + "", + "Run 'evicted' to see detailed eviction warnings") } def scalaLibWarn1 = { @@ -194,9 +209,12 @@ class EvictionWarningSpec extends BaseIvySpecification { val m = module(defaultModuleId, deps, Some("2.10.4")) val report = ivyUpdate(m) EvictionWarning(m, defaultOptions, report, log).lines must_== - List("There may be incompatibilities among your library dependencies.", - "Here are some of the libraries that were evicted:", - "\t* com.typesafe.akka:akka-actor_2.10:2.1.4 -> 2.3.4 (caller: com.example:foo:0.1.0)") + List("Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:", + "", + "\t* com.typesafe.akka:akka-actor_2.10:2.3.4 is selected over 2.1.4", + "\t +- com.example:foo:0.1.0 (depends on 2.1.4)", + "", + "Run 'evicted' to see detailed eviction warnings") } def scalaLibNoWarn1 = { @@ -224,9 +242,16 @@ class EvictionWarningSpec extends BaseIvySpecification { def scalaLibTransitiveWarn3 = { val m = module(defaultModuleId, scalaLibTransitiveDeps, Some("2.10.4")) val report = ivyUpdate(m) - EvictionWarning(m, defaultOptions, report, log).lines must_== - List("There may be incompatibilities among your library dependencies.", - "Here are some of the libraries that were evicted:", - "\t* com.typesafe.akka:akka-actor_2.10:2.1.4 -> 2.3.4 (caller: com.typesafe.akka:akka-remote_2.10:2.3.4, org.w3:banana-sesame_2.10:0.4, org.w3:banana-rdf_2.10:0.4)") + val actual = EvictionWarning(m, defaultOptions, report, log).lines + // println(actual.mkString("\n")) + actual must_== + List("Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:", + "", + "\t* com.typesafe.akka:akka-actor_2.10:2.3.4 is selected over 2.1.4", + "\t +- com.typesafe.akka:akka-remote_2.10:2.3.4 (depends on 2.3.4)", + "\t +- org.w3:banana-rdf_2.10:0.4 (depends on 2.1.4)", + "\t +- org.w3:banana-sesame_2.10:0.4 (depends on 2.1.4)", + "", + "Run 'evicted' to see detailed eviction warnings") } }