Skip to content

Commit 0de8f66

Browse files
committed
refactor(evaluator)!: Turn licenseSource of violations to a Set
Prepare for an upcoming change. Signed-off-by: Frank Viernau <frank.viernau@gmail.com>
1 parent df3e954 commit 0de8f66

File tree

10 files changed

+18
-21
lines changed

10 files changed

+18
-21
lines changed

evaluator/src/main/kotlin/Rule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ abstract class Rule(
139139
rule = name,
140140
pkg = pkgId,
141141
license = license,
142-
licenseSource = licenseSource,
142+
licenseSources = setOfNotNull(licenseSource),
143143
message = message,
144144
howToFix = howToFix
145145
)

evaluator/src/test/kotlin/EvaluatorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class EvaluatorTest : WordSpec({
102102
rule shouldBe "rule 1"
103103
pkg shouldBe Identifier("type:namespace:name:1.0")
104104
license shouldBe "license-1".toSpdx()
105-
licenseSource shouldBe LicenseSource.DETECTED
105+
licenseSources should containExactlyInAnyOrder(LicenseSource.DETECTED)
106106
severity shouldBe Severity.ERROR
107107
message shouldBe "message 1"
108108
howToFix shouldBe "how to fix 1"
@@ -112,7 +112,7 @@ class EvaluatorTest : WordSpec({
112112
rule shouldBe "rule 2"
113113
pkg shouldBe Identifier("type:namespace:name:2.0")
114114
license shouldBe "license-2".toSpdx()
115-
licenseSource shouldBe LicenseSource.DECLARED
115+
licenseSources should containExactlyInAnyOrder(LicenseSource.DECLARED)
116116
severity shouldBe Severity.WARNING
117117
message shouldBe "message 2"
118118
howToFix shouldBe "how to fix 2"

evaluator/src/test/kotlin/RuleTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.ossreviewtoolkit.evaluator
2121

2222
import io.kotest.core.spec.style.WordSpec
23+
import io.kotest.matchers.collections.containExactlyInAnyOrder
2324
import io.kotest.matchers.collections.haveSize
2425
import io.kotest.matchers.should
2526
import io.kotest.matchers.shouldBe
@@ -55,7 +56,7 @@ class RuleTest : WordSpec() {
5556
violation.rule shouldBe rule.name
5657
violation.pkg shouldBe id
5758
violation.license shouldBe license
58-
violation.licenseSource shouldBe licenseSource
59+
violation.licenseSources should containExactlyInAnyOrder(licenseSource)
5960
violation.severity shouldBe Severity.HINT
6061
violation.message shouldBe message
6162
violation.howToFix shouldBe howToFix
@@ -74,7 +75,7 @@ class RuleTest : WordSpec() {
7475
violation.rule shouldBe rule.name
7576
violation.pkg shouldBe id
7677
violation.license shouldBe license
77-
violation.licenseSource shouldBe licenseSource
78+
violation.licenseSources should containExactlyInAnyOrder(licenseSource)
7879
violation.severity shouldBe Severity.WARNING
7980
violation.message shouldBe message
8081
violation.howToFix shouldBe howToFix
@@ -93,7 +94,7 @@ class RuleTest : WordSpec() {
9394
violation.rule shouldBe rule.name
9495
violation.pkg shouldBe id
9596
violation.license shouldBe license
96-
violation.licenseSource shouldBe licenseSource
97+
violation.licenseSources should containExactlyInAnyOrder(licenseSource)
9798
violation.severity shouldBe Severity.ERROR
9899
violation.message shouldBe message
99100
violation.howToFix shouldBe howToFix

model/src/main/kotlin/RuleViolation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ data class RuleViolation(
3838
val license: SpdxSingleLicenseExpression?,
3939

4040
/**
41-
* The [source][LicenseSource] of the [license]. Can be null if the rule does not work on licenses.
41+
* The [license sources][licenseSources] of the [license]. Can be empty if the rule does not work on licenses.
4242
*/
43-
val licenseSource: LicenseSource?,
43+
val licenseSources: Set<LicenseSource>,
4444

4545
/**
4646
* The severity of the rule violation.

model/src/test/kotlin/OrtResultTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class OrtResultTest : WordSpec({
512512
rule = "rule id",
513513
pkg = Identifier("Maven", "org.ossreviewtoolkit", "resolved-violation", "0.8.15"),
514514
license = null,
515-
licenseSource = null,
515+
licenseSources = emptySet(),
516516
severity = Severity.HINT,
517517
message = "Rule violation message to resolve",
518518
howToFix = ""
@@ -534,7 +534,7 @@ class OrtResultTest : WordSpec({
534534
rule = "Resolved rule violation",
535535
pkg = Identifier("Maven", "org.ossreviewtoolkit", "resolved-violation", "0.8.15"),
536536
license = null,
537-
licenseSource = null,
537+
licenseSources = emptySet(),
538538
severity = Severity.ERROR,
539539
message = "Rule violation message to resolve",
540540
howToFix = ""
@@ -543,7 +543,7 @@ class OrtResultTest : WordSpec({
543543
rule = "Rule violation without resolution",
544544
pkg = Identifier("Maven", "com.example", "package-without-resolution", "1.0.0"),
545545
license = null,
546-
licenseSource = null,
546+
licenseSources = emptySet(),
547547
severity = Severity.WARNING,
548548
message = "Message without any resolution",
549549
howToFix = ""
@@ -552,7 +552,7 @@ class OrtResultTest : WordSpec({
552552
rule = "Rule violation below minSeverity",
553553
pkg = Identifier("Maven", "com.example", "violation-below-threshold", "3.14"),
554554
license = null,
555-
licenseSource = null,
555+
licenseSources = emptySet(),
556556
severity = Severity.HINT,
557557
message = "Message without any resolution",
558558
howToFix = ""

model/src/test/kotlin/config/RuleViolationResolutionTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private fun ruleViolation(message: String) =
6666
rule = "",
6767
pkg = null,
6868
license = null,
69-
licenseSource = null,
69+
licenseSources = emptySet(),
7070
severity = Severity.ERROR,
7171
message = message,
7272
howToFix = ""

plugins/commands/evaluator/src/main/kotlin/EvaluateCommand.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,7 @@ private fun RuleViolation.format() =
375375

376376
license?.let { license ->
377377
append(license)
378-
licenseSource?.let { source ->
379-
append(" (")
380-
append(source)
381-
append(")")
382-
}
378+
licenseSources.takeUnless { it.isEmpty() }?.joinToString(prefix = "(", postfix = ")") { it.toString() }
383379

384380
append(" - ")
385381
}

plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) {
393393
rule = ruleViolation.rule,
394394
pkg = pkg,
395395
license = license,
396-
licenseSource = ruleViolation.licenseSource,
396+
licenseSources = ruleViolation.licenseSources,
397397
severity = ruleViolation.severity,
398398
message = ruleViolation.message,
399399
howToFix = ruleViolation.howToFix,

plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedRuleViolation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data class EvaluatedRuleViolation(
3636
@JsonInclude(JsonInclude.Include.NON_NULL)
3737
val license: LicenseId?,
3838
@JsonInclude(JsonInclude.Include.NON_NULL)
39-
val licenseSource: LicenseSource?,
39+
val licenseSources: Set<LicenseSource>,
4040
val severity: Severity,
4141
@JsonInclude(JsonInclude.Include.NON_EMPTY)
4242
val message: String,

plugins/reporters/static-html/src/main/kotlin/StaticHtmlReporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class StaticHtmlReporter(override val descriptor: PluginDescriptor = StaticHtmlR
320320
td { +(ruleViolation.violation.pkg?.toCoordinates() ?: "-") }
321321
td {
322322
+if (ruleViolation.violation.license != null) {
323-
"${ruleViolation.violation.licenseSource}: ${ruleViolation.violation.license}"
323+
"${ruleViolation.violation.licenseSources.joinToString()}: ${ruleViolation.violation.license}"
324324
} else {
325325
"-"
326326
}

0 commit comments

Comments
 (0)