1 37 package net.sourceforge.cruisecontrol.util; 38 39 import net.sourceforge.cruisecontrol.CruiseControlException; 40 import net.sourceforge.cruisecontrol.DateFormatFactory; 41 42 import java.io.File ; 43 import java.io.FileWriter ; 44 import java.io.IOException ; 45 import java.text.DateFormat ; 46 import java.util.Date ; 47 48 52 public final class CurrentBuildFileWriter { 53 54 private CurrentBuildFileWriter() { 55 } 56 57 public static void writefile(String info, Date date, String fileName) throws CruiseControlException { 58 DateFormat formatter = DateFormatFactory.getDateFormat(); 59 StringBuffer sb = new StringBuffer (); 60 sb.append(info); 61 sb.append(formatter.format(date)); 62 63 FileWriter fw = null; 64 try { 65 fw = new FileWriter (fileName); 66 fw.write(sb.toString()); 67 } catch (IOException ioe) { 68 throw new CruiseControlException("Error writing file: " + fileName, ioe); 69 } finally { 70 if (fw != null) { 71 try { 72 fw.close(); 73 } catch (IOException ignore) { 74 } 75 } 76 } 77 } 78 79 public static void validate(String fileName) throws CruiseControlException { 80 File file = new File (fileName); 81 File dir = file.getParentFile(); 82 if (dir != null && !dir.isDirectory()) { 83 ValidationHelper.assertTrue(dir.mkdirs(), 84 "directory for file " + fileName + " doesn't exist and couldn't be created."); 85 } 86 } 87 } 88 | Popular Tags |