From 5fa7fd00ff6585e4613172ca7e2b1e210a283743 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 authors This is a preparation for solving #3400 and making copyright holder curations possible. A new field authors is added to Package, PackageCuration and Project in order to be able to track fields like authors 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 | 11 +++++++++++ model/src/main/kotlin/PackageCurationData.kt | 7 +++++++ 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..feb74f4754d54 100644 --- a/model/src/main/kotlin/Package.kt +++ b/model/src/main/kotlin/Package.kt @@ -52,6 +52,15 @@ data class Package( */ val purl: String = id.toPurl(), + /** + * The list of authors declared for this package. + * + * TODO: The annotation can be removed after all package manager implementations have filled the field [authors] + * accordingly. + */ + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + val authors: SortedSet = sortedSetOf(), + /** * The list of licenses the authors have declared for this package. This does not necessarily correspond to the * licenses as detected by a scanner. Both need to be taken into account for any conclusions. @@ -125,6 +134,7 @@ data class Package( val EMPTY = Package( id = Identifier.EMPTY, purl = "", + authors = sortedSetOf(), declaredLicenses = sortedSetOf(), declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY, concludedLicense = null, @@ -153,6 +163,7 @@ data class Package( } return PackageCurationData( + authors = authors.takeIf { it != other.authors }, declaredLicenses = declaredLicenses.takeIf { it != other.declaredLicenses }, description = description.takeIf { it != other.description }, homepageUrl = homepageUrl.takeIf { it != other.homepageUrl }, diff --git a/model/src/main/kotlin/PackageCurationData.kt b/model/src/main/kotlin/PackageCurationData.kt index 4e7b191d65582..e98aaf7fe5036 100644 --- a/model/src/main/kotlin/PackageCurationData.kt +++ b/model/src/main/kotlin/PackageCurationData.kt @@ -33,6 +33,11 @@ import org.ossreviewtoolkit.utils.DeclaredLicenseProcessor */ @JsonInclude(JsonInclude.Include.NON_NULL) data class PackageCurationData( + /** + * The list of authors of this package. + */ + val authors: SortedSet? = null, + /** * The list of licenses the authors have declared for this package. This does not necessarily correspond to the * licenses as detected by a scanner. Both need to be taken into account for any conclusions. @@ -118,12 +123,14 @@ private fun applyCurationToPackage(targetPackage: CuratedPackage, curation: Pack ) } ?: base.vcs + val authors = curation.authors ?: base.authors val declaredLicenses = curation.declaredLicenses ?: base.declaredLicenses val declaredLicenseMapping = targetPackage.getDeclaredLicenseMapping() + curation.declaredLicenseMapping val declaredLicensesProcessed = DeclaredLicenseProcessor.process(declaredLicenses, declaredLicenseMapping) val pkg = Package( id = base.id, + authors = authors, declaredLicenses = declaredLicenses, declaredLicensesProcessed = declaredLicensesProcessed, concludedLicense = curation.concludedLicense ?: base.concludedLicense, diff --git a/model/src/main/kotlin/Project.kt b/model/src/main/kotlin/Project.kt index 97b4cf80833d3..02ac94071b67b 100644 --- a/model/src/main/kotlin/Project.kt +++ b/model/src/main/kotlin/Project.kt @@ -50,6 +50,15 @@ data class Project( */ val definitionFilePath: String, + /** + * The list of authors declared for this package. + * + * TODO: The annotation can be removed after all package manager implementations have filled the field [authors] + * accordingly. + */ + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + val authors: SortedSet = sortedSetOf(), + /** * The list of licenses the authors have declared for this package. This does not necessarily correspond to the * licenses as detected by a scanner. Both need to be taken into account for any conclusions. @@ -102,6 +111,7 @@ data class Project( val EMPTY = Project( id = Identifier.EMPTY, definitionFilePath = "", + authors = sortedSetOf(), declaredLicenses = sortedSetOf(), declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY, vcs = VcsInfo.EMPTY, @@ -205,6 +215,7 @@ data class Project( fun toPackage() = Package( id = id, + authors = authors, declaredLicenses = declaredLicenses, description = "", homepageUrl = homepageUrl, diff --git a/model/src/test/kotlin/PackageCurationTest.kt b/model/src/test/kotlin/PackageCurationTest.kt index 4e8734be15e60..fcbe08231851d 100644 --- a/model/src/test/kotlin/PackageCurationTest.kt +++ b/model/src/test/kotlin/PackageCurationTest.kt @@ -39,6 +39,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), + authors = sortedSetOf(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -52,6 +53,7 @@ class PackageCurationTest : WordSpec({ val curation = PackageCuration( id = pkg.id, data = PackageCurationData( + authors = sortedSetOf("author 1", "author 2"), declaredLicenses = sortedSetOf("license a", "license b"), declaredLicenseMapping = mapOf("license a" to "Apache-2.0".toSpdx()), concludedLicense = "license1 OR license2".toSpdx(), @@ -81,6 +83,7 @@ class PackageCurationTest : WordSpec({ with(curatedPkg.pkg) { id.toCoordinates() shouldBe pkg.id.toCoordinates() + authors shouldBe curation.data.authors declaredLicenses shouldBe curation.data.declaredLicenses declaredLicensesProcessed.spdxExpression shouldBe "Apache-2.0".toSpdx() declaredLicensesProcessed.unmapped should containExactlyInAnyOrder("license b") @@ -107,6 +110,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), + authors = sortedSetOf("author 1", "author 2"), declaredLicenses = sortedSetOf("license a", "license b"), description = "description", homepageUrl = "homepageUrl", @@ -137,6 +141,7 @@ class PackageCurationTest : WordSpec({ with(curatedPkg.pkg) { id.toCoordinates() shouldBe pkg.id.toCoordinates() + authors shouldBe pkg.authors declaredLicenses shouldBe pkg.declaredLicenses concludedLicense shouldBe pkg.concludedLicense description shouldBe pkg.description @@ -167,6 +172,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), + authors = sortedSetOf("author 1", "author 2"), declaredLicenses = sortedSetOf("license a", "license b"), description = "description", homepageUrl = "homepageUrl", @@ -206,6 +212,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), + authors = sortedSetOf(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -239,6 +246,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), + authors = sortedSetOf(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -268,6 +276,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), + authors = sortedSetOf(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -362,6 +371,7 @@ class PackageCurationTest : WordSpec({ "accumulate the map entries and override the entries with same key" { val pkg = Package( id = Identifier("type", "namespace", "name", "version"), + authors = sortedSetOf(), declaredLicenses = sortedSetOf("license a", "license b", "license c"), description = "", homepageUrl = "", diff --git a/model/src/test/kotlin/PackageTest.kt b/model/src/test/kotlin/PackageTest.kt index 01f94e5d28000..cdff6f332a18e 100644 --- a/model/src/test/kotlin/PackageTest.kt +++ b/model/src/test/kotlin/PackageTest.kt @@ -43,6 +43,7 @@ class PackageTest : StringSpec({ name = "name", version = "version" ), + authors = sortedSetOf("author"), declaredLicenses = sortedSetOf("declared license"), description = "description", homepageUrl = "homepageUrl", @@ -59,6 +60,7 @@ class PackageTest : StringSpec({ name = "name", version = "version" ), + authors = sortedSetOf("other author"), declaredLicenses = sortedSetOf("other declared license"), description = "other description", homepageUrl = "other homepageUrl", @@ -72,6 +74,7 @@ class PackageTest : StringSpec({ diff.binaryArtifact shouldBe pkg.binaryArtifact diff.comment should beNull() + diff.authors shouldBe pkg.authors diff.declaredLicenses shouldBe pkg.declaredLicenses diff.homepageUrl shouldBe pkg.homepageUrl diff.sourceArtifact shouldBe pkg.sourceArtifact @@ -87,6 +90,7 @@ class PackageTest : StringSpec({ name = "name", version = "version" ), + authors = sortedSetOf("author"), declaredLicenses = sortedSetOf("declared license"), description = "description", homepageUrl = "homepageUrl", @@ -99,6 +103,7 @@ class PackageTest : StringSpec({ diff.binaryArtifact should beNull() diff.comment should beNull() + diff.authors should beNull() diff.declaredLicenses should beNull() diff.homepageUrl should beNull() diff.sourceArtifact should beNull()