Skip to content

Commit

Permalink
model: Add a new field for declared authors
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 declaredAuthors 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 <onur.demirci@bosch.io>
  • Loading branch information
bs-ondem committed Feb 16, 2021
1 parent 04be50f commit 27d8f29
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions model/src/main/kotlin/Package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ data class Package(
*/
val declaredLicenses: SortedSet<String>,

/**
* The list of authors declared for this package.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
val declaredAuthors: SortedSet<String> = sortedSetOf(),

/**
* The declared licenses as [SpdxExpression]. If [declaredLicenses] contains multiple licenses they are
* concatenated with [SpdxOperator.AND].
Expand Down Expand Up @@ -126,6 +132,7 @@ data class Package(
id = Identifier.EMPTY,
purl = "",
declaredLicenses = sortedSetOf(),
declaredAuthors = sortedSetOf(),
declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY,
concludedLicense = null,
description = "",
Expand Down Expand Up @@ -154,6 +161,7 @@ data class Package(

return PackageCurationData(
declaredLicenses = declaredLicenses.takeIf { it != other.declaredLicenses },
declaredAuthors = declaredAuthors.takeIf { it != other.declaredAuthors },
description = description.takeIf { it != other.description },
homepageUrl = homepageUrl.takeIf { it != other.homepageUrl },
binaryArtifact = binaryArtifact.takeIf { it != other.binaryArtifact },
Expand Down
7 changes: 7 additions & 0 deletions model/src/main/kotlin/PackageCurationData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ data class PackageCurationData(
*/
val declaredLicenses: SortedSet<String>? = null,

/**
* The list of authors of this package.
*/
val declaredAuthors: 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 +124,14 @@ private fun applyCurationToPackage(targetPackage: CuratedPackage, curation: Pack
} ?: base.vcs

val declaredLicenses = curation.declaredLicenses ?: base.declaredLicenses
val declaredAuthors = curation.declaredAuthors ?: base.declaredAuthors
val declaredLicenseMapping = targetPackage.getDeclaredLicenseMapping() + curation.declaredLicenseMapping
val declaredLicensesProcessed = DeclaredLicenseProcessor.process(declaredLicenses, declaredLicenseMapping)

val pkg = Package(
id = base.id,
declaredLicenses = declaredLicenses,
declaredAuthors = declaredAuthors,
declaredLicensesProcessed = declaredLicensesProcessed,
concludedLicense = curation.concludedLicense ?: base.concludedLicense,
description = curation.description ?: base.description,
Expand Down
8 changes: 8 additions & 0 deletions model/src/main/kotlin/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ data class Project(
*/
val declaredLicenses: SortedSet<String>,

/**
* The list of authors declared for this package.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
val declaredAuthors: SortedSet<String> = sortedSetOf(),

/**
* The declared licenses as [SpdxExpression]. If [declaredLicenses] contains multiple licenses they are
* concatenated with [SpdxOperator.AND].
Expand Down Expand Up @@ -103,6 +109,7 @@ data class Project(
id = Identifier.EMPTY,
definitionFilePath = "",
declaredLicenses = sortedSetOf(),
declaredAuthors = sortedSetOf(),
declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY,
vcs = VcsInfo.EMPTY,
vcsProcessed = VcsInfo.EMPTY,
Expand Down Expand Up @@ -199,6 +206,7 @@ data class Project(
Package(
id = id,
declaredLicenses = declaredLicenses,
declaredAuthors = declaredAuthors,
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(),
declaredAuthors = 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"),
declaredAuthors = sortedSetOf("author 1", "author 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
declaredAuthors shouldBe curation.data.declaredAuthors
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"),
declaredAuthors = sortedSetOf("author 1", "author 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
declaredAuthors shouldBe pkg.declaredAuthors
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"),
declaredAuthors = sortedSetOf("author 1", "author 2"),
description = "description",
homepageUrl = "homepageUrl",
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down Expand Up @@ -207,6 +213,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredAuthors = sortedSetOf(),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down Expand Up @@ -240,6 +247,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredAuthors = sortedSetOf(),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact.EMPTY,
Expand Down Expand Up @@ -269,6 +277,7 @@ class PackageCurationTest : WordSpec({
version = "1.3"
),
declaredLicenses = sortedSetOf(),
declaredAuthors = 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"),
declaredAuthors = 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"),
declaredAuthors = sortedSetOf("declared author"),
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"),
declaredAuthors = sortedSetOf("other declared author"),
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.declaredAuthors shouldBe pkg.declaredAuthors
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"),
declaredAuthors = sortedSetOf("declared author"),
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.declaredAuthors should beNull()
diff.homepageUrl should beNull()
diff.sourceArtifact should beNull()
diff.vcs should beNull()
Expand Down

0 comments on commit 27d8f29

Please sign in to comment.