diff --git a/scanner/src/main/kotlin/ScanResultsStorage.kt b/scanner/src/main/kotlin/ScanResultsStorage.kt index 8b4e12a414873..65dd4d4cb7e1f 100644 --- a/scanner/src/main/kotlin/ScanResultsStorage.kt +++ b/scanner/src/main/kotlin/ScanResultsStorage.kt @@ -154,27 +154,30 @@ abstract class ScanResultsStorage : PackageBasedScanStorage { if (results.isEmpty()) { results } else { - val scanResults = results.toMutableList() + val (matchingProvenance, nonMatchingProvenance) = results.partition { it.provenance.matches(pkg) } - // Only keep scan results whose provenance information matches the package information. - scanResults.retainAll { it.provenance.matches(pkg) } - if (scanResults.isEmpty()) { + if (matchingProvenance.isEmpty()) { logger.debug { "No stored scan results found for $pkg. The following entries with non-matching provenance " + - "have been ignored: ${scanResults.map { it.provenance }}" + "have been ignored: ${nonMatchingProvenance.map { it.provenance }}" } + + matchingProvenance } else { - // Only keep scan results from compatible scanners. - scanResults.retainAll { scannerCriteria.matches(it.scanner) } - if (scanResults.isEmpty()) { + val (matchingCriteria, nonMatchingCriteria) = matchingProvenance.partition { + scannerCriteria.matches(it.scanner) + } + + if (matchingCriteria.isEmpty()) { logger.debug { - "No stored scan results found for $scannerCriteria. The following entries with " + - "incompatible scanners have been ignored: ${scanResults.map { it.scanner }}" + "No stored scan results for '${pkg.id.toCoordinates()}' match $scannerCriteria. The " + + "following entries with non-matching criteria have been ignored: " + + nonMatchingCriteria.map { it.scanner } } } - } - scanResults + matchingCriteria + } } }