KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > listeners > CurrentBuildStatusListener


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 JavaDoc;
13
14 /**
15  * Writes an HTML snippet in a file (typically in a location where the reporting module can read it), indicating
16  * the current build status.
17  *
18  * <p>{@link net.sourceforge.cruisecontrol.DateFormatFactory} for the dateformat
19  *
20  * @see net.sourceforge.cruisecontrol.DateFormatFactory
21  * @author jfredrick
22  */

23 public class CurrentBuildStatusListener implements Listener {
24     private static final Logger LOG = Logger.getLogger(CurrentBuildStatusListener.class);
25     private String JavaDoc 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 JavaDoc text = newState.getDescription() + " since\n";
33             CurrentBuildFileWriter.writefile(text, new Date JavaDoc(), fileName);
34         } else {
35             // ignore other ProjectEvents
36
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 JavaDoc fileName) {
46         this.fileName = fileName.trim();
47         LOG.debug("set fileName = " + fileName);
48     }
49 }
50
Popular Tags