From 023390a01915e6d473a522ecf5ca0953abcfaa50 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Tue, 12 Sep 2023 11:20:46 +0200 Subject: [PATCH] refactor(spdx): Add an overload for `toSpdxId()` Allow for passing just the `type` as alternative to passing `infix` and `suffix` separately, in order to avoid code redundancy in an upcoming change. Signed-off-by: Frank Viernau --- plugins/reporters/spdx/src/main/kotlin/Extensions.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/reporters/spdx/src/main/kotlin/Extensions.kt b/plugins/reporters/spdx/src/main/kotlin/Extensions.kt index 7d79ac7d2ba7a..bb3ffd1daccc4 100644 --- a/plugins/reporters/spdx/src/main/kotlin/Extensions.kt +++ b/plugins/reporters/spdx/src/main/kotlin/Extensions.kt @@ -81,6 +81,11 @@ internal fun Identifier.toSpdxId(infix: String = "Package", suffix: String = "") if (suffix.isNotEmpty()) append("-$suffix") }.toSpdxId() +/** + * Convert an [Identifier]'s coordinates to an SPDX reference ID for the specified [type]. + */ +internal fun Identifier.toSpdxId(type: SpdxPackageType): String = toSpdxId(type.infix, type.suffix) + /** * Get the text with all Copyright statements associated with the package of the given [id], or return `NONE` if there * are no associated Copyright statements. @@ -145,7 +150,7 @@ internal fun Package.toSpdxPackage( } return SpdxPackage( - spdxId = id.toSpdxId(type.infix, type.suffix), + spdxId = id.toSpdxId(type), checksums = when (type) { SpdxPackageType.BINARY_PACKAGE -> listOfNotNull(binaryArtifact.hash.toSpdxChecksum()) SpdxPackageType.SOURCE_PACKAGE -> listOfNotNull(sourceArtifact.hash.toSpdxChecksum())