From 9a7e87c2c5d8ffc660cb4359eae40a6d8a95a242 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Wed, 8 Jan 2020 18:12:08 +0100 Subject: [PATCH] Remove guru.nidi.graphviz-java library Fixes #8 --- pom.xml | 6 ----- src/main/java/tfm/exec/CFGLog.java | 7 ----- src/main/java/tfm/exec/GraphLog.java | 39 ++++++++++++++++++++++------ src/main/java/tfm/exec/PDGLog.java | 1 - 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 71c6c4f..2963592 100644 --- a/pom.xml +++ b/pom.xml @@ -35,12 +35,6 @@ compile - - guru.nidi - graphviz-java - 0.8.3 - - org.jgrapht jgrapht-core diff --git a/src/main/java/tfm/exec/CFGLog.java b/src/main/java/tfm/exec/CFGLog.java index ebd6b2f..e04a483 100644 --- a/src/main/java/tfm/exec/CFGLog.java +++ b/src/main/java/tfm/exec/CFGLog.java @@ -1,16 +1,9 @@ package tfm.exec; import com.github.javaparser.ast.Node; -import guru.nidi.graphviz.engine.Format; -import guru.nidi.graphviz.engine.Graphviz; import tfm.graphs.CFGGraph; -import tfm.utils.FileUtil; import tfm.visitors.cfg.CFGBuilder; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - public class CFGLog extends GraphLog { public CFGLog() { diff --git a/src/main/java/tfm/exec/GraphLog.java b/src/main/java/tfm/exec/GraphLog.java index 5a9db09..a3d38fa 100644 --- a/src/main/java/tfm/exec/GraphLog.java +++ b/src/main/java/tfm/exec/GraphLog.java @@ -1,16 +1,26 @@ package tfm.exec; import com.github.javaparser.ast.Node; -import guru.nidi.graphviz.engine.Format; -import guru.nidi.graphviz.engine.Graphviz; import tfm.graphs.Graph; import tfm.utils.FileUtil; import tfm.utils.Logger; -import java.io.File; -import java.io.IOException; +import java.io.*; public abstract class GraphLog { + public enum Format { + PNG("png"), + PDF("pdf"); + + private String ext; + Format(String ext) { + this.ext = ext; + } + + public String getExt() { + return ext; + } + } static final String CFG = "cfg"; static final String PDG = "pdg"; @@ -61,9 +71,22 @@ public abstract class GraphLog { this.imageName = imageName; this.format = format; generated = true; - Graphviz.fromString(graph.toGraphvizRepresentation()) - .render(format) - .toFile(getImageFile()); + File tmpDot = File.createTempFile("graph-source-", ".dot"); + tmpDot.deleteOnExit(); + try (Writer w = new FileWriter(tmpDot)) { + w.write(graph.toGraphvizRepresentation()); + } + ProcessBuilder pb = new ProcessBuilder("dot", + tmpDot.getAbsolutePath(), "-T" + format.getExt(), + "-o", getImageFile().getAbsolutePath()); + try { + int result = pb.start().waitFor(); + if (result != 0) { + Logger.log("Image generation failed"); + } + } catch (InterruptedException e) { + Logger.log("Image generation failed\n" + e.getMessage()); + } } public void openVisualRepresentation() throws IOException { @@ -72,6 +95,6 @@ public abstract class GraphLog { } protected File getImageFile() { - return new File("./out/" + imageName + "." + format.name()); + return new File("./out/" + imageName + "." + format.getExt()); } } diff --git a/src/main/java/tfm/exec/PDGLog.java b/src/main/java/tfm/exec/PDGLog.java index a3efaec..a712abe 100644 --- a/src/main/java/tfm/exec/PDGLog.java +++ b/src/main/java/tfm/exec/PDGLog.java @@ -1,6 +1,5 @@ package tfm.exec; -import guru.nidi.graphviz.engine.Format; import tfm.graphs.PDGGraph; import tfm.nodes.GraphNode; import tfm.utils.Logger; -- GitLab