From a97eefb9be82da4a6ab2897e8f3addff04adc5d7 Mon Sep 17 00:00:00 2001 From: Marcel Bochtler Date: Tue, 19 Sep 2023 13:28:33 +0200 Subject: [PATCH] fix(Scanner): Apply `detectedLicenseMapping` to package scanners While the `detectedLicenseMapping` is already applied for path scanners, these mappings are not applied for package scanners. As FossId is not a path scanner, the mappings did not work. Also apply the mappings to package scanners. This fixes an issue introduced in 6cc401a. Signed-off-by: Marcel Bochtler --- scanner/src/main/kotlin/Scanner.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scanner/src/main/kotlin/Scanner.kt b/scanner/src/main/kotlin/Scanner.kt index 3a2ccfdc6fdf9..b2239511eb41d 100644 --- a/scanner/src/main/kotlin/Scanner.kt +++ b/scanner/src/main/kotlin/Scanner.kt @@ -376,6 +376,14 @@ class Scanner( // Filter the scan context to hide the excludes from scanner with scan criteria. val filteredContext = if (scanner.criteria == null) context else context.copy(excludes = null) val scanResult = scanner.scanPackage(referencePackage, filteredContext) + val scanResultWithMappedLicenses = scanResult.copy( + summary = scanResult.summary.copy( + licenseFindings = scanResult.summary.licenseFindings.mapTo(mutableSetOf()) { + val licenseString = it.license.toString() + it.copy(license = licenseString.mapLicense(scannerConfig.detectedLicenseMapping).toSpdx()) + } + ) + ) logger.info { "Scan of '${referencePackage.id.toCoordinates()}' with package scanner '${scanner.name}' finished." @@ -383,7 +391,7 @@ class Scanner( packagesWithIncompleteScanResult.forEach processResults@{ pkg -> val nestedProvenance = controller.getNestedProvenance(pkg.id) ?: return@processResults - val nestedProvenanceScanResult = scanResult.toNestedProvenanceScanResult(nestedProvenance) + val nestedProvenanceScanResult = scanResultWithMappedLicenses.toNestedProvenanceScanResult(nestedProvenance) controller.addNestedScanResult(scanner, nestedProvenanceScanResult) // TODO: Run in coroutine.