Skip to content

Commit 483895b

Browse files
committed
fix(spdx): Set the licenseConcluded via ORT's effective license
Previously, only ORT's `concludedLicense` from a package curation was taken into account. However, if solely detected license findings were cleared via license finding curations from package configurations, that did not have any impact at all until now. To fix this, use the effective license with a custom license view of the declared and detected licenses as a fallback if no concluded license is set. Finally, the `licenseConcluded` should only be set if (human) clearance work was involved, so only set it if it differs from the `licenseDeclared`. If `licenseDeclared` already was correct from the start, then this needs to be "acknowledged" by manually setting the concluded license to the same expression. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent 110da7a commit 483895b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

plugins/reporters/spdx/src/main/kotlin/Extensions.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.ossreviewtoolkit.model.Hash
3030
import org.ossreviewtoolkit.model.Identifier
3131
import org.ossreviewtoolkit.model.KnownProvenance
3232
import org.ossreviewtoolkit.model.LicenseFinding
33+
import org.ossreviewtoolkit.model.LicenseSource
3334
import org.ossreviewtoolkit.model.OrtResult
3435
import org.ossreviewtoolkit.model.Package
3536
import org.ossreviewtoolkit.model.Provenance
@@ -159,6 +160,12 @@ internal fun Package.toSpdxPackage(
159160
.applyChoices(ortResult.getPackageLicenseChoices(id))
160161
.applyChoices(ortResult.getRepositoryLicenseChoices())
161162

163+
val licenseDeclared = resolvedLicenseInfo.mainLicense()?.simplify()
164+
165+
val licenseView = LicenseView(setOf(LicenseSource.DECLARED, LicenseSource.DETECTED))
166+
val licenseConcluded = concludedLicense ?: resolvedLicenseInfo.effectiveLicense(licenseView)
167+
.takeUnless { it == licenseDeclared }
168+
162169
return SpdxPackage(
163170
spdxId = id.toSpdxId(type),
164171
checksums = when (type) {
@@ -182,11 +189,10 @@ internal fun Package.toSpdxPackage(
182189
SpdxPackageType.SOURCE_PACKAGE -> SpdxConstants.NOASSERTION
183190
// Clear the concluded license as it might need to be different for the VCS location.
184191
SpdxPackageType.VCS_PACKAGE -> SpdxConstants.NOASSERTION
185-
SpdxPackageType.PROJECT -> concludedLicense.nullOrBlankToSpdxNoassertionOrNone()
186-
else -> concludedLicense.nullOrBlankToSpdxNoassertionOrNone()
192+
SpdxPackageType.PROJECT -> licenseConcluded.nullOrBlankToSpdxNoassertionOrNone()
193+
else -> licenseConcluded.nullOrBlankToSpdxNoassertionOrNone()
187194
},
188-
licenseDeclared = resolvedLicenseInfo.mainLicense()
189-
?.simplify()
195+
licenseDeclared = licenseDeclared
190196
?.sorted()
191197
?.nullOrBlankToSpdxNoassertionOrNone()
192198
?: SpdxConstants.NONE,

0 commit comments

Comments
 (0)