From 7f61de72a03cbe3344a69baf2974ec288a9fda81 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Oct 2024 13:20:03 +0100 Subject: [PATCH] refactor(spdx): Move `nullOrBlankToSpdxNoassertionOrNone()` Because probably being the most natural string representation for an `SpdxExpression`, it makes sense to move that function to `spdx-utils`. Note that in order to continue working for `null`, it needs to stay an extension function and not just override `toString()` in `SpdxExpression`. Signed-off-by: Sebastian Schuberth --- plugins/reporters/spdx/src/main/kotlin/Extensions.kt | 11 +---------- utils/spdx/src/main/kotlin/Extensions.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/reporters/spdx/src/main/kotlin/Extensions.kt b/plugins/reporters/spdx/src/main/kotlin/Extensions.kt index 2a1fd29a30c3a..dd70e0d30f132 100644 --- a/plugins/reporters/spdx/src/main/kotlin/Extensions.kt +++ b/plugins/reporters/spdx/src/main/kotlin/Extensions.kt @@ -55,6 +55,7 @@ import org.ossreviewtoolkit.utils.spdx.model.SpdxExtractedLicenseInfo import org.ossreviewtoolkit.utils.spdx.model.SpdxFile import org.ossreviewtoolkit.utils.spdx.model.SpdxPackage import org.ossreviewtoolkit.utils.spdx.model.SpdxPackageVerificationCode +import org.ossreviewtoolkit.utils.spdx.nullOrBlankToSpdxNoassertionOrNone import org.ossreviewtoolkit.utils.spdx.toSpdx import org.ossreviewtoolkit.utils.spdx.toSpdxId @@ -251,16 +252,6 @@ internal fun SpdxDocument.addExtractedLicenseInfo(licenseTextProvider: LicenseTe return copy(hasExtractedLicensingInfos = extractedLicenseInfo) } -/** - * Convert an [SpdxExpression] to `NOASSERTION` if null, to `NONE` if blank, or to its string representation otherwise. - */ -private fun SpdxExpression?.nullOrBlankToSpdxNoassertionOrNone(): String = - when { - this == null -> SpdxConstants.NOASSERTION - toString().isBlank() -> SpdxConstants.NONE - else -> toString() - } - /** * Convert a null or blank [String] to `NONE`. */ diff --git a/utils/spdx/src/main/kotlin/Extensions.kt b/utils/spdx/src/main/kotlin/Extensions.kt index e8daa0c03b384..6658447ecc766 100644 --- a/utils/spdx/src/main/kotlin/Extensions.kt +++ b/utils/spdx/src/main/kotlin/Extensions.kt @@ -28,6 +28,16 @@ import org.ossreviewtoolkit.utils.spdx.SpdxExpression.Strictness private val logger = loggerOf(MethodHandles.lookup().lookupClass()) +/** + * Convert an [SpdxExpression] to `NOASSERTION` if null, to `NONE` if blank, or to its string representation otherwise. + */ +fun SpdxExpression?.nullOrBlankToSpdxNoassertionOrNone(): String = + when { + this == null -> SpdxConstants.NOASSERTION + toString().isBlank() -> SpdxConstants.NONE + else -> toString() + } + /** * Create an [SpdxLicenseIdExpression] from this [SpdxLicense]. */