1 11 package org.eclipse.update.internal.jarprocessor; 12 13 import java.io.File ; 14 import java.util.List ; 15 import java.util.Properties ; 16 17 21 public abstract class CommandStep implements IProcessStep { 22 protected String command = null; 23 protected String extension = null; 24 private Properties options = null; 25 protected boolean verbose = false; 26 27 public CommandStep(Properties options, String command, String extension, boolean verbose) { 28 this.command = command; 29 this.extension = extension; 30 this.options = options; 31 this.verbose = verbose; 32 } 33 34 protected static int execute(String [] cmd) { 35 return execute(cmd, false); 36 } 37 38 protected static int execute(String [] cmd, boolean verbose) { 39 Runtime runtime = Runtime.getRuntime(); 40 Process proc = null; 41 try { 42 proc = runtime.exec(cmd); 43 StreamProcessor errorStreamProcessor = new StreamProcessor(proc.getErrorStream(), StreamProcessor.STDERR, verbose); StreamProcessor outputStreamProcessor = new StreamProcessor(proc.getInputStream(), StreamProcessor.STDOUT, verbose); errorStreamProcessor.start(); 46 outputStreamProcessor.start(); 47 } catch (Exception e) { 48 if(verbose) { 49 System.out.println("Error executing command " + Utils.concat(cmd)); e.printStackTrace(); 51 } 52 return -1; 53 } 54 try { 55 int result = proc.waitFor(); 56 return result; 57 } catch (InterruptedException e) { 58 if(verbose) 59 e.printStackTrace(); 60 } 61 return -1; 62 } 63 64 public Properties getOptions() { 65 if(options == null) 66 options = new Properties (); 67 return options; 68 } 69 70 public void adjustInf(File input, Properties inf, List containers) { 71 } 73 } 74 | Popular Tags |