1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import net.sourceforge.cruisecontrol.CruiseControlException; 40 import net.sourceforge.cruisecontrol.Publisher; 41 import net.sourceforge.cruisecontrol.util.Commandline; 42 import net.sourceforge.cruisecontrol.util.ValidationHelper; 43 44 import org.apache.log4j.Logger; 45 import org.jdom.Element; 46 47 import java.io.IOException ; 48 49 54 public class ExecutePublisher implements Publisher { 55 56 private static final Logger LOG = Logger.getLogger(ExecutePublisher.class); 57 58 private String commandString; 59 60 public void setCommand(String commandString) { 61 this.commandString = commandString; 62 } 63 64 70 public void validate() throws CruiseControlException { 71 ValidationHelper.assertIsSet(commandString, "command", this.getClass()); 72 } 73 74 public void publish(Element cruisecontrolLog) 75 throws CruiseControlException { 76 77 Commandline command = new Commandline(commandString); 78 LOG.info("executing command: " + command); 79 80 try { 81 Process p = command.execute(); 82 p.waitFor(); 83 LOG.debug("waitfor() ended with exit code " + p.exitValue()); 84 } catch (IOException e) { 85 throw new CruiseControlException(e); 86 } catch (InterruptedException e) { 87 throw new CruiseControlException(e); 88 } 89 } 90 91 } 92 | Popular Tags |