diff --git a/plugins/scanners/fossid/src/main/kotlin/FossId.kt b/plugins/scanners/fossid/src/main/kotlin/FossId.kt index 848efc734bc9c..5c3146ea81e37 100644 --- a/plugins/scanners/fossid/src/main/kotlin/FossId.kt +++ b/plugins/scanners/fossid/src/main/kotlin/FossId.kt @@ -641,7 +641,7 @@ class FossId internal constructor( }.orEmpty() // Create an issue for each legacy rule. - val legacyRules = excludesRules.filterLegacyRules(existingRules, issues) + val legacyRules = existingRules.filterLegacyRules(excludesRules, issues) if (legacyRules.isNotEmpty()) { logger.warn { "${legacyRules.size} legacy rules have been found." } } diff --git a/plugins/scanners/fossid/src/main/kotlin/Utils.kt b/plugins/scanners/fossid/src/main/kotlin/Utils.kt index 0156df9d54aa5..88cf28acc9a19 100644 --- a/plugins/scanners/fossid/src/main/kotlin/Utils.kt +++ b/plugins/scanners/fossid/src/main/kotlin/Utils.kt @@ -84,15 +84,16 @@ private fun PathExclude.mapToRule(): IgnoreRule? { } /** - * Check if some elements of [rulesToTest] are legacy rules i.e. are not present in a reference list (current object). - * Create an issue on [issues] for each legacy rule and return a list of the latter. + * Filter [IgnoreRule]s which are not contained in the [referenceRules]. These are legacy rules because they were not + * created from the [Excludes] defined in the repository configuration. Also create an [Issue] for each legacy rule and + * add it to [issues]. */ internal fun List.filterLegacyRules( - rulesToTest: List, + referenceRules: List, issues: MutableList ): List = - rulesToTest.filterNot { ruleToTest -> - any { it.value == ruleToTest.value && it.type == ruleToTest.type } + filterNot { rule -> + referenceRules.any { it.value == rule.value && it.type == rule.type } }.onEach { issues += Issue( source = "FossID.compare", diff --git a/plugins/scanners/fossid/src/test/kotlin/LegacyRulesTest.kt b/plugins/scanners/fossid/src/test/kotlin/LegacyRulesTest.kt index b086b8405021a..69748b20e071c 100644 --- a/plugins/scanners/fossid/src/test/kotlin/LegacyRulesTest.kt +++ b/plugins/scanners/fossid/src/test/kotlin/LegacyRulesTest.kt @@ -43,7 +43,7 @@ class LegacyRulesTest : WordSpec({ ) val issues = mutableListOf() - val legacyRules = referenceRules.filterLegacyRules(rulesToTest, issues) + val legacyRules = rulesToTest.filterLegacyRules(referenceRules, issues) issues shouldHaveSize 1 issues.first() shouldNotBeNull { @@ -65,7 +65,7 @@ class LegacyRulesTest : WordSpec({ ) val issues = mutableListOf() - val legacyRules = referenceRules.filterLegacyRules(rulesToTest, issues) + val legacyRules = rulesToTest.filterLegacyRules(referenceRules, issues) issues should beEmpty() legacyRules should beEmpty()