Skip to content

Commit

Permalink
fix(Scanner): Apply detectedLicenseMapping to package scanners
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
MarcelBochtler committed Sep 19, 2023
1 parent 3092dc2 commit a97eefb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scanner/src/main/kotlin/Scanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,22 @@ 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."
}

packagesWithIncompleteScanResult.forEach processResults@{ pkg ->
val nestedProvenance = controller.getNestedProvenance(pkg.id) ?: return@processResults
val nestedProvenanceScanResult = scanResult.toNestedProvenanceScanResult(nestedProvenance)
val nestedProvenanceScanResult = scanResultWithMappedLicenses.toNestedProvenanceScanResult(nestedProvenance)

Check warning

Code scanning / detekt

Line detected, which is longer than the defined maximum line length in the code style. Warning

Line detected, which is longer than the defined maximum line length in the code style.
controller.addNestedScanResult(scanner, nestedProvenanceScanResult)

// TODO: Run in coroutine.
Expand Down

0 comments on commit a97eefb

Please sign in to comment.