Skip to content

Commit

Permalink
Merge pull request #428 from mdedetrich/add-allModuleReports-to-updat…
Browse files Browse the repository at this point in the history
…eReportExtra

Add allModuleReports to UpdateReport
  • Loading branch information
eed3si9n authored Sep 13, 2023
2 parents b47e081 + fd3b33b commit a363771
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/src/main/scala/sbt/librarymanagement/UpdateReportExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ private[librarymanagement] abstract class UpdateReportExtra {
def stats: UpdateStats
private[sbt] def stamps: Map[File, Long]

private[sbt] def moduleKey(m: ModuleID) = (m.organization, m.name, m.revision)

/** All resolved modules in all configurations. */
def allModules: Vector[ModuleID] = {
val key = (m: ModuleID) => (m.organization, m.name, m.revision)
configurations.flatMap(_.allModules).groupBy(key).toVector map { case (_, v) =>
configurations.flatMap(_.allModules).groupBy(moduleKey).toVector map { case (_, v) =>
v reduceLeft { (agg, x) =>
agg.withConfigurations(
(agg.configurations, x.configurations) match {
Expand All @@ -141,6 +142,21 @@ private[librarymanagement] abstract class UpdateReportExtra {
}
}

def allModuleReports: Vector[ModuleReport] = {
configurations.flatMap(_.modules).groupBy(mR => moduleKey(mR.module)).toVector map {
case (_, v) =>
v reduceLeft { (agg, x) =>
agg.withConfigurations(
(agg.configurations, x.configurations) match {
case (v, _) if v.isEmpty => x.configurations
case (ac, v) if v.isEmpty => ac
case (ac, xc) => ac ++ xc
}
)
}
}
}

def retrieve(f: (ConfigRef, ModuleID, Artifact, File) => File): UpdateReport =
UpdateReport(cachedDescriptor, configurations map { _ retrieve f }, stats, stamps)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object FakeResolverSpecification extends BaseIvySpecification {
val allFiles = getAllFiles(report)

assert(report.allModules.length == 1)
assert(report.allModuleReports.length == 1)
assert(report.configurations.length == 3)
assert(allFiles.toSet.size == 1)
assert(allFiles(1).getName == "artifact1-0.0.1-SNAPSHOT.jar")
Expand All @@ -34,6 +35,7 @@ object FakeResolverSpecification extends BaseIvySpecification {
val allFiles = getAllFiles(report).toSet

assert(report.allModules.length == 1)
assert(report.allModuleReports.length == 1)
assert(report.configurations.length == 3)
assert(allFiles.toSet.size == 2)
assert(allFiles.map(_.getName) == Set("artifact1-1.0.0.jar", "artifact2-1.0.0.txt"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ object FrozenModeSpec extends BaseIvySpecification {
val onlineResolution = update(toResolve, onlineConf)
assert(onlineResolution.isRight)
val numberResolved = onlineResolution.right.get.allModules.size
val numberReportsResolved = onlineResolution.right.get.allModuleReports.size

cleanIvyCache()
val singleFrozenResolution = update(toResolve, frozenConf)
Expand All @@ -43,6 +44,10 @@ object FrozenModeSpec extends BaseIvySpecification {
singleFrozenResolution.right.get.allModules.size == 1,
s"The number of explicit modules in frozen mode should 1"
)
assert(
singleFrozenResolution.right.get.allModuleReports.size == 1,
s"The number of explicit module reports in frozen mode should 1"
)

cleanIvyCache()
// This relies on the fact that stoml has 5 transitive dependencies
Expand All @@ -53,5 +58,9 @@ object FrozenModeSpec extends BaseIvySpecification {
frozenResolution.right.get.allModules.size == numberResolved,
s"The number of explicit modules in frozen mode should be equal than $numberResolved"
)
assert(
frozenResolution.right.get.allModuleReports.size == numberReportsResolved,
s"The number of explicit module reports in frozen mode should be equal than $numberReportsResolved"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,31 @@ object InclExclSpec extends BaseIvySpecification {
!report.allModules.exists(_.name.contains("lift-json")),
"lift-json has not been excluded."
)
assert(
!report.allModuleReports.exists(_.module.name.contains("lift-json")),
"lift-json has not been excluded."
)
}

def testScalaLibraryIsMissing(report: UpdateReport): Unit = {
assert(
!report.allModules.exists(_.name.contains("scala-library")),
"scala-library has not been excluded."
)
assert(
!report.allModuleReports.exists(_.module.name.contains("scala-library")),
"scala-library has not been excluded."
)
}

def testScalahostIsMissing(report: UpdateReport): Unit = {
assert(
!report.allModules.exists(_.name.contains("scalahost")),
"scalahost has not been excluded."
)
assert(
!report.allModuleReports.exists(_.module.name.contains("scalahost")),
"scalahost has not been excluded."
)
}
}

0 comments on commit a363771

Please sign in to comment.