diff --git a/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt b/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt index a8f90f11e136d..a4a6377a9db10 100644 --- a/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt +++ b/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt @@ -64,13 +64,7 @@ class ClearlyDefinedServiceFunTest : WordSpec({ "return single curation data" { val service = ClearlyDefinedService.create() - val curation = service.getCuration( - coordinates.type, - coordinates.provider, - coordinates.namespace ?: "-", - coordinates.name, - coordinates.revision.orEmpty() - ) + val curation = service.getCuration(coordinates) curation.licensed?.declared shouldBe "CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0" } diff --git a/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt b/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt index 59ffc9b4f380b..df1a936ba9343 100644 --- a/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt +++ b/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt @@ -289,6 +289,28 @@ interface ClearlyDefinedService { ): ResponseBody } +suspend fun ClearlyDefinedService.getCuration(coordinates: Coordinates): Curation = + @Suppress("DestructuringDeclarationWithTooManyEntries") + coordinates.strings.let { (_, _, namespace, name, revision) -> + getCuration(coordinates.type, coordinates.provider, namespace, name, revision) + } + +suspend fun ClearlyDefinedService.harvestTools(coordinates: Coordinates): List = + @Suppress("DestructuringDeclarationWithTooManyEntries") + coordinates.strings.let { (_, _, namespace, name, revision) -> + harvestTools(coordinates.type, coordinates.provider, namespace, name, revision) + } + +suspend fun ClearlyDefinedService.harvestToolData( + coordinates: Coordinates, + tool: String, + toolVersion: String +): ResponseBody = + @Suppress("DestructuringDeclarationWithTooManyEntries") + coordinates.strings.let { (_, _, namespace, name, revision) -> + harvestToolData(coordinates.type, coordinates.provider, namespace, name, revision, tool, toolVersion) + } + suspend fun ClearlyDefinedService.call(block: suspend ClearlyDefinedService.() -> T): T = try { block() diff --git a/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt b/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt index 454c6c6c5a762..019b85801a8f9 100644 --- a/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt +++ b/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt @@ -33,6 +33,8 @@ import org.apache.logging.log4j.kotlin.logger import org.ossreviewtoolkit.clients.clearlydefined.ClearlyDefinedService import org.ossreviewtoolkit.clients.clearlydefined.ComponentType import org.ossreviewtoolkit.clients.clearlydefined.Coordinates +import org.ossreviewtoolkit.clients.clearlydefined.harvestToolData +import org.ossreviewtoolkit.clients.clearlydefined.harvestTools import org.ossreviewtoolkit.clients.clearlydefined.toCoordinates import org.ossreviewtoolkit.downloader.VcsHost import org.ossreviewtoolkit.model.ArtifactProvenance @@ -102,13 +104,7 @@ class ClearlyDefinedStorage( return runCatching { logger.debug { "Looking up ClearlyDefined scan results for '$coordinates'." } - val tools = service.harvestTools( - coordinates.type, - coordinates.provider, - coordinates.namespace ?: "-", - coordinates.name, - coordinates.revision.orEmpty() - ) + val tools = service.harvestTools(coordinates) val toolVersionsByName = tools.mapNotNull { it.withoutPrefix("$coordinates/") } .groupBy({ it.substringBefore('/') }, { it.substringAfter('/') }) @@ -181,16 +177,7 @@ class ClearlyDefinedStorage( * and return it as a [JsonNode]. */ private suspend fun loadToolData(coordinates: Coordinates, name: String, version: String): JsonNode { - val toolData = service.harvestToolData( - coordinates.type, - coordinates.provider, - coordinates.namespace ?: "-", - coordinates.name, - coordinates.revision.orEmpty(), - name, - version - ) - + val toolData = service.harvestToolData(coordinates, name, version) return toolData.use { jsonMapper.readTree(it.byteStream()) } }