Merge pull request #428 from mdedetrich/add-allModuleReports-to-updateReportExtra

Add allModuleReports to UpdateReport
This commit is contained in:
eugene yokota 2023-09-13 10:07:52 -04:00 committed by GitHub
commit a3637713eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 2 deletions

View File

@ -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 {
@ -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)

View File

@ -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")
@ -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"))

View File

@ -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)
@ -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
@ -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"
)
}
}

View File

@ -68,6 +68,10 @@ 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 = {
@ -75,6 +79,10 @@ object InclExclSpec extends BaseIvySpecification {
!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 = {
@ -82,5 +90,9 @@ object InclExclSpec extends BaseIvySpecification {
!report.allModules.exists(_.name.contains("scalahost")),
"scalahost has not been excluded."
)
assert(
!report.allModuleReports.exists(_.module.name.contains("scalahost")),
"scalahost has not been excluded."
)
}
}