Skip to content

Commit 74f8178

Browse files
fviernautsteenbe
authored andcommitted
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 4daf896 commit 74f8178

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
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 effectiveResolvedLicenseInfo = 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+
effectiveResolvedLicenseInfo.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) =

evaluator/src/main/kotlin/Rule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ abstract class Rule(
123123

124124
/**
125125
* Add an issue of the given [severity] for [pkgId] to the list of violations. Optionally, the offending [license]
126-
* and its [source][licenseSource] can be specified. The [message] further explains the violation itself and
126+
* and its [sources][licenseSources] can be specified. The [message] further explains the violation itself and
127127
* [howToFix] explains how it can be fixed.
128128
*/
129129
fun issue(

0 commit comments

Comments
 (0)