Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Scanner): Apply detectedLicenseMapping to FossId findings #7537

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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