package ca.mestevens.unity.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;

public class ProcessRunner {

	private Log log;

	public ProcessRunner(Log log) {
		this.log = log;
	}

	public int runProcess(String workingDirectory, String... strings) throws MojoFailureException {
		try {
			ProcessBuilder processBuilder = new ProcessBuilder(strings);
			if (workingDirectory != null) {
				processBuilder.directory(new File(workingDirectory));
			}
			processBuilder.redirectErrorStream(true);
			Process process = processBuilder.start();
			BufferedReader input = new BufferedReader(new InputStreamReader(
					process.getInputStream()));
			String line = null;
			while ((line = input.readLine()) != null) {
				log.info(line);
			}
			return process.waitFor();
		} catch (IOException e) {
			log.error(e.getMessage());
			throw new MojoFailureException(e.getMessage());
		} catch (InterruptedException e) {
			log.error(e.getMessage());
			throw new MojoFailureException(e.getMessage());
		}
	}
	
	public void checkReturnValue(int returnValue) throws MojoFailureException {
		if (returnValue != 0) {
			throw new MojoFailureException("Failed to build project.");
		}
	}

}

@@ -28,16 +28,152 @@
 utils;%0A%0A
+import com.google.common.base.Joiner;%0Aimport org.apache.maven.plugin.MojoFailureException;%0Aimport org.apache.maven.plugin.logging.Log;%0A%0A
 import j
@@ -283,106 +283,8 @@
 r;%0A%0A
-import org.apache.maven.plugin.MojoFailureException;%0Aimport org.apache.maven.plugin.logging.Log;%0A%0A
 publ
@@ -1199,17 +1199,325 @@
 %0A%09%09%7D%0A%09%7D%0A
-%09
+%0A%09public void runProcessAsync(final String... strings) throws MojoFailureException %7B%0A%09%09try %7B%0A%09%09%09Runtime.getRuntime().exec(Joiner.on(%22 %22).join(strings));%0A%09%09%7D catch(final Exception e) %7B%0A%09%09%09this.log.error(%22Failed to execute process%22, e);%0A%09%09%09throw new MojoFailureException(%22Failed to execute process%22, e);%0A%09%09%7D%0A%09%7D%0A
 %0A%09public

Add runProcessAsync method to ProcessRunner