Bug 530043: [Platform] change return type of runProcess() to Process

Change-Id: If10dc499ae8ef22cc65a82ff37780a93a3fc28b4
diff --git a/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/Future.java b/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/Future.java
deleted file mode 100644
index fde04db..0000000
--- a/plugins/org.eclipse.ease.modules.platform/src/org/eclipse/ease/modules/platform/Future.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package org.eclipse.ease.modules.platform;

-

-import java.util.Scanner;

-

-/**

- * Future object tracking an asynchronous execution result.

- */

-public class Future {

-

-	private final Process fProcess;

-	private final Exception fException;

-

-	/**

-	 * Constructor for a process.

-	 * 

-	 * @param process

-	 *            running process

-	 */

-	public Future(Process process) {

-		fProcess = process;

-		fException = null;

-	}

-

-	/**

-	 * Constructor for exceptions.

-	 * 

-	 * @param exception

-	 *            exception to provide for user

-	 */

-	public Future(Exception exception) {

-		fException = exception;

-		fProcess = null;

-	}

-

-	/**

-	 * Query external process for finished state.

-	 * 

-	 * @return <code>true</code> when finished

-	 */

-	public boolean isFinished() {

-		if (fException == null) {

-

-			try {

-				fProcess.exitValue();

-				return true;

-			} catch (final IllegalThreadStateException e) {

-				return false;

-			}

-		}

-

-		return true;

-	}

-

-	/**

-	 * Wait for external process to finish

-	 * 

-	 * @return <code>true</code> when finished

-	 */

-	public boolean join() {

-		if (!isFinished()) {

-			try {

-				fProcess.waitFor();

-			} catch (final InterruptedException e) {

-			}

-		}

-

-		return isFinished();

-	}

-

-	/**

-	 * Get exit code of external process. In case of an exception -1 is returned.

-	 * 

-	 * @return exit code

-	 */

-	public int getExitCode() {

-		if (fProcess != null)

-			return fProcess.exitValue();

-

-		return -1;

-	}

-

-	/**

-	 * Get the output of the process as string. This method works only once as it consumes a stream.

-	 * 

-	 * @return process output

-	 */

-	public String getOutput() {

-		if (fProcess != null) {

-			final Scanner scanner = new Scanner(fProcess.getInputStream()).useDelimiter("\\A");

-			return scanner.hasNext() ? scanner.next() : "";

-		}

-

-		return "";

-	}

-

-	/**

-	 * Get the error text of the process as string. This method works only once as it consumes a stream.

-	 * 

-	 * @return process error text (or exception message)

-	 */

-	public String getError() {

-		if (fProcess != null) {

-			final Scanner scanner = new Scanner(fProcess.getErrorStream()).useDelimiter("\\A");

-			return scanner.hasNext() ? scanner.next() : "";

-		} else if (fException != null) {

-			return fException.toString();

-		}

-

-		return "";

-	}

-}

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 bc8d332..45741e4 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
@@ -112,17 +112,20 @@
 	}
 
 	/**
-	 * Run an external process. The process is started in the background and a {@link Future} object is returned. Query the result for finished state, output
+	 * Run an external process. The process is started in the background and a {@link FutureX} object is returned. Query the result for finished state, output
 	 * and error streams of the executed process.
 	 *
 	 * @param name
 	 *            program to run (with full path if necessary)
 	 * @param args
 	 *            program arguments
-	 * @return {@link Future} object tracking the program
+	 * @return
+	 * @return {@link FutureX} object tracking the program
+	 * @throws IOException
+	 *             if an I/O error occurs
 	 */
 	@WrapToScript
-	public static Future runProcess(final String name, @ScriptParameter(defaultValue = ScriptParameter.NULL) final String[] args) {
+	public static Process runProcess(final String name, @ScriptParameter(defaultValue = ScriptParameter.NULL) final String[] args) throws IOException {
 		final List<String> arguments = new ArrayList<>();
 		arguments.add(name);
 		if (args != null) {
@@ -131,11 +134,7 @@
 		}
 
 		final ProcessBuilder builder = new ProcessBuilder(arguments);
-		try {
-			return new Future(builder.start());
-		} catch (final IOException e) {
-			return new Future(e);
-		}
+		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 18c2b48..28c958e 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
@@ -15,6 +15,8 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
+
 import org.eclipse.ease.service.IScriptService;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -56,10 +58,10 @@
 	}
 
 	@Test(timeout = 3000)
-	public void runProcess() {
-		Future process = PlatformModule.runProcess("ls", new String[] { "-la" });
-		process.join();
+	public void runProcess() throws IOException, InterruptedException {
+		final Process process = PlatformModule.runProcess("ls", new String[] { "-la" });
+		process.waitFor();
 
-		assertNotNull(process.getOutput());
+		assertTrue(process.getInputStream().available() > 0);
 	}
 }