Skip to content

Commit

Permalink
feat(model): Allow to set sourceCodeOrigins via package curations
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Mar 15, 2024
1 parent cadf56a commit bf12184
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
3 changes: 2 additions & 1 deletion model/src/main/kotlin/Package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ data class Package(
sourceArtifact = sourceArtifact.takeIf { it != other.sourceArtifact },
vcs = vcsProcessed.takeIf { it != other.vcsProcessed }?.toCuration(),
isMetadataOnly = isMetadataOnly.takeIf { it != other.isMetadataOnly },
isModified = isModified.takeIf { it != other.isModified }
isModified = isModified.takeIf { it != other.isModified },
sourceCodeOrigins = sourceCodeOrigins.takeIf { it != other.sourceCodeOrigins }
)
}

Expand Down
15 changes: 12 additions & 3 deletions model/src/main/kotlin/PackageCurationData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ data class PackageCurationData(
* applied by [DeclaredLicenseProcessor.process].
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
val declaredLicenseMapping: Map<String, SpdxExpression> = emptyMap()
val declaredLicenseMapping: Map<String, SpdxExpression> = emptyMap(),

/**
* The considered source code origins in order of priority. If not null, this must not be empty and not contain any
* duplicates.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
val sourceCodeOrigins: List<SourceCodeOrigin>? = null
) {
/**
* Apply this [PackageCuration] to [targetPackage] by overriding all values of [targetPackage] with non-null values
Expand Down Expand Up @@ -139,7 +146,8 @@ data class PackageCurationData(
vcs = original.vcs,
vcsProcessed = vcsProcessed,
isMetadataOnly = isMetadataOnly ?: original.isMetadataOnly,
isModified = isModified ?: original.isModified
isModified = isModified ?: original.isModified,
sourceCodeOrigins = sourceCodeOrigins ?: original.sourceCodeOrigins
)

val declaredLicenseMappingDiff = buildMap {
Expand Down Expand Up @@ -179,6 +187,7 @@ data class PackageCurationData(
declaredLicenseMapping = declaredLicenseMapping.zip(other.declaredLicenseMapping) { value, otherValue ->
@Suppress("UnsafeCallOnNullableType")
(value ?: otherValue)!!
}
},
sourceCodeOrigins = sourceCodeOrigins ?: other.sourceCodeOrigins
)
}
15 changes: 10 additions & 5 deletions model/src/test/kotlin/PackageCurationDataTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class PackageCurationDataTest : WordSpec({
),
isMetadataOnly = true,
isModified = true,
declaredLicenseMapping = mapOf("original" to "original".toSpdx())
declaredLicenseMapping = mapOf("original" to "original".toSpdx()),
sourceCodeOrigins = listOf(SourceCodeOrigin.ARTIFACT, SourceCodeOrigin.VCS)
)

val other = PackageCurationData(
Expand All @@ -76,7 +77,8 @@ class PackageCurationDataTest : WordSpec({
),
isMetadataOnly = false,
isModified = false,
declaredLicenseMapping = mapOf("other" to "other".toSpdx())
declaredLicenseMapping = mapOf("other" to "other".toSpdx()),
sourceCodeOrigins = listOf(SourceCodeOrigin.VCS)
)

"Merging" should {
Expand All @@ -92,7 +94,8 @@ class PackageCurationDataTest : WordSpec({
binaryArtifact = null,
vcs = null,
isMetadataOnly = null,
declaredLicenseMapping = emptyMap()
declaredLicenseMapping = emptyMap(),
sourceCodeOrigins = null
)

originalWithSomeUnsetData.merge(other) shouldBe originalWithSomeUnsetData.copy(
Expand All @@ -102,7 +105,8 @@ class PackageCurationDataTest : WordSpec({
binaryArtifact = other.binaryArtifact,
vcs = other.vcs,
isMetadataOnly = other.isMetadataOnly,
declaredLicenseMapping = other.declaredLicenseMapping
declaredLicenseMapping = other.declaredLicenseMapping,
sourceCodeOrigins = other.sourceCodeOrigins
)
}

Expand All @@ -123,7 +127,8 @@ class PackageCurationDataTest : WordSpec({
comment = original.comment,
authors = original.authors,
concludedLicense = original.concludedLicense,
declaredLicenseMapping = original.declaredLicenseMapping
declaredLicenseMapping = original.declaredLicenseMapping,
sourceCodeOrigins = original.sourceCodeOrigins
)

val mergedData = original.merge(otherWithSomeOriginalData)
Expand Down
5 changes: 4 additions & 1 deletion model/src/test/kotlin/PackageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class PackageTest : StringSpec({
sourceArtifact = RemoteArtifact("url", Hash.create("hash")),
vcs = VcsInfo(VcsType.forName("type"), "url", "revision"),
isMetadataOnly = false,
isModified = false
isModified = false,
sourceCodeOrigins = null
)

val other = Package(
Expand Down Expand Up @@ -83,6 +84,7 @@ class PackageTest : StringSpec({
diff.vcs shouldBe pkg.vcsProcessed.toCuration()
diff.isMetadataOnly shouldBe pkg.isMetadataOnly
diff.isModified shouldBe pkg.isModified
diff.sourceCodeOrigins shouldBe pkg.sourceCodeOrigins
}

"diff result does not contain unchanged values" {
Expand Down Expand Up @@ -112,5 +114,6 @@ class PackageTest : StringSpec({
diff.sourceArtifact should beNull()
diff.vcs should beNull()
diff.isMetadataOnly should beNull()
diff.sourceCodeOrigins should beNull()
}
})

0 comments on commit bf12184

Please sign in to comment.