diff --git a/model/src/main/kotlin/licenses/LicenseInfoResolver.kt b/model/src/main/kotlin/licenses/LicenseInfoResolver.kt index d95deea1cc3f5..4cc15b28f2728 100644 --- a/model/src/main/kotlin/licenses/LicenseInfoResolver.kt +++ b/model/src/main/kotlin/licenses/LicenseInfoResolver.kt @@ -83,6 +83,10 @@ class LicenseInfoResolver( licenseInfo.concludedLicenseInfo.concludedLicense?.also { originalExpressions += ResolvedOriginalExpression(expression = it, source = LicenseSource.CONCLUDED) } + + licenseInfo.declaredLicenseInfo.authors.takeIf { it.isNotEmpty() && addAuthorsToCopyrights }?.also { + locations += getAuthorsAsCopyrightTextLocation(it) + } } } @@ -98,23 +102,7 @@ class LicenseInfoResolver( }.keys licenseInfo.declaredLicenseInfo.authors.takeIf { it.isNotEmpty() && addAuthorsToCopyrights }?.also { - locations += ResolvedLicenseLocation( - provenance = UnknownProvenance, - location = UNDEFINED_TEXT_LOCATION, - appliedCuration = null, - matchingPathExcludes = emptyList(), - copyrights = it.mapTo(mutableSetOf()) { author -> - val statement = "Copyright (C) $author".takeUnless { - author.contains("Copyright", ignoreCase = true) - } ?: author - - ResolvedCopyrightFinding( - statement = statement, - location = UNDEFINED_TEXT_LOCATION, - matchingPathExcludes = emptyList() - ) - } - ) + locations += getAuthorsAsCopyrightTextLocation(it) } } } @@ -287,6 +275,25 @@ class LicenseInfoResolver( return ResolvedLicenseFileInfo(id, licenseFiles) } + + private fun getAuthorsAsCopyrightTextLocation(authors: Set): ResolvedLicenseLocation = + ResolvedLicenseLocation( + provenance = UnknownProvenance, + location = UNDEFINED_TEXT_LOCATION, + appliedCuration = null, + matchingPathExcludes = emptyList(), + copyrights = authors.mapTo(mutableSetOf()) { author -> + val statement = "Copyright (C) $author".takeUnless { + author.contains("Copyright", ignoreCase = true) + } ?: author + + ResolvedCopyrightFinding( + statement = statement, + location = UNDEFINED_TEXT_LOCATION, + matchingPathExcludes = emptyList() + ) + } + ) } private class ResolvedLicenseBuilder(val license: SpdxSingleLicenseExpression) { diff --git a/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt b/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt index db6774f723377..70d5e66efc724 100644 --- a/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt +++ b/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt @@ -575,6 +575,27 @@ class LicenseInfoResolverTest : WordSpec({ ) } + "resolve copyrights from authors in concluded license" { + // In case of a concluded license (due to a package curation) verify that the authors named + // in the package curation are added as copyright statement under the concluded license + val licenseInfos = listOf( + createLicenseInfo( + id = pkgId, + authors = authors, + declaredLicenses = setOf("MIT"), + concludedLicense = SpdxExpression.parse("BSD-2-Clause") + ) + ) + + val resolver = createResolver(licenseInfos, addAuthorsToCopyrights = true) + + val result = resolver.resolveLicenseInfo(pkgId) + result should containCopyrightStatementsForLicenseExactly( + "BSD-2-Clause", + "Copyright (C) The Author", "Copyright (C) The Other Author" + ) + } + "not resolve copyrights from authors if disabled" { val licenseInfos = listOf( createLicenseInfo( @@ -589,6 +610,24 @@ class LicenseInfoResolverTest : WordSpec({ result should containCopyrightStatementsForLicenseExactly("LicenseRef-a") result should containCopyrightStatementsForLicenseExactly("LicenseRef-b") } + + "not resolve copyrights from authors in concluded license if disabled" { + // In case of a concluded license (due to a package curation) verify that the authors named + // in the package curation are added as copyright statement under the concluded license + val licenseInfos = listOf( + createLicenseInfo( + id = pkgId, + authors = authors, + declaredLicenses = setOf("MIT"), + concludedLicense = SpdxExpression.parse("BSD-2-Clause") + ) + ) + + val resolver = createResolver(licenseInfos, addAuthorsToCopyrights = false) + + val result = resolver.resolveLicenseInfo(pkgId) + result should containCopyrightStatementsForLicenseExactly("BSD-2-Clause") + } } "resolveLicenseFiles()" should {