Skip to content

Commit 1a40875

Browse files
authored
Merge pull request #11 from jacosro/8-remove-graphviz-lib
Remove guru.nidi.graphviz-java library
2 parents 2183fed + 9a7e87c commit 1a40875

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
<scope>compile</scope>
3636
</dependency>
3737

38-
<dependency>
39-
<groupId>guru.nidi</groupId>
40-
<artifactId>graphviz-java</artifactId>
41-
<version>0.8.3</version>
42-
</dependency>
43-
4438
<dependency>
4539
<groupId>org.jgrapht</groupId>
4640
<artifactId>jgrapht-core</artifactId>

src/main/java/tfm/exec/CFGLog.java

-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
package tfm.exec;
22

33
import com.github.javaparser.ast.Node;
4-
import guru.nidi.graphviz.engine.Format;
5-
import guru.nidi.graphviz.engine.Graphviz;
64
import tfm.graphs.CFGGraph;
7-
import tfm.utils.FileUtil;
85
import tfm.visitors.cfg.CFGBuilder;
96

10-
import java.io.File;
11-
import java.io.IOException;
12-
import java.util.Arrays;
13-
147
public class CFGLog extends GraphLog<CFGGraph> {
158

169
public CFGLog() {

src/main/java/tfm/exec/GraphLog.java

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
package tfm.exec;
22

33
import com.github.javaparser.ast.Node;
4-
import guru.nidi.graphviz.engine.Format;
5-
import guru.nidi.graphviz.engine.Graphviz;
64
import tfm.graphs.Graph;
75
import tfm.utils.FileUtil;
86
import tfm.utils.Logger;
97

10-
import java.io.File;
11-
import java.io.IOException;
8+
import java.io.*;
129

1310
public abstract class GraphLog<G extends Graph> {
11+
public enum Format {
12+
PNG("png"),
13+
PDF("pdf");
14+
15+
private String ext;
16+
Format(String ext) {
17+
this.ext = ext;
18+
}
19+
20+
public String getExt() {
21+
return ext;
22+
}
23+
}
1424

1525
static final String CFG = "cfg";
1626
static final String PDG = "pdg";
@@ -61,9 +71,22 @@ public void generateImages(String imageName, Format format) throws IOException {
6171
this.imageName = imageName;
6272
this.format = format;
6373
generated = true;
64-
Graphviz.fromString(graph.toGraphvizRepresentation())
65-
.render(format)
66-
.toFile(getImageFile());
74+
File tmpDot = File.createTempFile("graph-source-", ".dot");
75+
tmpDot.deleteOnExit();
76+
try (Writer w = new FileWriter(tmpDot)) {
77+
w.write(graph.toGraphvizRepresentation());
78+
}
79+
ProcessBuilder pb = new ProcessBuilder("dot",
80+
tmpDot.getAbsolutePath(), "-T" + format.getExt(),
81+
"-o", getImageFile().getAbsolutePath());
82+
try {
83+
int result = pb.start().waitFor();
84+
if (result != 0) {
85+
Logger.log("Image generation failed");
86+
}
87+
} catch (InterruptedException e) {
88+
Logger.log("Image generation failed\n" + e.getMessage());
89+
}
6790
}
6891

6992
public void openVisualRepresentation() throws IOException {
@@ -72,6 +95,6 @@ public void openVisualRepresentation() throws IOException {
7295
}
7396

7497
protected File getImageFile() {
75-
return new File("./out/" + imageName + "." + format.name());
98+
return new File("./out/" + imageName + "." + format.getExt());
7699
}
77100
}

src/main/java/tfm/exec/PDGLog.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package tfm.exec;
22

3-
import guru.nidi.graphviz.engine.Format;
43
import tfm.graphs.PDGGraph;
54
import tfm.nodes.GraphNode;
65
import tfm.utils.Logger;

0 commit comments

Comments
 (0)