Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reporter): Only write major / minor SPDX license list version info #9607

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private fun TestConfiguration.generateReport(

private fun SpdxDocument.getCustomReplacements() =
mapOf(
"<REPLACE_LICENSE_LIST_VERSION>" to SpdxLicense.LICENSE_LIST_VERSION.substringBefore("-"),
"<REPLACE_LICENSE_LIST_VERSION>" to SpdxLicense.LICENSE_LIST_VERSION.split('.').take(2).joinToString("."),
"<REPLACE_ORT_VERSION>" to Environment.ORT_VERSION,
"<REPLACE_CREATION_DATE_AND_TIME>" to creationInfo.created.toString(),
"<REPLACE_DOCUMENT_NAMESPACE>" to documentNamespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal object SpdxDocumentModelMapper {
comment = params.creationInfoComment,
created = Instant.now().truncatedTo(ChronoUnit.SECONDS),
creators = creators,
licenseListVersion = SpdxLicense.LICENSE_LIST_VERSION.substringBefore("-")
licenseListVersion = SpdxLicense.LICENSE_LIST_VERSION.split('.').take(2).joinToString(".")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution works, but it may be more efficient this other implementation, saving the splitting and joining back

Suggested change
licenseListVersion = SpdxLicense.LICENSE_LIST_VERSION.split('.').take(2).joinToString(".")
val licenseList = SpdxLicense.LICENSE_LIST_VERSION
licenseListVersion = licenseList.substring(0, licenseList.lastIndexOf("_"))

I do not really know much Kotlin, so take this with a pinch of salt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While lastIndexOf("_") would need to use "." instead, it would also not work for something like "1.2.3.4" as the input. Not that I'm expecting that to happen, but you never know 😉

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, otherwise I would have simply used substringBeforeLast('.').

),
documentNamespace = "spdx://${UUID.randomUUID()}",
documentDescribes = projectPackages.map { it.spdxId },
Expand Down
4 changes: 4 additions & 0 deletions utils/spdx/src/main/kotlin/model/SpdxCreationInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@
) {
init {
require(creators.isNotEmpty()) { "Creators must contain at least one entry, but was empty." }

require(licenseListVersion.isEmpty() || licenseListVersion.split('.').size == 2) {
"The license list version must contain exactly the major and minor parts."

Check warning on line 62 in utils/spdx/src/main/kotlin/model/SpdxCreationInfo.kt

View check run for this annotation

Codecov / codecov/patch

utils/spdx/src/main/kotlin/model/SpdxCreationInfo.kt#L62

Added line #L62 was not covered by tests
}
}
}
Loading