Skip to content

Commit

Permalink
model: Add a new field for authors
Browse files Browse the repository at this point in the history
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 <onur.demirci@bosch.io>
  • Loading branch information
bs-ondem authored and sschuberth committed Feb 18, 2021
1 parent 9aaa0d9 commit 5fa7fd0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions model/src/main/kotlin/Package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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.
Expand Down Expand Up @@ -125,6 +134,7 @@ data class Package(
val EMPTY = Package(
id = Identifier.EMPTY,
purl = "",
authors = sortedSetOf(),
declaredLicenses = sortedSetOf(),
declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY,
concludedLicense = null,
Expand Down Expand Up @@ -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 },
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 @@ -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<String>? = 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.
Expand Down Expand Up @@ -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,
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 @@ -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<String> = 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.
Expand Down Expand Up @@ -102,6 +111,7 @@ data class Project(
val EMPTY = Project(
id = Identifier.EMPTY,
definitionFilePath = "",
authors = sortedSetOf(),
declaredLicenses = sortedSetOf(),
declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY,
vcs = VcsInfo.EMPTY,
Expand Down Expand Up @@ -205,6 +215,7 @@ data class Project(
fun toPackage() =
Package(
id = id,
authors = authors,
declaredLicenses = declaredLicenses,
description = "",
homepageUrl = homepageUrl,
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 @@ -39,6 +39,7 @@ class PackageCurationTest : WordSpec({
name = "hamcrest-core",
version = "1.3"
),
authors = sortedSetOf(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand All @@ -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(),
Expand Down Expand Up @@ -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")
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -206,6 +212,7 @@ class PackageCurationTest : WordSpec({
name = "hamcrest-core",
version = "1.3"
),
authors = sortedSetOf(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand Down Expand Up @@ -239,6 +246,7 @@ class PackageCurationTest : WordSpec({
name = "hamcrest-core",
version = "1.3"
),
authors = sortedSetOf(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand Down Expand Up @@ -268,6 +276,7 @@ class PackageCurationTest : WordSpec({
name = "hamcrest-core",
version = "1.3"
),
authors = sortedSetOf(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand Down Expand Up @@ -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 = "",
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 @@ -43,6 +43,7 @@ class PackageTest : StringSpec({
name = "name",
version = "version"
),
authors = sortedSetOf("author"),
declaredLicenses = sortedSetOf("declared license"),
description = "description",
homepageUrl = "homepageUrl",
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -87,6 +90,7 @@ class PackageTest : StringSpec({
name = "name",
version = "version"
),
authors = sortedSetOf("author"),
declaredLicenses = sortedSetOf("declared license"),
description = "description",
homepageUrl = "homepageUrl",
Expand All @@ -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()
Expand Down

0 comments on commit 5fa7fd0

Please sign in to comment.