Skip to content

Commit 7819962

Browse files
authored
Output the dependency graph in png format with graphviz-java (#7)
1 parent c39cad3 commit 7819962

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

cacheinvalidationindex/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ gradlePlugin {
1818

1919
dependencies {
2020
implementation(kotlin("stdlib-jdk8"))
21+
implementation(libs.graphviz.java)
2122
implementation(libs.jgrapht.core)
2223
implementation(libs.jgrapht.io)
2324

cacheinvalidationindex/src/main/java/com/ivanalvarado/cacheinvalidationindex/CacheInvalidationIndexTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class CacheInvalidationIndexTask @Inject constructor(
2929
val affectedSubgraphs = affectedSubgraphs(dag)
3030
graphVizWriter.writeGraph(
3131
graph = affectedSubgraphs.find { it.node == project.path }!!.affectedDag,
32-
file = project.file("build/graph.dot")
32+
file = project.file("build/cacheinvalidationindex/dependency_graph.png")
3333
)
3434
}
3535
}

cacheinvalidationindex/src/main/java/com/ivanalvarado/cacheinvalidationindex/writer/GraphVizWriter.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.ivanalvarado.cacheinvalidationindex.writer
22

33
import com.ivanalvarado.cacheinvalidationindex.domain.model.DependencyEdge
4+
import guru.nidi.graphviz.engine.Format
5+
import guru.nidi.graphviz.engine.Graphviz
46
import org.jgrapht.graph.AbstractGraph
57
import org.jgrapht.nio.DefaultAttribute
68
import org.jgrapht.nio.dot.DOTExporter
79
import java.io.File
10+
import java.io.StringWriter
811

912
class GraphVizWriter {
1013

@@ -25,8 +28,14 @@ class GraphVizWriter {
2528
}
2629
}
2730

31+
val writer = StringWriter()
32+
exporter.exportGraph(graph, writer)
33+
val dotString = writer.toString()
34+
2835
file.delete()
29-
exporter.exportGraph(graph, file)
36+
Graphviz.fromString(dotString)
37+
.render(Format.PNG)
38+
.toFile(file)
3039
}
3140

3241
private fun String.sanitize(): String {

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[versions]
2+
graphviz-java = "0.18.1"
23
jetbrainsKotlinJvm = "1.9.24"
34
jgrapht = "1.5.1"
45
junit = "4.13.2"
56
truth = "1.4.4"
67

78
[libraries]
9+
graphviz-java = { group = "guru.nidi", name = "graphviz-java", version.ref = "graphviz-java" }
810
jgrapht-core = { group = "org.jgrapht", name = "jgrapht-core", version.ref = "jgrapht" }
911
jgrapht-io = { group = "org.jgrapht", name = "jgrapht-io", version.ref = "jgrapht" }
1012
junit = { group = "junit", name = "junit", version.ref = "junit" }

0 commit comments

Comments
 (0)