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/>.
*/
import java.io.IOException;
import edg.graph.Node;
import misc.Misc;
import misc.util.Flusher;
public class PdfFactory
{
public static void createPdf(File outputFile, EDG edg)
{
PdfFactory.createPdf(outputFile, edg, null, null, null);
}
public static void createPdf(File outputFile, EDG edg, Map<Edge.Type, Boolean> edgeFlags)
{
PdfFactory.createPdf(outputFile, edg, null, null, edgeFlags);
}
public static void createPdf(File outputFile, EDG edg, Node slicingCriterion, Set<Node> slice)
{
PdfFactory.createPdf(outputFile, edg, slicingCriterion, slice, null);
}
public static void createPdf(File outputFile, EDG edg, Node slicingCriterion, Set<Node> slice, Map<Edge.Type, Boolean> edgeFlags)
final File dotOutputFile;
try {
dotOutputFile = File.createTempFile("PdfFactory-graph", ".dot");
} catch (IOException e) {
e.printStackTrace();
return;
}
DotFactory.createDot(dotOutputFile, edg, slicingCriterion, slice, edgeFlags);
PdfFactory.createPdf(outputFile, dotOutputFile);
public static void createPdf(File outputFile, File dotFile)
{
try
{
final String dotPath = dotFile.getAbsolutePath();
final String outputPath = outputFile.getAbsolutePath();
final Process process = new ProcessBuilder()
.command("dot", "-Tpdf", "-o", outputPath, dotPath)
.inheritIO()
.start();
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
int result = process.waitFor();
if (result != 0)
throw new Exception("Error generating pdf from dot file, exit code: " + result);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void createSvg(File outputFile, EDG edg, Node slicingCriterion, Set<Node> slice)
{
PdfFactory.createSvg(outputFile, edg, slicingCriterion, slice, null);
}
public static void createSvg(File outputFile, EDG edg, Node slicingCriterion, Set<Node> slice, Map<Edge.Type, Boolean> edgeFlags)
{
final File dotOutputFile;
try {
dotOutputFile = File.createTempFile("PdfFactory-graph", ".dot");
} catch (IOException e) {
e.printStackTrace();
return;
}
DotFactory.createDot(dotOutputFile, edg, slicingCriterion, slice, edgeFlags);
PdfFactory.createSvg(outputFile, dotOutputFile);
dotOutputFile.delete();
}
public static void createSvg(File outputFile, File dotFile)
{
try
{
final String dotPath = dotFile.getAbsolutePath();
final String outputPath = outputFile.getAbsolutePath();
final Process process = new ProcessBuilder()
.command("dot", "-Tsvg", "-o", outputPath, dotPath)
.inheritIO()
.start();
int result = process.waitFor();
if (result != 0)
throw new Exception("Error generating pdf from dot file, exit code: " + result);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private PdfFactory()
{