Skip to content

Commit

Permalink
fix(Scanner): Apply detectedLicenseMapping to FossId findings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
MarcelBochtler committed Sep 21, 2023
1 parent 2a7d3f5 commit 0b04df0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/scanners/fossid/src/main/kotlin/FossId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +72,8 @@ internal data class FindingsContainer(
*/
internal fun <T : Summarizable> List<T>.mapSummary(
ignoredFiles: Map<String, IgnoredFile>,
issues: MutableList<Issue>
issues: MutableList<Issue>,
detectedLicenseMapping: Map<String, String>
): FindingsContainer {
val licenseFindings = mutableSetOf<LicenseFinding>()
val copyrightFindings = mutableSetOf<CopyrightFinding>()
Expand All @@ -83,7 +85,8 @@ internal fun <T : Summarizable> List<T>.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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FossIdLicenseMappingTest : WordSpec({
val sampleFile = createMarkAsIdentifiedFile("invalid license")
val issues = mutableListOf<Issue>()

val findings = listOf(sampleFile).mapSummary(emptyMap(), issues)
val findings = listOf(sampleFile).mapSummary(emptyMap(), issues, emptyMap())

issues should haveSize(1)
issues.first() shouldNotBeNull {
Expand Down

0 comments on commit 0b04df0

Please sign in to comment.