Skip to content

Commit eb3ff11

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 <[email protected]>
1 parent 110da7a commit eb3ff11

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 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,14 @@ internal fun Package.toSpdxPackage(
159160
.applyChoices(ortResult.getPackageLicenseChoices(id))
160161
.applyChoices(ortResult.getRepositoryLicenseChoices())
161162

163+
val licenseDeclared = resolvedLicenseInfo.mainLicense()?.simplify()
164+
165+
// Do not use `CONCLUDED_OR_DECLARED_AND_DETECTED` here to support explicitly setting the `concludedLicense` to the
166+
// `licenseDeclared` in order to acknowledge the latter and record it as the license concluded in SPDX.
167+
val licenseView = LicenseView(setOf(LicenseSource.DECLARED, LicenseSource.DETECTED))
168+
val licenseConcluded = concludedLicense ?: resolvedLicenseInfo.effectiveLicense(licenseView)
169+
.takeUnless { it == licenseDeclared }
170+
162171
return SpdxPackage(
163172
spdxId = id.toSpdxId(type),
164173
checksums = when (type) {
@@ -182,11 +191,10 @@ internal fun Package.toSpdxPackage(
182191
SpdxPackageType.SOURCE_PACKAGE -> SpdxConstants.NOASSERTION
183192
// Clear the concluded license as it might need to be different for the VCS location.
184193
SpdxPackageType.VCS_PACKAGE -> SpdxConstants.NOASSERTION
185-
SpdxPackageType.PROJECT -> concludedLicense.nullOrBlankToSpdxNoassertionOrNone()
186-
else -> concludedLicense.nullOrBlankToSpdxNoassertionOrNone()
194+
SpdxPackageType.PROJECT -> licenseConcluded.nullOrBlankToSpdxNoassertionOrNone()
195+
else -> licenseConcluded.nullOrBlankToSpdxNoassertionOrNone()
187196
},
188-
licenseDeclared = resolvedLicenseInfo.mainLicense()
189-
?.simplify()
197+
licenseDeclared = licenseDeclared
190198
?.sorted()
191199
?.nullOrBlankToSpdxNoassertionOrNone()
192200
?: SpdxConstants.NONE,

0 commit comments

Comments
 (0)