Skip to content

Commit 82617f5

Browse files
authored
Fix filtering of licenseConfigurations (#141)
With the changes of #86, the filtering of configurations broke and test dependencies got reported even though licenseConfigurations was set to Set("compile"). This is due to the fact that the resolved Ivy deps not properly mirror the configurations the dependency was defined for. By selecting the configurations from the report early on, we restore the filtering.
1 parent 79a0a3d commit 82617f5

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/main/scala/sbtlicensereport/license/LicenseReport.scala

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,32 @@ object LicenseReport {
316316
}
317317
}
318318

319+
// TODO: Remove when https://github.com/sbt/librarymanagement/pull/547 is merged so we can properly filter
320+
private def moduleKey(m: ModuleID) = (m.organization, m.name, m.revision)
321+
322+
private def allModuleReports(configurations: Vector[ConfigurationReport]): Vector[ModuleReport] =
323+
configurations.flatMap(_.modules).groupBy(mR => moduleKey(mR.module)).toVector map { case (_, v) =>
324+
v reduceLeft { (agg, x) =>
325+
agg.withConfigurations(
326+
(agg.configurations, x.configurations) match {
327+
case (v, _) if v.isEmpty => x.configurations
328+
case (ac, v) if v.isEmpty => ac
329+
case (ac, xc) => ac ++ xc
330+
}
331+
)
332+
}
333+
}
334+
319335
private def getLicenses(
320336
report: UpdateReport,
321-
configs: Set[String] = Set.empty,
322-
categories: Seq[LicenseCategory] = LicenseCategory.all,
337+
configs: Set[String],
338+
categories: Seq[LicenseCategory],
323339
originatingModule: DepModuleInfo,
324340
log: Logger
325341
): Seq[DepLicense] = {
342+
val relevantConfigurations = report.configurations.filter(c => configs.contains(c.configuration.name))
326343
for {
327-
dep <- report.allModuleReports
344+
dep <- allModuleReports(relevantConfigurations)
328345
report <- pickLicenseForDep(dep, configs, categories, originatingModule, log)
329346
} yield report
330347
}

0 commit comments

Comments
 (0)