Skip to content

Commit

Permalink
refactor(cocoapods): Factor out parsePodspec()
Browse files Browse the repository at this point in the history
Prepare for migrating the parsing to KxS.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Jul 15, 2024
1 parent 634f145 commit d4a1741
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugins/package-managers/cocoapods/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -211,9 +210,9 @@ class CocoaPods(
return null
}

val podspecFile = File(podspecCommand.stdout.trim())
val podspec = File(podspecCommand.stdout.trim()).readText().parsePodspec()

podspecFile.readValue<Podspec>().withSubspecs().associateByTo(podspecCache) { it.name }
podspec.withSubspecs().associateByTo(podspecCache) { it.name }

return podspecCache.getValue(id.name)
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/package-managers/cocoapods/src/main/kotlin/Podspec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -54,6 +56,8 @@ internal data class Podspec(
}
}

internal fun String.parsePodspec(): Podspec = jsonMapper.readValue<Podspec>(this)

/**
* Handle deserialization of the following two possible representations:
*
Expand Down

0 comments on commit d4a1741

Please sign in to comment.