-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ResolveExternalDependencies is configuration-cache compatible.
This is a first step towards making the rest of the plugin compatible.
- Loading branch information
1 parent
83bd478
commit ea94054
Showing
7 changed files
with
165 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/kotlin/com/autonomousapps/internal/graph/CCGraphViewBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.autonomousapps.internal.graph | ||
|
||
import com.autonomousapps.internal.isJavaPlatform | ||
import com.autonomousapps.internal.utils.rootCoordinates | ||
import com.autonomousapps.internal.utils.toCoordinates | ||
import com.autonomousapps.model.Coordinates | ||
import com.autonomousapps.model.DependencyGraphView | ||
import com.google.common.graph.Graph | ||
import org.gradle.api.artifacts.result.ResolvedComponentResult | ||
import org.gradle.api.artifacts.result.ResolvedDependencyResult | ||
|
||
/** | ||
* Walks the resolved dependency graph to create a dependency graph rooted on the current project in a configuration | ||
* cache-compatible way. | ||
* | ||
* Ultimately a replacement for [GraphViewBuilder]. | ||
*/ | ||
@Suppress("UnstableApiUsage") // Guava Graph | ||
internal class CCGraphViewBuilder( | ||
root: ResolvedComponentResult, | ||
fileCoordinates: Set<Coordinates>, | ||
) { | ||
|
||
val graph: Graph<Coordinates> | ||
|
||
private val graphBuilder = DependencyGraphView.newGraphBuilder() | ||
|
||
private val visited = mutableSetOf<Coordinates>() | ||
|
||
init { | ||
val rootId = root.rootCoordinates() | ||
|
||
walkFileDeps(fileCoordinates, rootId) | ||
walk(root, rootId) | ||
|
||
graph = graphBuilder.build() | ||
} | ||
|
||
private fun walkFileDeps(fileCoordinates: Set<Coordinates>, rootId: Coordinates) { | ||
graphBuilder.addNode(rootId) | ||
|
||
// the only way to get flat jar file dependencies | ||
fileCoordinates.forEach { id -> | ||
graphBuilder.putEdge(rootId, id) | ||
} | ||
} | ||
|
||
private fun walk(root: ResolvedComponentResult, rootId: Coordinates) { | ||
root.dependencies | ||
.filterIsInstance<ResolvedDependencyResult>() | ||
// AGP adds all runtime dependencies as constraints to the compile classpath, and these show | ||
// up in the resolution result. Filter them out. | ||
.filterNot { it.isConstraint } | ||
// For similar reasons as above | ||
.filterNot { it.isJavaPlatform() } | ||
// Sometimes there is a self-dependency? | ||
.filterNot { it.selected == root } | ||
.forEach { dependencyResult -> | ||
// Might be from an included build, in which case the coordinates reflect the _requested_ dependency instead of | ||
// the _resolved_ dependency. | ||
val depId = dependencyResult.toCoordinates() | ||
|
||
// add an edge | ||
graphBuilder.putEdge(rootId, depId) | ||
|
||
if (!visited.contains(depId)) { | ||
visited.add(depId) | ||
// recursively walk the graph in a depth-first pattern | ||
walk(dependencyResult.selected, depId) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.