Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 492395
Collapse All | Expand All

(-)a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotExecutableUtilsTests.java (-5 / +17 lines)
Lines 13-28 Link Here
13
 *******************************************************************************/
13
 *******************************************************************************/
14
package org.eclipse.gef4.dot.tests;
14
package org.eclipse.gef4.dot.tests;
15
15
16
import static org.junit.Assert.assertNotNull;
17
import static org.junit.Assert.assertTrue;
18
16
import java.io.File;
19
import java.io.File;
17
import java.io.IOException;
20
import java.io.IOException;
18
import java.io.InputStream;
21
import java.io.InputStream;
19
import java.util.Properties;
22
import java.util.Properties;
20
23
24
import org.eclipse.gef4.dot.internal.DotExecutableUtils;
21
import org.eclipse.gef4.dot.internal.DotExport;
25
import org.eclipse.gef4.dot.internal.DotExport;
22
import org.eclipse.gef4.dot.internal.DotFileUtils;
26
import org.eclipse.gef4.dot.internal.DotFileUtils;
23
import org.eclipse.gef4.dot.internal.DotExecutableUtils;
24
import org.eclipse.gef4.dot.internal.ui.GraphvizPreferencePage;
25
import org.eclipse.gef4.graph.Graph;
26
import org.junit.Assert;
27
import org.junit.Assert;
27
import org.junit.BeforeClass;
28
import org.junit.BeforeClass;
28
import org.junit.Test;
29
import org.junit.Test;
Lines 54-60 Link Here
54
			if (stream == null) {
55
			if (stream == null) {
55
				System.err.println(
56
				System.err.println(
56
						"Could not load the test.properties file in directory of " //$NON-NLS-1$
57
						"Could not load the test.properties file in directory of " //$NON-NLS-1$
57
								+ DotExecutableUtilsTests.class.getSimpleName());
58
								+ DotExecutableUtilsTests.class
59
										.getSimpleName());
58
			} else
60
			} else
59
				try {
61
				try {
60
					props.load(stream);
62
					props.load(stream);
Lines 80-86 Link Here
80
82
81
	@Test
83
	@Test
82
	public void simpleGraph() {
84
	public void simpleGraph() {
83
		testDotGeneration(DotTestUtils.getSimpleGraph(), "simple_graph.dot");
85
		testDotGeneration(DotTestUtils.getSimpleGraph(),
86
				"arrowshapes_direction_both.dot");
84
	}
87
	}
85
88
86
	@Test
89
	@Test
Lines 114-117 Link Here
114
		}
117
		}
115
	}
118
	}
116
119
120
	@Test(timeout = 2000)
121
	public void testComplexDot() throws Exception {
122
		File dotFile = new File("./resources/arrowshapes_direction_both.dot");
123
		assertTrue(dotFile.exists());
124
		String[] dotResult = DotExecutableUtils
125
				.executeDot(new File(dotExecutablePath), dotFile, null, null);
126
		assertNotNull("Result should not be null", dotResult);
127
	}
128
117
}
129
}
(-)a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotExecutableUtils.java (-2 / +28 lines)
Lines 17-22 Link Here
17
package org.eclipse.gef4.dot.internal;
17
package org.eclipse.gef4.dot.internal;
18
18
19
import java.io.File;
19
import java.io.File;
20
import java.io.FileInputStream;
20
import java.io.IOException;
21
import java.io.IOException;
21
import java.io.InputStream;
22
import java.io.InputStream;
22
import java.util.ArrayList;
23
import java.util.ArrayList;
Lines 95-110 Link Here
95
	public static String[] executeDot(final File dotExecutablePath,
96
	public static String[] executeDot(final File dotExecutablePath,
96
			final File dotInputFile, final File outputFile,
97
			final File dotInputFile, final File outputFile,
97
			final String outputFormat) {
98
			final String outputFormat) {
99
		File buffer = null;
100
		boolean hasBuffer = false;
98
		List<String> commands = new ArrayList<>();
101
		List<String> commands = new ArrayList<>();
99
		commands.add(dotExecutablePath.getAbsolutePath());
102
		commands.add(dotExecutablePath.getAbsolutePath());
100
		if (outputFormat != null) {
103
		if (outputFormat != null) {
101
			commands.add("-T" + outputFormat);
104
			commands.add("-T" + outputFormat);
102
		}
105
		}
103
		if (outputFile != null) {
106
		if (outputFile != null) {
104
			commands.add("-o" + outputFile.toPath().toString());
107
			buffer = outputFile;
108
		} else {
109
			try {
110
				buffer = File.createTempFile("tmpResult", ".dot");
111
				hasBuffer = true;
112
			} catch (IOException e) {
113
				e.printStackTrace();
114
			}
105
		}
115
		}
116
		commands.add("-o" + buffer.toPath().toString());
106
		commands.add(dotInputFile.toPath().toString());
117
		commands.add(dotInputFile.toPath().toString());
107
		return call(commands.toArray(new String[] {}));
118
		String[] call = call(commands.toArray(new String[] {}));
119
		if (hasBuffer) {
120
			FileInputStream input;
121
			try {
122
				input = new FileInputStream(buffer);
123
				call[0] = read(input);
124
				input.close();
125
			} catch (Exception e) {
126
				System.out.println("failed to read temp dot file");
127
			} finally {
128
				buffer.delete();
129
			}
130
			return call;
131
		} else {
132
			return call;
133
		}
108
	}
134
	}
109
135
110
	/***
136
	/***

Return to bug 492395