Skip to content

Commit

Permalink
promote CCGraphViewBuilder to be the only GraphViewBuilder
Browse files Browse the repository at this point in the history
* delete the non CC compatible GraphViewBuilder
* rename the CCGraphViewBuilder to drop the CC prefix

Signed-off-by: Christoph Obexer <cobexer@gradle.com>
Co-authored-by: Louis Jacomet <louis@gradle.com>
  • Loading branch information
2 people authored and autonomousapps committed Dec 9, 2023
1 parent ff4f700 commit 424e0fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 98 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.autonomousapps.internal.graph

import com.autonomousapps.internal.isJavaPlatform
import com.autonomousapps.internal.utils.mapNotNullToSet
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.Configuration
import org.gradle.api.artifacts.FileCollectionDependency
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. */
/**
* Walks the resolved dependency graph to create a dependency graph rooted on the current project in a configuration
* cache-compatible way.
*/
@Suppress("UnstableApiUsage") // Guava Graph
internal class GraphViewBuilder(conf: Configuration) {
internal class GraphViewBuilder(
root: ResolvedComponentResult,
fileCoordinates: Set<Coordinates>,
) {

val graph: Graph<Coordinates>

Expand All @@ -23,29 +26,21 @@ internal class GraphViewBuilder(conf: Configuration) {
private val visited = mutableSetOf<Coordinates>()

init {
val root = conf
.incoming
.resolutionResult
.root
val rootId = root.rootCoordinates()

val rootId = conf.rootCoordinates()

walkFileDeps(conf, rootId)
walkFileDeps(fileCoordinates, rootId)
walk(root, rootId)

graph = graphBuilder.build()
}

private fun walkFileDeps(conf: Configuration, rootId: Coordinates) {
private fun walkFileDeps(fileCoordinates: Set<Coordinates>, rootId: Coordinates) {
graphBuilder.addNode(rootId)

// the only way to get flat jar file dependencies
conf.allDependencies
.filterIsInstance<FileCollectionDependency>()
.mapNotNullToSet { it.toCoordinates() }
.forEach { id ->
graphBuilder.putEdge(rootId, id)
}
fileCoordinates.forEach { id ->
graphBuilder.putEdge(rootId, id)
}
}

private fun walk(root: ResolvedComponentResult, rootId: Coordinates) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/autonomousapps/tasks/GraphViewTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.autonomousapps.tasks

import com.autonomousapps.TASK_GROUP_DEP_INTERNAL
import com.autonomousapps.internal.externalArtifactsFor
import com.autonomousapps.internal.graph.CCGraphViewBuilder
import com.autonomousapps.internal.graph.GraphViewBuilder
import com.autonomousapps.internal.graph.GraphWriter
import com.autonomousapps.internal.utils.bufferWriteJson
import com.autonomousapps.internal.utils.getAndDelete
Expand Down Expand Up @@ -136,14 +136,14 @@ abstract class GraphViewTask : DefaultTask() {
val outputRuntime = outputRuntime.getAndDelete()
val outputRuntimeDot = outputRuntimeDot.getAndDelete()

val compileGraph = CCGraphViewBuilder(compileClasspathResult.get(), compileClasspathFileCoordinates.get()).graph
val compileGraph = GraphViewBuilder(compileClasspathResult.get(), compileClasspathFileCoordinates.get()).graph
val compileGraphView = DependencyGraphView(
variant = Variant(variant.get(), kind.get()),
configurationName = compileClasspathName.get(),
graph = compileGraph
)

val runtimeGraph = CCGraphViewBuilder(runtimeClasspathResult.get(), runtimeClasspathFileCoordinates.get()).graph
val runtimeGraph = GraphViewBuilder(runtimeClasspathResult.get(), runtimeClasspathFileCoordinates.get()).graph
val runtimeGraphView = DependencyGraphView(
variant = Variant(variant.get(), kind.get()),
configurationName = runtimeClasspathName.get(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.autonomousapps.tasks

import com.autonomousapps.internal.externalArtifactsFor
import com.autonomousapps.internal.graph.CCGraphViewBuilder
import com.autonomousapps.internal.graph.GraphViewBuilder
import com.autonomousapps.internal.utils.getAndDelete
import com.autonomousapps.internal.utils.mapNotNullToSet
import com.autonomousapps.internal.utils.toCoordinates
Expand Down Expand Up @@ -77,8 +77,8 @@ abstract class ResolveExternalDependenciesTask : DefaultTask() {
@TaskAction fun action() {
val output = output.getAndDelete()

val compileGraph = CCGraphViewBuilder(compileClasspathResult.get(), compileClasspathFileCoordinates.get()).graph
val runtimeGraph = CCGraphViewBuilder(runtimeClasspathResult.get(), runtimeClasspathFileCoordinates.get()).graph
val compileGraph = GraphViewBuilder(compileClasspathResult.get(), compileClasspathFileCoordinates.get()).graph
val runtimeGraph = GraphViewBuilder(runtimeClasspathResult.get(), runtimeClasspathFileCoordinates.get()).graph

val dependencies = compileGraph.nodes().asSequence().plus(runtimeGraph.nodes().asSequence())
.filterIsInstance<ModuleCoordinates>()
Expand Down

0 comments on commit 424e0fb

Please sign in to comment.