Changeset 13562


Ignore:
Timestamp:
2007-01-11T13:18:15+13:00 (15 years ago)
Author:
shaoqun
Message:

used the ant output to determine the state of the running ant process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/server/RunAnt.java

    r13229 r13562  
    22
    33import java.io.IOException;
     4import java.io.BufferedReader;
     5import java.io.InputStream;
     6import java.io.InputStreamReader;
    47
    58import org.greenstone.server.StreamGobbler;
    69
     10import org.apache.log4j.*;
     11
    712public 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;
    918
    10     public RunAnt() {
    11     }
     19    private String antSuccess = "BUILD SUCCESSFUL";
     20    private String antFailed = "BUILD FAILED";
     21    private String antFinished = "Total time";
    1222
    1323    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     }
    3346    }
    34 
     47 
     48    public int getState(){
     49    return state;     
     50    }
     51   
    3552    public void setAntCmd(String cmd) {
    3653    String osName = System.getProperty("os.name");
    37     System.out.println("command: " + cmd);
    38     if (osName.startsWith("Windows")) {
     54        if (osName.startsWith("Windows")) {
    3955        this.antCmd = "ant.bat " + cmd;
    4056    } else {
     
    4662    return this.antCmd;
    4763    }
    48 
    4964}
Note: See TracChangeset for help on using the changeset viewer.