Skip to content

Commit

Permalink
fix(CocoaPods): Added Sub Dependency Tracking for CocoaPods
Browse files Browse the repository at this point in the history
Signed-off-by: ksg97031 <[email protected]>
  • Loading branch information
ksg97031 committed Sep 21, 2023
1 parent e40c142 commit 9267139
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class CocoaPods(

val podspecCommand = runCatching {
run(
"spec", "which", podspecName,
"spec", "which", "^$podspecName$",
"--version=${id.version}",
"--allow-root",
"--regex",
Expand Down Expand Up @@ -233,9 +233,6 @@ private val NAME_AND_VERSION_REGEX = "(\\S+)\\s+(.*)".toRegex()

private fun getPackageReferences(podfileLock: File): Set<PackageReference> {
val versionForName = mutableMapOf<String, String>()
val dependenciesForName = mutableMapOf<String, MutableSet<String>>()
val root = yamlMapper.readTree(podfileLock)

root.get("PODS").asIterable().forEach { node ->
val entry = when (node) {
is ObjectNode -> node.fieldNames().asSequence().first()

Check warning on line 238 in plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Constant conditions

'when' branch is never reachable
Expand All @@ -247,8 +244,29 @@ private fun getPackageReferences(podfileLock: File): Set<PackageReference> {
}
versionForName[name] = version

val dependencies = node[entry]?.map { it.textValue().substringBefore(" ") }.orEmpty()
val dependencies = node[entry]?.map { it.textValue().substringBefore(" ") }.orEmpty()
dependenciesForName.getOrPut(name) { mutableSetOf() } += dependencies

// If this node has sub dependencies, append them to the dependency tracking.
// Sub dependencies are additional dependencies that are required.
// For more details, refer to issue #7523.
if (node is ObjectNode) {

Check warning on line 253 in plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Constant conditions

Condition 'node is ObjectNode' is always false
val subEntries = node[entry].map { it.textValue() }
subEntries.filter { it.contains("(= ") }.forEach { subEntry ->
val (subDependencyName, subDependencyVersion) = NAME_AND_VERSION_REGEX.find(subEntry)!!.groups.let {
it[1]!!.value to it[2]!!.value.removeSurrounding("(= ", ")")
}

// Add sub dependency if it's not already tracked
if (!versionForName.containsKey(subDependencyName)) {
versionForName[subDependencyName] = subDependencyVersion

val subDependencies = node[subEntry]?.map { it.textValue().substringBefore(" ") }.orEmpty()
dependenciesForName.getOrPut(subDependencyName) { mutableSetOf() } += subDependencies
}
}
}
}
}

fun createPackageReference(name: String): PackageReference =
Expand Down

0 comments on commit 9267139

Please sign in to comment.