Skip to content

Commit 5c05663

Browse files
committed
feat(evaluator): Allow to evaluate license sources together
While it is valuable to be able to evaluate the license rule seperately per license source, some users do desire to evaluate only once per license for all source. Introduce a toggle, which allows for that while keeping the old behavior as default. Signed-off-by: Frank Viernau <frank.viernau@gmail.com>
1 parent 4863f11 commit 5c05663

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

evaluator/src/main/kotlin/PackageRule.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,25 @@ open class PackageRule(
202202
/**
203203
* A DSL function to configure a [LicenseRule] and add it to this rule.
204204
*/
205-
fun licenseRule(name: String, licenseView: LicenseView, block: LicenseRule.() -> Unit) {
206-
resolvedLicenseInfo.filter(licenseView, filterSources = true)
205+
fun licenseRule(
206+
name: String,
207+
licenseView: LicenseView,
208+
separateEvaluationPerSource: Boolean = true,
209+
block: LicenseRule.() -> Unit
210+
) {
211+
val effectiveResolveLicenseInfo = resolvedLicenseInfo.filter(licenseView, filterSources = true)
207212
.applyChoices(ruleSet.ortResult.getPackageLicenseChoices(pkg.metadata.id), licenseView)
208-
.applyChoices(ruleSet.ortResult.getRepositoryLicenseChoices(), licenseView).forEach { resolvedLicense ->
213+
.applyChoices(ruleSet.ortResult.getRepositoryLicenseChoices(), licenseView)
214+
215+
effectiveResolveLicenseInfo.forEach { resolvedLicense ->
216+
if (separateEvaluationPerSource) {
209217
resolvedLicense.sources.forEach { licenseSource ->
210218
licenseRules += LicenseRule(name, resolvedLicense, setOf(licenseSource)).apply(block)
211219
}
220+
} else {
221+
licenseRules += LicenseRule(name, resolvedLicense, resolvedLicense.sources).apply(block)
212222
}
223+
}
213224
}
214225

215226
fun issue(severity: Severity, message: String, howToFix: String) =

0 commit comments

Comments
 (0)