From a97d4ea17dbba24dbf784f6d1d6e9bee8d0c1526 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 FossId findings While the `detectedLicenseMapping`s are globally applied for the other scanners, these mappings are not applied for FossId. This is because FossId works different from other scanners as a "remote" scanner. Apply the mappings to FossId results as well. This fixes a regression introduced in cdecb9b. Signed-off-by: Marcel Bochtler --- plugins/scanners/fossid/src/main/kotlin/FossId.kt | 2 +- .../scanners/fossid/src/main/kotlin/FossIdScanResults.kt | 7 +++++-- .../fossid/src/test/kotlin/FossIdLicenseMappingTest.kt | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/scanners/fossid/src/main/kotlin/FossId.kt b/plugins/scanners/fossid/src/main/kotlin/FossId.kt index 949aa9da6e8c7..00f3d4d17b686 100644 --- a/plugins/scanners/fossid/src/main/kotlin/FossId.kt +++ b/plugins/scanners/fossid/src/main/kotlin/FossId.kt @@ -876,7 +876,7 @@ class FossId internal constructor( val (licenseFindings, copyrightFindings) = rawResults.markedAsIdentifiedFiles.ifEmpty { rawResults.identifiedFiles - }.mapSummary(ignoredFiles, issues) + }.mapSummary(ignoredFiles, issues, scannerConfig.detectedLicenseMapping) val summary = ScanSummary( startTime = startTime, diff --git a/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt b/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt index e7b6623315a40..3977e14c2d967 100644 --- a/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt +++ b/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt @@ -38,6 +38,7 @@ import org.ossreviewtoolkit.model.Snippet as OrtSnippet import org.ossreviewtoolkit.model.SnippetFinding import org.ossreviewtoolkit.model.TextLocation import org.ossreviewtoolkit.model.createAndLogIssue +import org.ossreviewtoolkit.model.mapLicense import org.ossreviewtoolkit.model.utils.PurlType import org.ossreviewtoolkit.utils.common.collapseToRanges import org.ossreviewtoolkit.utils.common.collectMessages @@ -71,7 +72,8 @@ internal data class FindingsContainer( */ internal fun List.mapSummary( ignoredFiles: Map, - issues: MutableList + issues: MutableList, + detectedLicenseMapping: Map ): FindingsContainer { val licenseFindings = mutableSetOf() val copyrightFindings = mutableSetOf() @@ -83,7 +85,8 @@ internal fun List.mapSummary( summary.licences.forEach { runCatching { - LicenseFinding(it.identifier, location) + // TODO: The license mapping should be moved to a central place. + LicenseFinding(it.identifier.mapLicense(detectedLicenseMapping), location) }.onSuccess { licenseFinding -> licenseFindings += licenseFinding.copy(license = licenseFinding.license.normalize()) }.onFailure { spdxException -> diff --git a/plugins/scanners/fossid/src/test/kotlin/FossIdLicenseMappingTest.kt b/plugins/scanners/fossid/src/test/kotlin/FossIdLicenseMappingTest.kt index e868f96236063..33b85dd97ec98 100644 --- a/plugins/scanners/fossid/src/test/kotlin/FossIdLicenseMappingTest.kt +++ b/plugins/scanners/fossid/src/test/kotlin/FossIdLicenseMappingTest.kt @@ -49,7 +49,7 @@ class FossIdLicenseMappingTest : WordSpec({ val sampleFile = createMarkAsIdentifiedFile("invalid license") val issues = mutableListOf() - val findings = listOf(sampleFile).mapSummary(emptyMap(), issues) + val findings = listOf(sampleFile).mapSummary(emptyMap(), issues, emptyMap()) issues should haveSize(1) issues.first() shouldNotBeNull {