Bug 564971: [Platform] runProcess() should consume output streams

  merge did not work before

Change-Id: Ic72e696f4f5c1c5806f83202bd0dea0a09387e5b
diff --git a/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/PlatformModule.java b/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/PlatformModule.java
index 0dc1f70..d81f199 100644
--- a/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/PlatformModule.java
+++ b/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/PlatformModule.java
@@ -128,7 +128,6 @@
 	 *            program to run (with full path if necessary)
 	 * @param args
 	 *            program arguments
-	 * @return process object to track process execution
 	 * @param output
 	 *            output file location to redirect output to.
 	 *            <ul>
@@ -148,7 +147,8 @@
 	 *             if an I/O error occurs
 	 */
 	@WrapToScript
-	public static Process runProcess(final String name, @ScriptParameter(defaultValue = ScriptParameter.NULL) final String[] args) throws IOException {
+	public static Process runProcess(final String name, @ScriptParameter(defaultValue = ScriptParameter.NULL) final String[] args,
+			@ScriptParameter(defaultValue = "system.out") String output, @ScriptParameter(defaultValue = "system.err") String error) throws IOException {
 		final List<String> arguments = new ArrayList<>();
 		arguments.add(name);
 		if (args != null) {
@@ -157,6 +157,29 @@
 		}
 
 		final ProcessBuilder builder = new ProcessBuilder(arguments);
+
+		if (output == null) {
+			// TODO discard is supported in Java 9 and newer. Our current compile target is still Java 8, so keep this commented until the time comes
+			// builder.redirectOutput(Redirect.DISCARD);
+			builder.redirectOutput(Redirect.INHERIT);
+
+		} else if ("system.out".equalsIgnoreCase(output))
+			builder.redirectOutput(Redirect.INHERIT);
+
+		else if (!"keep".equalsIgnoreCase(output))
+			builder.redirectOutput(new File(output));
+
+		if (error == null) {
+			// TODO discard is supported in Java 9 and newer. Our current compile target is still Java 8, so keep this commented until the time comes
+			// builder.redirectOutput(Redirect.DISCARD);
+			builder.redirectError(Redirect.INHERIT);
+
+		} else if ("system.err".equalsIgnoreCase(error))
+			builder.redirectError(Redirect.INHERIT);
+
+		else if (!"keep".equalsIgnoreCase(error))
+			builder.redirectError(new File(error));
+
 		return builder.start();
 	}
 
diff --git a/tests/org.eclipse.ease.modules.platform.test/src/org/eclipse/ease/modules/platform/PlatformModuleTest.java b/tests/org.eclipse.ease.modules.platform.test/src/org/eclipse/ease/modules/platform/PlatformModuleTest.java
index 6a69a43..f9b8d5e 100644
--- a/tests/org.eclipse.ease.modules.platform.test/src/org/eclipse/ease/modules/platform/PlatformModuleTest.java
+++ b/tests/org.eclipse.ease.modules.platform.test/src/org/eclipse/ease/modules/platform/PlatformModuleTest.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.ease.modules.platform;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -59,9 +60,10 @@
 
 	@Test(timeout = 3000)
 	public void runProcess() throws IOException, InterruptedException {
-		final Process process = PlatformModule.runProcess("ls", new String[] { "-la" });
+		final Process process = PlatformModule.runProcess("ls", new String[] { "-la" }, "keep", null);
 		process.waitFor();
 
 		assertTrue(process.getInputStream().available() > 0);
+		assertEquals(0, process.getErrorStream().available());
 	}
 }