Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cacheinvalidationindex/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gradlePlugin {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(libs.jgrapht.core)
implementation(libs.jgrapht.io)

testImplementation(libs.junit)
testImplementation(libs.truth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ivanalvarado.cacheinvalidationindex
import com.ivanalvarado.cacheinvalidationindex.domain.usecase.AffectedSubgraphsImpl
import com.ivanalvarado.cacheinvalidationindex.domain.usecase.BuildDagFromDependencyPairsImpl
import com.ivanalvarado.cacheinvalidationindex.domain.usecase.FindDependencyPairsImpl
import com.ivanalvarado.cacheinvalidationindex.writer.GraphVizWriter
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.internal.configuration.problems.taskPathFrom
Expand All @@ -20,7 +21,8 @@ class CacheInvalidationIndexPlugin : Plugin<Project> {
CacheInvalidationIndexTask::class.java,
FindDependencyPairsImpl(),
BuildDagFromDependencyPairsImpl(),
AffectedSubgraphsImpl()
AffectedSubgraphsImpl(),
GraphVizWriter()
)
cacheInvalidationIndexTaskProvider.configure { task ->
task.configurationToAnalyze.set(extension.configurationToAnalyze)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ivanalvarado.cacheinvalidationindex
import com.ivanalvarado.cacheinvalidationindex.domain.usecase.AffectedSubgraphs
import com.ivanalvarado.cacheinvalidationindex.domain.usecase.BuildDagFromDependencyPairs
import com.ivanalvarado.cacheinvalidationindex.domain.usecase.FindDependencyPairs
import com.ivanalvarado.cacheinvalidationindex.writer.GraphVizWriter
import org.gradle.api.DefaultTask
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
Expand All @@ -12,7 +13,8 @@ import javax.inject.Inject
abstract class CacheInvalidationIndexTask @Inject constructor(
private val findDependencyPairs: FindDependencyPairs,
private val buildDagFromDependencyPairs: BuildDagFromDependencyPairs,
private val affectedSubgraphs: AffectedSubgraphs
private val affectedSubgraphs: AffectedSubgraphs,
private val graphVizWriter: GraphVizWriter
) : DefaultTask() {

@get:Input
Expand All @@ -23,10 +25,11 @@ abstract class CacheInvalidationIndexTask @Inject constructor(
val rootProject = project.rootProject
val configurationsToAnalyze = configurationToAnalyze.get()
val sampleList = findDependencyPairs(rootProject, configurationsToAnalyze)
println("Dependency Pairs: $sampleList")
val dag = buildDagFromDependencyPairs(sampleList)
println("DAG: $dag")
val affectedSubgraphs = affectedSubgraphs(dag)
println("Affected Subgraphs: $affectedSubgraphs")
graphVizWriter.writeGraph(
graph = affectedSubgraphs.find { it.node == project.path }!!.affectedDag,
file = project.file("build/graph.dot")
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ivanalvarado.cacheinvalidationindex.writer

import com.ivanalvarado.cacheinvalidationindex.domain.model.DependencyEdge
import org.jgrapht.graph.AbstractGraph
import org.jgrapht.nio.DefaultAttribute
import org.jgrapht.nio.dot.DOTExporter
import java.io.File

class GraphVizWriter {

fun writeGraph(graph: AbstractGraph<String, DependencyEdge>, file: File) {
val exporter = DOTExporter<String, DependencyEdge> { vertex ->
vertex.sanitize()
}

exporter.setVertexAttributeProvider { vertex ->
buildMap {
put("label", DefaultAttribute.createAttribute(vertex))
}
}

exporter.setEdgeAttributeProvider { edge ->
buildMap {
put("label", DefaultAttribute.createAttribute(edge.configuration))
}
}

file.delete()
exporter.exportGraph(graph, file)
}

private fun String.sanitize(): String {
return this.replace("-", "_")
.replace(".", "_")
.replace(":", "_")
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ truth = "1.4.4"

[libraries]
jgrapht-core = { group = "org.jgrapht", name = "jgrapht-core", version.ref = "jgrapht" }
jgrapht-io = { group = "org.jgrapht", name = "jgrapht-io", version.ref = "jgrapht" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }

Expand Down