use of org.eclipse.elk.core.util.WrappedException in project elk by eclipse.
the class GraphvizTool method initialize.
/**
* Initialize the Graphviz tool instance by starting the dot process and the watcher
* thread as necessary. The given command line arguments are appended to the default
* arguments.
*
* @param arguments command line arguments to be added to the default list of arguments.
* May be {@code null} or empty.
*/
public synchronized void initialize(final List<String> arguments) {
if (watchdog == null) {
// start the watcher thread for timeout checking
watchdog = new Watchdog();
watchdog.setName("Graphviz Watchdog");
watchdog.start();
}
if (process == null) {
String dotExecutable = getDotExecutable();
// assemble the final list of command-line arguments
List<String> args = Lists.newArrayList(dotExecutable, ARG_NOWARNINGS, ARG_INVERTYAXIS, ARG_COMMAND + command);
if (arguments != null) {
args.addAll(arguments);
}
// create the process
try {
process = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
} catch (IOException exception) {
throw new WrappedException("Failed to start Graphviz process." + " Please check your Graphviz installation.", exception);
}
}
}
use of org.eclipse.elk.core.util.WrappedException in project elk by eclipse.
the class GmfLayoutEditPolicy method handleSplineConnection.
/**
* Handle the ELK SplineConnection class without a direct reference to it. Reflection is used
* to avoid a dependency to its containing plugin.
*
* @param edgeFigure
* the edge figure instance
* @param edgeRouting
* the edge routing returned by the layout algorithm
* @return {@code true} if an approximation should be used to represent the spline
*/
private static boolean handleSplineConnection(final IFigure edgeFigure, final EdgeRouting edgeRouting) {
boolean isSC;
Class<?> clazz = edgeFigure.getClass();
do {
String canonicalName = clazz.getCanonicalName();
// in some cases, eg anonymous classes, the canonical name may be null
isSC = canonicalName != null && canonicalName.equals(SPLINE_CONNECTION);
clazz = clazz.getSuperclass();
} while (!isSC && clazz != null);
if (isSC) {
clazz = edgeFigure.getClass();
try {
if (edgeRouting == EdgeRouting.SPLINES) {
// SplineConnection.SPLINE_CUBIC
clazz.getMethod("setSplineMode", int.class).invoke(edgeFigure, 1);
} else {
// SplineConnection.SPLINE_OFF
clazz.getMethod("setSplineMode", int.class).invoke(edgeFigure, 0);
}
return false;
} catch (Exception exception) {
throw new WrappedException(exception);
}
}
// no spline connection class, but spline representation is requested
return edgeRouting == EdgeRouting.SPLINES;
}
use of org.eclipse.elk.core.util.WrappedException in project elk by eclipse.
the class GraphvizLayoutProvider method writeDotGraph.
/**
* Writes a serialized version of the Graphviz model to the given output stream.
*
* @param graphvizModel
* Graphviz model to serialize
* @param monitor
* a monitor to which progress is reported
* @param debugMode
* whether debug mode is active
* @param resourceSet
* the resource set for serialization
*/
private void writeDotGraph(final GraphvizModel graphvizModel, final IElkProgressMonitor monitor, final boolean debugMode, final XtextResourceSet resourceSet) {
monitor.begin("Serialize model", 1);
OutputStream outputStream = graphvizTool.input();
// enable debug output if needed
FileOutputStream debugStream = null;
if (debugMode) {
try {
String path = System.getProperty("user.home");
if (path.endsWith(File.separator)) {
path += "tmp" + File.separator + "graphviz";
} else {
path += File.separator + "tmp" + File.separator + "graphviz";
}
new File(path).mkdirs();
debugStream = new FileOutputStream(new File(path + File.separator + debugFileBase() + "-in.dot"));
outputStream = new ForkedOutputStream(outputStream, debugStream);
} catch (Exception exception) {
System.out.println("GraphvizLayouter: Could not initialize debug output: " + exception.getMessage());
}
}
try {
XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI("output.graphviz_dot"));
resource.getContents().add(graphvizModel);
/* KIPRA-1498
* We disable formatting and validation when saving the resource. Enabling it lead to
* possible ConcurrentModificationExceptions in Xtext.
*/
Map<Object, Object> saveOptions = SaveOptions.newBuilder().noValidation().getOptions().toOptionsMap();
resource.save(outputStream, saveOptions);
outputStream.write('\n');
outputStream.flush();
} catch (IOException exception) {
graphvizTool.cleanup(Cleanup.ERROR);
throw new WrappedException("Failed to send the graph to Graphviz.", exception);
} finally {
if (debugStream != null) {
try {
debugStream.close();
} catch (IOException exception) {
// ignore exception
}
}
monitor.done();
}
}
use of org.eclipse.elk.core.util.WrappedException in project elk by eclipse.
the class GraphvizLayoutProvider method readDotGraph.
/**
* Reads and parses a serialized Graphviz model.
*
* @param monitor
* a monitor to which progress is reported
* @param debugMode
* whether debug mode is active
* @param resourceSet
* the resoure set for parsing
* @return an instance of the parsed graphviz model
*/
private GraphvizModel readDotGraph(final IElkProgressMonitor monitor, final boolean debugMode, final XtextResourceSet resourceSet) {
monitor.begin("Parse output", 1);
InputStream inputStream = graphvizTool.output();
// enable debug output if needed
FileOutputStream debugStream = null;
if (debugMode) {
try {
String path = System.getProperty("user.home");
if (path.endsWith(File.separator)) {
path += "tmp" + File.separator + "graphviz";
} else {
path += File.separator + "tmp" + File.separator + "graphviz";
}
new File(path).mkdirs();
debugStream = new FileOutputStream(new File(path + File.separator + debugFileBase() + "-out.dot"));
inputStream = new ForwardingInputStream(inputStream, debugStream);
} catch (Exception exception) {
System.out.println("GraphvizLayouter: Could not initialize debug output: " + exception.getMessage());
}
}
// parse the output stream of the dot process
XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI("input.graphviz_dot"));
try {
resource.load(inputStream, null);
} catch (IOException exception) {
graphvizTool.cleanup(Cleanup.ERROR);
throw new WrappedException("Failed to read Graphviz output.", exception);
} finally {
if (debugStream != null) {
try {
debugStream.close();
} catch (IOException exception) {
// ignore exception
}
}
}
// analyze errors and retrieve parse result
if (!resource.getErrors().isEmpty()) {
StringBuilder errorString = new StringBuilder("Errors in Graphviz output:");
for (Diagnostic diagnostic : resource.getErrors()) {
errorString.append("\n" + diagnostic.getLine() + ": " + diagnostic.getMessage());
}
graphvizTool.cleanup(Cleanup.ERROR);
throw new GraphvizException(errorString.toString());
}
GraphvizModel graphvizModel = (GraphvizModel) resource.getParseResult().getRootASTElement();
if (graphvizModel == null || graphvizModel.getGraphs().isEmpty()) {
graphvizTool.cleanup(Cleanup.ERROR);
throw new GraphvizException("No output from the Graphviz process." + " Try increasing the timeout value in the Eclipse Diagram Layout preferences.");
}
monitor.done();
return graphvizModel;
}
Aggregations