Newer
Older
/*
* EDG, a library to generate and slice Expression Dependence Graphs.
* Copyright (c) 2021. David Insa, Sergio Pérez, Josep Silva, Salvador Tamarit.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package edg;
import java.io.File;
import java.util.List;
import java.util.Map;
import edg.config.Config;
import edg.graph.EDG;
import edg.graph.EdgeInfo;
import edg.graph.Node;
import misc.Misc;
import misc.util.Flusher;
public class PdfFactory
{
private static final Config config = Config.getConfig();
private static File getTempDotFile()
{
final String temporaryPath = PdfFactory.config.getTemporaryPath();
int temporaryPathIndex = 0;
while (true)
{
final String extraDotPath = temporaryPathIndex++ > 0 ? temporaryPathIndex + "" : "";
final String temporaryDotPath = temporaryPath + "temp" + extraDotPath + ".dot";
final File temporatyDotFile = new File(temporaryDotPath);
if (!temporatyDotFile.exists())
return temporatyDotFile;
}
}
public static void createPdf(File outputFile, EDG edg)
{
PdfFactory.createPdf(outputFile, edg, null, null, null);
}
public static void createPdf(File outputFile, EDG edg, Map<EdgeInfo.Type, Boolean> edgeFlags)
{
PdfFactory.createPdf(outputFile, edg, null, null, edgeFlags);
}
public static void createPdf(File outputFile, EDG edg, Node slicingCriterion, List<Node> slice)
{
PdfFactory.createPdf(outputFile, edg, slicingCriterion, slice, null);
}
public static void createPdf(File outputFile, EDG edg, Node slicingCriterion, List<Node> slice, Map<EdgeInfo.Type, Boolean> edgeFlags)
{
final File dotOutputFile = PdfFactory.getTempDotFile();
DotFactory.createDot(dotOutputFile, edg, slicingCriterion, slice, edgeFlags);
PdfFactory.createPdf(outputFile, dotOutputFile);
Misc.delete(dotOutputFile);
}
public static void createPdf(File outputFile, File dotFile)
{
try
{
final String dotPath = dotFile.getAbsolutePath();
final String outputPath = outputFile.getAbsolutePath();
final String command = "dot -Tpdf \"" + dotPath + "\" > \"" + outputPath + "\"";
final String path = "PATH=/usr/local/bin:" + System.getenv("PATH");
final Runtime runtime = Runtime.getRuntime();
final Process process = runtime.exec(new String[] { "/bin/sh", "-c", command }, new String[] { path }, null);
new Flusher(process).start();
process.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
}
private PdfFactory()
{
}
}