Skip to content

Commit

Permalink
model: Add a new field for declared contributors
Browse files Browse the repository at this point in the history
This is a preparation for solving oss-review-toolkit#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 <onur.demirci@bosch.io>
  • Loading branch information
bs-ondem committed Feb 11, 2021
1 parent 36806b1 commit 1a4317a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions model/src/main/kotlin/Package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ data class Package(
*/
val declaredLicenses: SortedSet<String>,

/**
* 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<String>? = null,

/**
* The declared licenses as [SpdxExpression]. If [declaredLicenses] contains multiple licenses they are
* concatenated with [SpdxOperator.AND].
Expand Down Expand Up @@ -126,6 +134,7 @@ data class Package(
id = Identifier.EMPTY,
purl = "",
declaredLicenses = sortedSetOf(),
declaredContributors = sortedSetOf(),
declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY,
concludedLicense = null,
description = "",
Expand Down Expand Up @@ -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 },
Expand Down
8 changes: 8 additions & 0 deletions model/src/main/kotlin/PackageCurationData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ data class PackageCurationData(
*/
val declaredLicenses: SortedSet<String>? = null,

/**
* The list of contributors of this package.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
val declaredContributors: SortedSet<String>? = 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.
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions model/src/main/kotlin/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.ossreviewtoolkit.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude

import java.util.SortedSet

Expand Down Expand Up @@ -53,6 +54,14 @@ data class Project(
*/
val declaredLicenses: SortedSet<String>,

/**
* 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<String>? = null,

/**
* The declared licenses as [SpdxExpression]. If [declaredLicenses] contains multiple licenses they are
* concatenated with [SpdxOperator.AND].
Expand Down Expand Up @@ -88,6 +97,7 @@ data class Project(
id = Identifier.EMPTY,
definitionFilePath = "",
declaredLicenses = sortedSetOf(),
declaredContributors = sortedSetOf(),
declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY,
vcs = VcsInfo.EMPTY,
vcsProcessed = VcsInfo.EMPTY,
Expand Down Expand Up @@ -165,6 +175,7 @@ data class Project(
Package(
id = id,
declaredLicenses = declaredLicenses,
declaredContributors = declaredContributors,
description = "",
homepageUrl = homepageUrl,
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down
10 changes: 10 additions & 0 deletions model/src/test/kotlin/PackageCurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredContributors = sortedSetOf(),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact.EMPTY,
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -207,6 +213,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredContributors = sortedSetOf(),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down Expand Up @@ -240,6 +247,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredContributors = sortedSetOf(),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down Expand Up @@ -269,6 +277,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredContributors = sortedSetOf(),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions model/src/test/kotlin/PackageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -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")),
Expand All @@ -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()
Expand All @@ -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")),
Expand All @@ -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()
Expand Down

0 comments on commit 1a4317a

Please sign in to comment.