Add evicted stuff to update report

Should make evicted work fine from sbt-lm-coursier and sbt itself
This commit is contained in:
Alexandre Archambault 2019-06-19 17:13:44 +02:00
parent 7bf70bce97
commit 8185c94b1c
5 changed files with 102 additions and 2 deletions

View File

@ -262,10 +262,42 @@ private[internal] object SbtUpdateReport {
} else
reports.toVector
val details = reports0.map { rep =>
val mainReportDetails = reports0.map { rep =>
OrganizationArtifactReport(rep.module.organization, rep.module.name, Vector(rep))
}
val evicted = coursier.graph.Conflict(subRes).flatMap { c =>
// FIXME The project for c.wantedVersion is possibly not around (it's likely it was just not fetched)
val projOpt = subRes.projectCache.get((c.module, c.wantedVersion))
.orElse(subRes.projectCache.get((c.module, c.version)))
projOpt.toSeq.map {
case (_, proj) =>
// likely misses some details (transitive, exclusions, )
val dep = Dependency(c.module, c.wantedVersion)
val dependee = Dependency(c.dependeeModule, c.dependeeVersion)
val dependeeProj = subRes.projectCache
.get((c.dependeeModule, c.dependeeVersion))
.map(_._2)
.getOrElse {
// should not happen
Project(c.dependeeModule, c.dependeeVersion, Nil, Map(), None, Nil, Nil, Nil, None, None, None, false, None, Nil, coursier.core.Info.empty)
}
val rep = moduleReport((dep, Seq((dependee, dependeeProj)), proj.copy(version = c.wantedVersion), Nil))
.withEvicted(true)
.withEvictedData(Some("version selection")) // ??? put latest-revision like sbt/ivy here?
OrganizationArtifactReport(c.module.organization.value, c.module.name.value, Vector(rep))
}
}
val details = (mainReportDetails ++ evicted)
.groupBy(r => (r.organization, r.name))
.toVector // order?
.map {
case ((org, name), l) =>
val modules = l.flatMap(_.modules)
OrganizationArtifactReport(org, name, modules)
}
ConfigurationReport(
ConfigRef(config.value),
reports0,

View File

@ -0,0 +1,47 @@
// examples adapted from https://github.com/coursier/sbt-coursier/pull/75#issuecomment-497128870
lazy val a = project
.settings(
scalaVersion := "2.11.8",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect" % "1.3.1",
"org.typelevel" %% "cats-core" % "1.5.0"
)
)
lazy val b = project
.settings(
scalaVersion := "2.11.8",
libraryDependencies ++= Seq(
"org.slf4s" %% "slf4s-api" % "1.7.12", // depends on org.slf4j:slf4j-api:1.7.12
"ch.qos.logback" % "logback-classic" % "1.1.2" // depends on org.slf4j:slf4j-api:1.7.6
)
)
lazy val check = taskKey[Unit]("")
check := {
val aReport = update.in(a).value
val bReport = update.in(b).value
def doCheck(report: UpdateReport): Unit = {
val compileReport = report
.configurations
.find(_.configuration.name == "compile")
.getOrElse {
sys.error("compile report not found")
}
val foundEvictions = compileReport.details.exists(_.modules.exists(_.evicted))
if (!foundEvictions)
compileReport.details.foreach(println)
assert(foundEvictions)
}
// needs https://github.com/coursier/coursier/pull/1217
// doCheck(aReport)
doCheck(bReport)
}

View File

@ -0,0 +1,13 @@
addSbtPlugin {
val name = sys.props.getOrElse(
"plugin.name",
sys.error("plugin.name Java property not set")
)
val version = sys.props.getOrElse(
"plugin.version",
sys.error("plugin.version Java property not set")
)
"io.get-coursier" % name % version
}

View File

@ -0,0 +1,2 @@
> evicted
> check

View File

@ -14,13 +14,19 @@ sbtShading() {
}
runLmCoursierTests() {
if [ "$TEST_GROUP" = 1 ]; then
SCRIPTED_EXTRA="sbt-lm-coursier/*"
else
SCRIPTED_EXTRA=""
fi
# publishing locally to ensure shading runs fine
./metadata/scripts/with-test-repo.sh sbt \
++$TRAVIS_SCALA_VERSION! \
mimaReportBinaryIssues \
lm-coursier-shaded/publishLocal \
lm-coursier/test \
"sbt-lm-coursier/scripted shared-$TEST_GROUP/*"
"sbt-lm-coursier/scripted shared-$TEST_GROUP/* $SCRIPTED_EXTRA"
}
runSbtCoursierTests() {