1 37 package net.sourceforge.cruisecontrol; 38 39 import java.io.File ; 40 import java.text.ParseException ; 41 import java.util.Date ; 42 import java.util.Locale ; 43 44 import net.sourceforge.cruisecontrol.util.DateHelper; 45 46 52 public class StatusHelper { 53 private BuildInfo newestBuild; 54 private BuildInfo newestSuccessfulBuild; 55 56 private static final String PASSED = "passed"; 57 private static final String FAILED = "failed"; 58 59 public void setProjectDirectory(File directory) { 60 LogFile newestLogfile = LogFile.getLatestLogFile(directory); 61 if (newestLogfile == null) { 62 newestBuild = null; 63 } else { 64 try { 65 newestBuild = new BuildInfo(newestLogfile); 66 } catch (ParseException pe) { 67 newestBuild = null; 68 } 69 } 70 LogFile newestSuccessfulLogfile = LogFile.getLatestSuccessfulLogFile(directory); 71 if (newestSuccessfulLogfile == null) { 72 newestSuccessfulBuild = null; 73 } else { 74 try { 75 newestSuccessfulBuild = new BuildInfo(newestSuccessfulLogfile); 76 } catch (ParseException pe) { 77 newestBuild = null; 78 } 79 } 80 } 81 82 public String getLastBuildResult() { 83 if (newestBuild == null) { 84 return null; 85 } 86 87 return newestBuild.isSuccessful() ? PASSED : FAILED; 88 } 89 90 public String getLastBuildTimeString(Locale locale) { 91 if (newestBuild == null) { 92 return null; 93 } 94 return getBuildTimeString(newestBuild, locale); 95 } 96 97 public String getLastSuccessfulBuildLabel() { 98 if (newestSuccessfulBuild == null) { 99 return null; 100 } 101 102 return newestSuccessfulBuild.getLabel(); 103 } 104 105 public String getLastSuccessfulBuildTimeString(Locale locale) { 106 if (newestSuccessfulBuild == null) { 107 return null; 108 } 109 return getBuildTimeString(newestSuccessfulBuild, locale); 110 } 111 112 private String getBuildTimeString(BuildInfo logInfo, Locale locale) { 113 Date date = logInfo.getBuildDate(); 114 return DateHelper.createDateFormat(locale).format(date); 115 } 116 117 public String getCurrentStatus(String singleProject, String logDirPath, String projectName, String statusFile) { 118 boolean isSingleProject = Boolean.getBoolean(singleProject); 119 120 return getCurrentStatus(isSingleProject, logDirPath, projectName, statusFile); 121 } 122 123 public String getCurrentStatus(boolean isSingleProject, String logDirPath, String projectName, String statusFile) { 124 String status = null; 125 126 try { 127 status = BuildStatus.getStatusHtml(isSingleProject, logDirPath, projectName, statusFile, 128 BuildStatus.READ_ONLY_STATUS_LINES); 129 } catch (CruiseControlWebAppException e) { 130 status = '(' + e.getMessage() + ')'; 131 } 132 133 return status; 134 } 135 } 136 | Popular Tags |