From 1a4317a9673049925ad6f485f25724bb42748eeb Mon Sep 17 00:00:00 2001 From: Onur Demirci Date: Thu, 11 Feb 2021 11:13:52 +0100 Subject: [PATCH] model: Add a new field for declared contributors This is a preparation for solving #3400 and making copyright holder curations possible. A new field declaredContributors is added to Package, PackageCuration and Project in order to be able to track fields like authors/developers/contributors from various package managers. These changes don't include the adaptation of the package managers. Signed-off-by: Onur Demirci --- model/src/main/kotlin/Package.kt | 10 ++++++++++ model/src/main/kotlin/PackageCurationData.kt | 8 ++++++++ model/src/main/kotlin/Project.kt | 11 +++++++++++ model/src/test/kotlin/PackageCurationTest.kt | 10 ++++++++++ model/src/test/kotlin/PackageTest.kt | 5 +++++ 5 files changed, 44 insertions(+) diff --git a/model/src/main/kotlin/Package.kt b/model/src/main/kotlin/Package.kt index a4ed0ed65c593..8e55be212bfba 100644 --- a/model/src/main/kotlin/Package.kt +++ b/model/src/main/kotlin/Package.kt @@ -58,6 +58,14 @@ data class Package( */ val declaredLicenses: SortedSet, + /** + * The list of contributors declared for this package. + * + * TODO: Remove default value after upgrading all package manager implementations. + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + val declaredContributors: SortedSet? = null, + /** * The declared licenses as [SpdxExpression]. If [declaredLicenses] contains multiple licenses they are * concatenated with [SpdxOperator.AND]. @@ -126,6 +134,7 @@ data class Package( id = Identifier.EMPTY, purl = "", declaredLicenses = sortedSetOf(), + declaredContributors = sortedSetOf(), declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY, concludedLicense = null, description = "", @@ -154,6 +163,7 @@ data class Package( return PackageCurationData( declaredLicenses = declaredLicenses.takeIf { it != other.declaredLicenses }, + declaredContributors = declaredContributors.takeIf { it != other.declaredContributors }, description = description.takeIf { it != other.description }, homepageUrl = homepageUrl.takeIf { it != other.homepageUrl }, binaryArtifact = binaryArtifact.takeIf { it != other.binaryArtifact }, diff --git a/model/src/main/kotlin/PackageCurationData.kt b/model/src/main/kotlin/PackageCurationData.kt index 4e7b191d65582..5a574a546dafb 100644 --- a/model/src/main/kotlin/PackageCurationData.kt +++ b/model/src/main/kotlin/PackageCurationData.kt @@ -39,6 +39,12 @@ data class PackageCurationData( */ val declaredLicenses: SortedSet? = null, + /** + * The list of contributors of this package. + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + val declaredContributors: SortedSet? = null, + /** * The concluded license as an [SpdxExpression]. It can be used to correct the license of a package in case the * [declaredLicenses] found in the packages metadata or the licenses detected by a scanner do not match reality. @@ -119,12 +125,14 @@ private fun applyCurationToPackage(targetPackage: CuratedPackage, curation: Pack } ?: base.vcs val declaredLicenses = curation.declaredLicenses ?: base.declaredLicenses + val declaredContributors = curation.declaredContributors ?: base.declaredContributors val declaredLicenseMapping = targetPackage.getDeclaredLicenseMapping() + curation.declaredLicenseMapping val declaredLicensesProcessed = DeclaredLicenseProcessor.process(declaredLicenses, declaredLicenseMapping) val pkg = Package( id = base.id, declaredLicenses = declaredLicenses, + declaredContributors = declaredContributors, declaredLicensesProcessed = declaredLicensesProcessed, concludedLicense = curation.concludedLicense ?: base.concludedLicense, description = curation.description ?: base.description, diff --git a/model/src/main/kotlin/Project.kt b/model/src/main/kotlin/Project.kt index 1967dff1948d3..ac1e49878c512 100644 --- a/model/src/main/kotlin/Project.kt +++ b/model/src/main/kotlin/Project.kt @@ -20,6 +20,7 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonInclude import java.util.SortedSet @@ -53,6 +54,14 @@ data class Project( */ val declaredLicenses: SortedSet, + /** + * The list of contributors declared for this package. + * + * TODO: Remove default value after upgrading all package manager implementations. + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + val declaredContributors: SortedSet? = null, + /** * The declared licenses as [SpdxExpression]. If [declaredLicenses] contains multiple licenses they are * concatenated with [SpdxOperator.AND]. @@ -88,6 +97,7 @@ data class Project( id = Identifier.EMPTY, definitionFilePath = "", declaredLicenses = sortedSetOf(), + declaredContributors = sortedSetOf(), declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY, vcs = VcsInfo.EMPTY, vcsProcessed = VcsInfo.EMPTY, @@ -165,6 +175,7 @@ data class Project( Package( id = id, declaredLicenses = declaredLicenses, + declaredContributors = declaredContributors, description = "", homepageUrl = homepageUrl, binaryArtifact = RemoteArtifact.EMPTY, diff --git a/model/src/test/kotlin/PackageCurationTest.kt b/model/src/test/kotlin/PackageCurationTest.kt index 4e8734be15e60..cf79bf0843416 100644 --- a/model/src/test/kotlin/PackageCurationTest.kt +++ b/model/src/test/kotlin/PackageCurationTest.kt @@ -40,6 +40,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), declaredLicenses = sortedSetOf(), + declaredContributors = sortedSetOf(), description = "", homepageUrl = "", binaryArtifact = RemoteArtifact.EMPTY, @@ -53,6 +54,7 @@ class PackageCurationTest : WordSpec({ id = pkg.id, data = PackageCurationData( declaredLicenses = sortedSetOf("license a", "license b"), + declaredContributors = sortedSetOf("contributor 1", "contributor 2"), declaredLicenseMapping = mapOf("license a" to "Apache-2.0".toSpdx()), concludedLicense = "license1 OR license2".toSpdx(), description = "description", @@ -82,6 +84,7 @@ class PackageCurationTest : WordSpec({ with(curatedPkg.pkg) { id.toCoordinates() shouldBe pkg.id.toCoordinates() declaredLicenses shouldBe curation.data.declaredLicenses + declaredContributors shouldBe curation.data.declaredContributors declaredLicensesProcessed.spdxExpression shouldBe "Apache-2.0".toSpdx() declaredLicensesProcessed.unmapped should containExactlyInAnyOrder("license b") concludedLicense shouldBe curation.data.concludedLicense @@ -108,6 +111,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), declaredLicenses = sortedSetOf("license a", "license b"), + declaredContributors = sortedSetOf("contributor 1", "contributor 2"), description = "description", homepageUrl = "homepageUrl", binaryArtifact = RemoteArtifact.EMPTY, @@ -138,6 +142,7 @@ class PackageCurationTest : WordSpec({ with(curatedPkg.pkg) { id.toCoordinates() shouldBe pkg.id.toCoordinates() declaredLicenses shouldBe pkg.declaredLicenses + declaredContributors shouldBe pkg.declaredContributors concludedLicense shouldBe pkg.concludedLicense description shouldBe pkg.description homepageUrl shouldBe curation.data.homepageUrl @@ -168,6 +173,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), declaredLicenses = sortedSetOf("license a", "license b"), + declaredContributors = sortedSetOf("contributor 1", "contributor 2"), description = "description", homepageUrl = "homepageUrl", binaryArtifact = RemoteArtifact.EMPTY, @@ -207,6 +213,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), declaredLicenses = sortedSetOf(), + declaredContributors = sortedSetOf(), description = "", homepageUrl = "", binaryArtifact = RemoteArtifact.EMPTY, @@ -240,6 +247,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), declaredLicenses = sortedSetOf(), + declaredContributors = sortedSetOf(), description = "", homepageUrl = "", binaryArtifact = RemoteArtifact.EMPTY, @@ -269,6 +277,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), declaredLicenses = sortedSetOf(), + declaredContributors = sortedSetOf(), description = "", homepageUrl = "", binaryArtifact = RemoteArtifact.EMPTY, @@ -363,6 +372,7 @@ class PackageCurationTest : WordSpec({ val pkg = Package( id = Identifier("type", "namespace", "name", "version"), declaredLicenses = sortedSetOf("license a", "license b", "license c"), + declaredContributors = sortedSetOf(), description = "", homepageUrl = "", binaryArtifact = RemoteArtifact.EMPTY, diff --git a/model/src/test/kotlin/PackageTest.kt b/model/src/test/kotlin/PackageTest.kt index 01f94e5d28000..aef0523a791fd 100644 --- a/model/src/test/kotlin/PackageTest.kt +++ b/model/src/test/kotlin/PackageTest.kt @@ -44,6 +44,7 @@ class PackageTest : StringSpec({ version = "version" ), declaredLicenses = sortedSetOf("declared license"), + declaredContributors = sortedSetOf("declared contributor"), description = "description", homepageUrl = "homepageUrl", binaryArtifact = RemoteArtifact("url", Hash.create("hash")), @@ -60,6 +61,7 @@ class PackageTest : StringSpec({ version = "version" ), declaredLicenses = sortedSetOf("other declared license"), + declaredContributors = sortedSetOf("other declared contributor"), description = "other description", homepageUrl = "other homepageUrl", binaryArtifact = RemoteArtifact("other url", Hash.create("other hash")), @@ -73,6 +75,7 @@ class PackageTest : StringSpec({ diff.binaryArtifact shouldBe pkg.binaryArtifact diff.comment should beNull() diff.declaredLicenses shouldBe pkg.declaredLicenses + diff.declaredContributors shouldBe pkg.declaredContributors diff.homepageUrl shouldBe pkg.homepageUrl diff.sourceArtifact shouldBe pkg.sourceArtifact diff.vcs shouldBe pkg.vcs.toCuration() @@ -88,6 +91,7 @@ class PackageTest : StringSpec({ version = "version" ), declaredLicenses = sortedSetOf("declared license"), + declaredContributors = sortedSetOf("declared contributor"), description = "description", homepageUrl = "homepageUrl", binaryArtifact = RemoteArtifact("url", Hash.create("hash")), @@ -100,6 +104,7 @@ class PackageTest : StringSpec({ diff.binaryArtifact should beNull() diff.comment should beNull() diff.declaredLicenses should beNull() + diff.declaredContributors should beNull() diff.homepageUrl should beNull() diff.sourceArtifact should beNull() diff.vcs should beNull()