1 package net.sourceforge.cruisecontrol.listeners; 2 3 import net.sourceforge.cruisecontrol.CruiseControlException; 4 import net.sourceforge.cruisecontrol.Listener; 5 import net.sourceforge.cruisecontrol.ProjectEvent; 6 import net.sourceforge.cruisecontrol.ProjectState; 7 import net.sourceforge.cruisecontrol.util.CurrentBuildFileWriter; 8 import net.sourceforge.cruisecontrol.util.ValidationHelper; 9 10 import org.apache.log4j.Logger; 11 12 import java.util.Date ; 13 14 23 public class CurrentBuildStatusListener implements Listener { 24 private static final Logger LOG = Logger.getLogger(CurrentBuildStatusListener.class); 25 private String fileName; 26 27 public void handleEvent(ProjectEvent event) throws CruiseControlException { 28 if (event instanceof ProjectStateChangedEvent) { 29 final ProjectStateChangedEvent stateChanged = (ProjectStateChangedEvent) event; 30 final ProjectState newState = stateChanged.getNewState(); 31 LOG.debug("updating status to " + newState.getName() + " for project " + stateChanged.getProjectName()); 32 final String text = newState.getDescription() + " since\n"; 33 CurrentBuildFileWriter.writefile(text, new Date (), fileName); 34 } else { 35 LOG.debug("ignoring event " + event.getClass().getName() + " for project " + event.getProjectName()); 37 } 38 } 39 40 public void validate() throws CruiseControlException { 41 ValidationHelper.assertIsSet(fileName, "file", this.getClass()); 42 CurrentBuildFileWriter.validate(fileName); 43 } 44 45 public void setFile(String fileName) { 46 this.fileName = fileName.trim(); 47 LOG.debug("set fileName = " + fileName); 48 } 49 } 50 | Popular Tags |