From b3f6311609c2607fb670a5d9c154fbfcb5678149 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Mon, 15 Jul 2024 12:19:58 +0200 Subject: [PATCH] refactor(cocoapods): Use a data class for the `source` property When the `source` node contains boolean properties with unquoted values, such as [1], the deserialization of the source property to a `Map` with KxS fails by default. So, introduce a dedicated data class to prepare for migrating to KxS and to improve the readability. [1]: "source": { "git": "https://github.com/AFNetworking/AFNetworking.git", "tag": "3.2.1", "submodules": true } Signed-off-by: Frank Viernau --- .../cocoapods/src/main/kotlin/CocoaPods.kt | 6 +++--- .../cocoapods/src/main/kotlin/Podspec.kt | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt index 48037818a4ee4..8165b3260db54 100644 --- a/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt +++ b/plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt @@ -159,11 +159,11 @@ class CocoaPods( private fun getPackage(id: Identifier, workingDir: File): Package { val podspec = getPodspec(id, workingDir) ?: return Package.EMPTY.copy(id = id, purl = id.toPurl()) - val vcs = podspec.source["git"]?.let { url -> + val vcs = podspec.source?.git?.let { url -> VcsInfo( type = VcsType.GIT, url = url, - revision = podspec.source["tag"].orEmpty() + revision = podspec.source.tag.orEmpty() ) }.orEmpty() @@ -174,7 +174,7 @@ class CocoaPods( description = podspec.summary, homepageUrl = podspec.homepage, binaryArtifact = RemoteArtifact.EMPTY, - sourceArtifact = podspec.source["http"]?.let { RemoteArtifact(it, Hash.NONE) }.orEmpty(), + sourceArtifact = podspec.source?.http?.let { RemoteArtifact(it, Hash.NONE) }.orEmpty(), vcs = vcs, vcsProcessed = processPackageVcs(vcs, podspec.homepage) ) diff --git a/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt b/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt index c6d58a817c071..7a3af02ea9bce 100644 --- a/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt +++ b/plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt @@ -38,9 +38,16 @@ internal data class Podspec( val license: String = "", val summary: String = "", val homepage: String = "", - val source: Map = emptyMap(), + val source: Source? = null, private val subspecs: List = emptyList() ) { + @JsonIgnoreProperties(ignoreUnknown = true) + data class Source( + val git: String? = null, + val tag: String? = null, + val http: String? = null + ) + fun withSubspecs(): List { val result = mutableListOf()