Implemented general eviction warning. #1200

a> update
    [info] Updating {file:/foo/}a...
    [info] Resolving org.fusesource.jansi#jansi;1.4 ...
    [info] Done updating.
    [warn] Some dependencies were evicted:
    [warn]  * org.scala-lang:scala-library (2.10.1) -> 2.10.3
This commit is contained in:
Eugene Yokota 2014-07-18 06:17:37 -04:00
parent 5e6f0c4ff1
commit 05b97b4007
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package sbt
import collection.mutable
final class EvictionWarningOptions(
val configurations: Seq[String],
val level: Level.Value) {
}
object EvictionWarningOptions {
def apply(): EvictionWarningOptions =
new EvictionWarningOptions(Vector("compile"), Level.Warn)
}
object EvictionWarning {
def apply(options: EvictionWarningOptions, report: UpdateReport, log: Logger): Unit = {
val evictions = buildEvictions(options, report)
processEvictions(evictions, log)
}
private[sbt] def buildEvictions(options: EvictionWarningOptions, report: UpdateReport): Seq[ModuleDetailReport] = {
val buffer: mutable.ListBuffer[ModuleDetailReport] = mutable.ListBuffer()
val confs = report.configurations filter { x => options.configurations contains x.configuration }
confs flatMap { confReport =>
confReport.details map { detail =>
if ((detail.modules exists { _.evicted }) &&
!(buffer exists { x => (x.organization == detail.organization) && (x.name == detail.name) })) {
buffer += detail
}
}
}
buffer.toList.toVector
}
private[sbt] def processEvictions(evictions: Seq[ModuleDetailReport], log: Logger): Unit = {
if (!evictions.isEmpty) {
log.warn("Some dependencies were evicted:")
evictions foreach { detail =>
val revs = detail.modules filter { _.evicted } map { _.module.revision }
val winner = (detail.modules filterNot { _.evicted } map { _.module.revision }).headOption map { " -> " + _ } getOrElse ""
log.warn(s"\t* ${detail.organization}:${detail.name} (${revs.mkString(", ")})$winner")
}
}
}
}