From c1a93c65b7d4fdc76a47679f1ebc94eb5e01c861 Mon Sep 17 00:00:00 2001 From: bigwheel Date: Thu, 10 Jan 2019 21:51:49 +0900 Subject: [PATCH 1/2] [Fix #287] Eviction warning summary shows only binary incompatible --- .../librarymanagement/EvictionWarning.scala | 28 ++++++++++++------- .../EvictionWarningSpec.scala | 18 ++++++------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala index 529353ba4..08fef77bc 100644 --- a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala +++ b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala @@ -195,7 +195,8 @@ final class EvictionWarning private[sbt] ( val scalaEvictions: Seq[EvictionPair], val directEvictions: Seq[EvictionPair], val transitiveEvictions: Seq[EvictionPair], - val allEvictions: Seq[EvictionPair] + val allEvictions: Seq[EvictionPair], + val binaryIncompatibleEvictionExists: Boolean ) { def reportedEvictions: Seq[EvictionPair] = scalaEvictions ++ directEvictions ++ transitiveEvictions @@ -279,6 +280,7 @@ object EvictionWarning { val scalaEvictions: mutable.ListBuffer[EvictionPair] = mutable.ListBuffer() val directEvictions: mutable.ListBuffer[EvictionPair] = mutable.ListBuffer() val transitiveEvictions: mutable.ListBuffer[EvictionPair] = mutable.ListBuffer() + var binaryIncompatibleEvictionExists = false def guessCompatible(p: EvictionPair): Boolean = p.evicteds forall { r => options.guessCompatible( @@ -288,18 +290,23 @@ object EvictionWarning { pairs foreach { case p if isScalaArtifact(module, p.organization, p.name) => (module.scalaModuleInfo, p.winner) match { - case (Some(s), Some(winner)) - if (s.scalaFullVersion != winner.module.revision) && options.warnScalaVersionEviction => - scalaEvictions += p + case (Some(s), Some(winner)) if (s.scalaFullVersion != winner.module.revision) => + binaryIncompatibleEvictionExists = true + if (options.warnScalaVersionEviction) + scalaEvictions += p case _ => } case p if p.includesDirect => - if (!guessCompatible(p) && options.warnDirectEvictions) { - directEvictions += p + if (!guessCompatible(p)) { + binaryIncompatibleEvictionExists = true + if (options.warnDirectEvictions) + directEvictions += p } case p => - if (!guessCompatible(p) && options.warnTransitiveEvictions) { - transitiveEvictions += p + if (!guessCompatible(p)) { + binaryIncompatibleEvictionExists = true + if (options.warnTransitiveEvictions) + transitiveEvictions += p } } new EvictionWarning( @@ -307,14 +314,15 @@ object EvictionWarning { scalaEvictions.toList, directEvictions.toList, transitiveEvictions.toList, - pairs + pairs, + binaryIncompatibleEvictionExists ) } implicit val evictionWarningLines: ShowLines[EvictionWarning] = ShowLines { a: EvictionWarning => import ShowLines._ val out: mutable.ListBuffer[String] = mutable.ListBuffer() - if ((a.options.warnEvictionSummary || a.reportedEvictions.nonEmpty) && a.allEvictions.nonEmpty) { + if (a.options.warnEvictionSummary && a.binaryIncompatibleEvictionExists) { out += "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings." } diff --git a/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala b/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala index d22ea557b..106a0e87f 100644 --- a/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala +++ b/ivy/src/test/scala/sbt/internal/librarymanagement/EvictionWarningSpec.scala @@ -27,7 +27,7 @@ class EvictionWarningSpec extends BaseIvySpecification { """Including two (suspect) binary compatible Java libraries to direct dependencies """ should "not be detected as eviction" in javaLibNoWarn1() - it should "print out message about the eviction" in javaLibNoWarn2() + it should "not print out message about the eviction" in javaLibNoWarn2() """Including two (suspect) transitively binary incompatible Java libraries to direct dependencies """ should "be detected as eviction" in javaLibTransitiveWarn2() @@ -41,7 +41,8 @@ class EvictionWarningSpec extends BaseIvySpecification { """Including two (suspect) binary compatible Scala libraries to direct dependencies """ should "not be detected as eviction" in scalaLibNoWarn1() - it should "print out message about the eviction" in scalaLibNoWarn2() + it should "not print out message about the eviction" in scalaLibNoWarn2() + it should "not print out summary about the eviction even if warn eviction summary enabled" in scalaLibNoWarn3() """Including two (suspect) transitively binary incompatible Scala libraries to direct dependencies """ should "be detected as eviction" in scalaLibTransitiveWarn2() @@ -111,7 +112,6 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, fullOptions.withShowCallers(false), report).lines shouldBe List( - "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.", "Scala version was updated by one of library dependencies:", "\t* org.scala-lang:scala-library:2.10.3 is selected over 2.10.2", "", @@ -125,7 +125,6 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, fullOptions, report).lines shouldBe List( - "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.", "Scala version was updated by one of library dependencies:", "\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)", @@ -182,7 +181,6 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, fullOptions, report).lines shouldBe List( - "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.", "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", @@ -196,7 +194,6 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, fullOptions.withShowCallers(true), report).lines shouldBe List( - "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.", "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", @@ -260,7 +257,6 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, fullOptions, report).lines shouldBe List( - "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.", "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", @@ -293,6 +289,13 @@ class EvictionWarningSpec extends BaseIvySpecification { EvictionWarning(m, fullOptions, report).lines shouldBe Nil } + def scalaLibNoWarn3() = { + val deps = Vector(scala2104, akkaActor230, akkaActor234) + val m = module(defaultModuleId, deps, Some("2.10.4")) + val report = ivyUpdate(m) + EvictionWarning(m, EvictionWarningOptions.summary, report).lines shouldBe Nil + } + def scalaLibTransitiveDeps = Vector(scala2104, bananaSesame04, akkaRemote234) def scalaLibTransitiveWarn2() = { @@ -306,7 +309,6 @@ class EvictionWarningSpec extends BaseIvySpecification { val report = ivyUpdate(m) EvictionWarning(m, fullOptions, report).lines shouldBe List( - "There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.", "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", From 8d4f6cee48e7002dfa3f8158234f444f7bae8f30 Mon Sep 17 00:00:00 2001 From: bigwheel Date: Mon, 14 Jan 2019 19:02:41 +0900 Subject: [PATCH 2/2] [Fix #287] Add alternative constructor for binary compatibility --- .../sbt/librarymanagement/EvictionWarning.scala | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala index 08fef77bc..04da1a4c6 100644 --- a/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala +++ b/core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala @@ -198,6 +198,13 @@ final class EvictionWarning private[sbt] ( val allEvictions: Seq[EvictionPair], val binaryIncompatibleEvictionExists: Boolean ) { + private[sbt] def this( + options: EvictionWarningOptions, + scalaEvictions: Seq[EvictionPair], + directEvictions: Seq[EvictionPair], + transitiveEvictions: Seq[EvictionPair], + allEvictions: Seq[EvictionPair] + ) = this(options, scalaEvictions, directEvictions, transitiveEvictions, allEvictions, false) def reportedEvictions: Seq[EvictionPair] = scalaEvictions ++ directEvictions ++ transitiveEvictions private[sbt] def infoAllTheThings: List[String] = EvictionWarning.infoAllTheThings(this) @@ -291,22 +298,25 @@ object EvictionWarning { case p if isScalaArtifact(module, p.organization, p.name) => (module.scalaModuleInfo, p.winner) match { case (Some(s), Some(winner)) if (s.scalaFullVersion != winner.module.revision) => - binaryIncompatibleEvictionExists = true if (options.warnScalaVersionEviction) scalaEvictions += p + if (options.warnEvictionSummary) + binaryIncompatibleEvictionExists = true case _ => } case p if p.includesDirect => if (!guessCompatible(p)) { - binaryIncompatibleEvictionExists = true if (options.warnDirectEvictions) directEvictions += p + if (options.warnEvictionSummary) + binaryIncompatibleEvictionExists = true } case p => if (!guessCompatible(p)) { - binaryIncompatibleEvictionExists = true if (options.warnTransitiveEvictions) transitiveEvictions += p + if (options.warnEvictionSummary) + binaryIncompatibleEvictionExists = true } } new EvictionWarning(