From d4a17414ea9b67f32f009abe69d5440c185ebe78 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Mon, 15 Jul 2024 09:11:24 +0200 Subject: [PATCH] refactor(cocoapods): Factor out `parsePodspec()` Prepare for migrating the parsing to KxS. Signed-off-by: Frank Viernau --- plugins/package-managers/cocoapods/build.gradle.kts | 1 + .../package-managers/cocoapods/src/main/kotlin/CocoaPods.kt | 5 ++--- .../package-managers/cocoapods/src/main/kotlin/Podspec.kt | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/package-managers/cocoapods/build.gradle.kts b/plugins/package-managers/cocoapods/build.gradle.kts index 20efd5569cdb8..3d753ab5c88dc 100644 --- a/plugins/package-managers/cocoapods/build.gradle.kts +++ b/plugins/package-managers/cocoapods/build.gradle.kts @@ -41,6 +41,7 @@ dependencies { implementation(libs.jackson.core) implementation(libs.jackson.databind) implementation(libs.jackson.dataformat.yaml) + implementation(libs.jackson.module.kotlin) funTestImplementation(testFixtures(projects.analyzer)) } diff --git a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt index f647500d94b3a..869bd4abd0a3b 100644 --- a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt +++ b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt @@ -44,7 +44,6 @@ import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.model.createAndLogIssue import org.ossreviewtoolkit.model.orEmpty -import org.ossreviewtoolkit.model.readValue import org.ossreviewtoolkit.model.utils.toPurl import org.ossreviewtoolkit.model.yamlMapper import org.ossreviewtoolkit.utils.common.CommandLineTool @@ -211,9 +210,9 @@ class CocoaPods( return null } - val podspecFile = File(podspecCommand.stdout.trim()) + val podspec = File(podspecCommand.stdout.trim()).readText().parsePodspec() - podspecFile.readValue().withSubspecs().associateByTo(podspecCache) { it.name } + podspec.withSubspecs().associateByTo(podspecCache) { it.name } return podspecCache.getValue(id.name) } diff --git a/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt b/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt index f0cd5639ecea0..c6d58a817c071 100644 --- a/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt +++ b/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt @@ -25,7 +25,9 @@ import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer +import com.fasterxml.jackson.module.kotlin.readValue +import org.ossreviewtoolkit.model.jsonMapper import org.ossreviewtoolkit.utils.common.textValueOrEmpty @JsonIgnoreProperties(ignoreUnknown = true) @@ -54,6 +56,8 @@ internal data class Podspec( } } +internal fun String.parsePodspec(): Podspec = jsonMapper.readValue(this) + /** * Handle deserialization of the following two possible representations: *