Skip to content

Commit

Permalink
refactor(cocoapods): Use a data class for the source property
Browse files Browse the repository at this point in the history
When the `source` node contains boolean properties with unquoted values,
such as [1], the deserialization of the source property to a
`Map<String, String>` 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 <[email protected]>
  • Loading branch information
fviernau committed Jul 15, 2024
1 parent 26c31cf commit b3f6311
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ internal data class Podspec(
val license: String = "",
val summary: String = "",
val homepage: String = "",
val source: Map<String, String> = emptyMap(),
val source: Source? = null,
private val subspecs: List<Podspec> = emptyList()
) {
@JsonIgnoreProperties(ignoreUnknown = true)
data class Source(
val git: String? = null,
val tag: String? = null,
val http: String? = null
)

fun withSubspecs(): List<Podspec> {
val result = mutableListOf<Podspec>()

Expand Down

0 comments on commit b3f6311

Please sign in to comment.