From 41f56f34f235b37571f938899c145dd7e58d734d Mon Sep 17 00:00:00 2001 From: fros4943 Date: Fri, 3 Dec 2010 15:25:17 +0000 Subject: [PATCH] added compile method with command array argument --- .../se/sics/cooja/dialogs/CompileContiki.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java b/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java index b9f904608..128ba1c82 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/CompileContiki.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: CompileContiki.java,v 1.7 2010/11/10 13:11:43 fros4943 Exp $ + * $Id: CompileContiki.java,v 1.8 2010/12/03 15:25:17 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -43,6 +43,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.util.ArrayList; +import java.util.Arrays; import javax.swing.Action; @@ -86,14 +87,47 @@ public class CompileContiki { final MessageList compilationOutput, boolean synchronous) throws Exception { + /* TODO Split into correct arguments: parse " and ' */ + return compile(command.split(" "), env, outputFile, directory, onSuccess, onFailure, compilationOutput, synchronous); + } - compilationOutput.addMessage("", MessageList.NORMAL); - compilationOutput.addMessage("> " + command, MessageList.NORMAL); - logger.info("> " + command); + /** + * Executes a Contiki compilation command. + * + * @param command Command + * @param env (Optional) Environment. May be null. + * @param outputFile Expected output. May be null. + * @param directory Directory in which to execute command + * @param onSuccess Action called if compilation succeeds + * @param onFailure Action called if compilation fails + * @param compilationOutput Is written both std and err process output + * @param synchronous If true, method blocks until process completes + * @return Sub-process if called asynchronously + * @throws Exception If process returns error, or outputFile does not exist + */ + public static Process compile( + final String command[], + final String[] env, + final File outputFile, + final File directory, + final Action onSuccess, + final Action onFailure, + final MessageList compilationOutput, + boolean synchronous) + throws Exception { + + { + String cmd = ""; + for (String c: command) { + cmd += c + " "; + } + logger.info("> " + cmd); + compilationOutput.addMessage("", MessageList.NORMAL); + compilationOutput.addMessage("> " + cmd, MessageList.NORMAL); + } final Process compileProcess; try { - /* TODO Split into correct arguments: parse " and ' */ compileProcess = Runtime.getRuntime().exec(command, env, directory); final BufferedReader processNormal = new BufferedReader(