1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import java.util.Date ; 40 import java.io.File ; 41 import java.io.IOException ; 42 43 import net.sourceforge.cruisecontrol.CruiseControlException; 44 import net.sourceforge.cruisecontrol.Publisher; 45 import net.sourceforge.cruisecontrol.util.CurrentBuildFileWriter; 46 import net.sourceforge.cruisecontrol.util.AbstractFTPClass; 47 import net.sourceforge.cruisecontrol.util.Util; 48 import net.sourceforge.cruisecontrol.util.ValidationHelper; 49 import net.sourceforge.cruisecontrol.util.XMLLogHelper; 50 51 import org.jdom.Element; 52 import org.apache.log4j.Logger; 53 54 59 public class CurrentBuildStatusFTPPublisher extends AbstractFTPClass 60 implements Publisher { 61 private static final Logger LOG = Logger.getLogger(CurrentBuildStatusFTPPublisher.class); 62 63 private String fileName; 64 private String destdir; 65 66 public CurrentBuildStatusFTPPublisher() { 67 LOG.warn("CurrentBuildStatusFTPPublisher was obsoleted by CurrentBuildStatusFTPListener"); 68 } 69 70 public void setFile(String fileName) { 71 this.fileName = fileName; 72 } 73 74 75 public void setDestDir(String dir) { 76 this.destdir = dir; 77 } 78 79 80 86 public void validate() throws CruiseControlException { 87 ValidationHelper.assertIsSet(fileName, "file", this.getClass()); 88 ValidationHelper.assertIsSet(destdir, "destdir", this.getClass()); 89 super.validate(); 90 } 91 92 public void publish(Element cruisecontrolLog) throws CruiseControlException { 93 String out = makeFile(cruisecontrolLog); 94 String fname = destdir + File.separator + fileName; 95 96 sendFileToFTPPath(out, fname); 97 } 98 99 protected String makeFile(Element cruisecontrolLog) 100 throws CruiseControlException { 101 XMLLogHelper helper = new XMLLogHelper(cruisecontrolLog); 102 103 long interval = Long.parseLong(helper.getCruiseControlInfoProperty("interval")); 104 writeFile(new Date (), interval); 105 106 try { 107 return Util.readFileToString(fileName); 108 } catch (IOException ioe) { 109 throw new CruiseControlException(ioe.getMessage()); 110 } 111 } 112 113 protected void writeFile(Date date, long interval) throws CruiseControlException { 114 Date datePlusInterval = new Date (date.getTime() + (interval * 1000)); 115 CurrentBuildFileWriter.writefile("Next Build Starts At:\n", datePlusInterval, fileName); 116 } 117 } 118 | Popular Tags |