Changeset 13562 for trunk/gsdl3/src/java/org/greenstone/server/RunAnt.java
- Timestamp:
- 2007-01-11T13:18:15+13:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/server/RunAnt.java
r13229 r13562 2 2 3 3 import java.io.IOException; 4 import java.io.BufferedReader; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 4 7 5 8 import org.greenstone.server.StreamGobbler; 6 9 10 import org.apache.log4j.*; 11 7 12 public class RunAnt extends Thread { 8 private String antCmd = null; 13 private String antCmd = ""; 14 static Logger logger = Logger.getLogger(org.greenstone.server.RunAnt.class.getName()); 15 private int state = -1; //success: 0 error: 1 16 public static int SUCCESS = 0; 17 public static int FAILED = 1; 9 18 10 public RunAnt() { 11 } 19 private String antSuccess = "BUILD SUCCESSFUL"; 20 private String antFailed = "BUILD FAILED"; 21 private String antFinished = "Total time"; 12 22 13 23 public void run() { 14 Runtime run = Runtime.getRuntime(); 15 Process process = null; 16 //BufferedReader processOut; 17 try { 18 setPriority(MIN_PRIORITY); 19 //Thread.sleep(1000); 20 process = run.exec(getAntCmd()); 21 // any error message? 22 StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR"); 23 // any output? 24 StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "OUTPUT"); 25 // kick them off 26 errorGobbler.run(); 27 outputGobbler.run(); 28 } catch (IOException ioe) { 29 ioe.printStackTrace(); 30 } catch (Throwable t) { 31 t.printStackTrace(); 32 } 24 25 try { 26 state = -1; 27 Runtime run = Runtime.getRuntime(); 28 Process process = run.exec(getAntCmd()); 29 BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); 30 String line = null; 31 while (!(line = br.readLine()).startsWith(antFinished)){ 32 33 if (line.equals(antSuccess)){ 34 state = 0; 35 } 36 37 if (line.equals(antFailed)){ 38 state = 1; 39 } 40 logger.info(line); 41 } 42 } catch (Exception e) { 43 logger.error(e); 44 state = 1; 45 } 33 46 } 34 47 48 public int getState(){ 49 return state; 50 } 51 35 52 public void setAntCmd(String cmd) { 36 53 String osName = System.getProperty("os.name"); 37 System.out.println("command: " + cmd); 38 if (osName.startsWith("Windows")) { 54 if (osName.startsWith("Windows")) { 39 55 this.antCmd = "ant.bat " + cmd; 40 56 } else { … … 46 62 return this.antCmd; 47 63 } 48 49 64 }
Note:
See TracChangeset
for help on using the changeset viewer.