Skip to content

Commit 05b57b9

Browse files
jjohannessschuberth
authored andcommitted
fix(DependencyGraphBuilder): Skip deep comparison for Gradle projects
This is unnecessary and leads to a long runtime (and possible an infinite loop / recursion) for large dependency graphs as observed in Signed-off-by: Jendrik Johannes <[email protected]>
1 parent e67ecbd commit 05b57b9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

model/src/main/kotlin/utils/DependencyGraphBuilder.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,19 @@ class DependencyGraphBuilder<D>(
331331
val dependencies = dependencyHandler.dependenciesFor(dependency)
332332
if (ref.dependencies.size != dependencies.size) return false
333333

334-
val dependencies1 = ref.dependencies.map { dependencyIds[it.pkg] }
334+
val dependencies1 = ref.dependencies.mapTo(mutableSetOf()) { dependencyIds[it.pkg] }
335335
val dependencies2 = dependencies.associateBy { dependencyHandler.identifierFor(it) }
336-
if (!dependencies2.keys.containsAll(dependencies1)) return false
336+
337+
if (dependencies1 == dependencies2.keys) {
338+
// It is not possible to check for the class instance here as the type comes from a plugin.
339+
if (dependencyHandler.javaClass.simpleName == "GradleDependencyHandler") {
340+
// In case of Gradle, the costly deep comparison can be skipped, because if the direct dependencies are
341+
// the same, their children are also the same.
342+
return true
343+
}
344+
} else {
345+
return false
346+
}
337347

338348
return ref.dependencies.all { refDep ->
339349
dependencies2[dependencyIds[refDep.pkg]]?.let { dependencyTreeEquals(refDep, it) } == true

0 commit comments

Comments
 (0)