<%@ page import="javax.servlet.http.HttpSession, java.io.BufferedReader, java.io.File, java.io.FileReader, java.io.IOException, java.util.TreeMap, java.util.Date, java.util.Iterator"%> Apache Build Status at: <%= new Date() %>

Apache Build Status



<%! String dir = "/mnt/builds/logs/"; String failedTestsCheck = "[ERROR] There are test failures."; String errorTest = "[ERROR] BUILD ERROR"; String fatalErrorTest = "[ERROR] FATAL ERROR"; String otherErrorsTest = "[INFO] BUILD ERRORS"; String successTest = "BUILD SUCCESSFUL"; String key_projectMap = "projects"; String key_timestamps = "timestamps"; String key_lastresults= "lastResults"; long RE_READ_TIMER = 20 * 60 * 1000; // 20 minutes re-read timer for UNKNOWN status long ACTIVITY_TIME_OUT = 5 * 60 * 1000; // 5 minutes because of longer scp uploads TreeMap prjMap = null; TreeMap tsMap = null; TreeMap lastResultMap = null; void setupMaps(HttpSession session) { // first setup the projects map if (session.getAttribute(key_projectMap) != null) { prjMap = (TreeMap)session.getAttribute(key_projectMap); } else { prjMap = new TreeMap(); // now add all projects prjMap.put("ActiveMQ Protobuf trunk deploy", "activemq-protobuf-deploy.log"); prjMap.put("ActiveMQ trunk deploy", "activemq-deploy.log"); prjMap.put("Camel trunk deploy", "camel-deploy.log"); prjMap.put("ServiceMix 3.3 deploy", "smx-3.3-trunk-deploy.log"); prjMap.put("ServiceMix 4 legal deploy", "smx4-legal-deploy.log"); prjMap.put("ServiceMix 4 bundles deploy", "smx4-bundles-deploy.log"); prjMap.put("ServiceMix 4 kernel deploy", "smx4-kernel-deploy.log"); prjMap.put("ServiceMix 4 specs deploy", "smx4-specs-deploy.log"); prjMap.put("ServiceMix 4 nmr deploy", "smx4-nmr-deploy.log"); prjMap.put("ServiceMix 4 features deploy", "smx4-features-deploy.log"); prjMap.put("ServiceMix Components", "smx-components-deploy.log"); prjMap.put("ServiceMix Archetypes", "smx-archetypes-deploy.log"); prjMap.put("ServiceMix Maven Plugins POM", "smx-mvn-plugins-pom-deploy.log"); prjMap.put("ServiceMix Utils", "smx-utils-trunk-deploy.log"); prjMap.put("ServiceMix POM", "smx-pom-deploy.log"); // add more projects here // register to session session.setAttribute(key_projectMap, prjMap); } // then setup the timestamp map if (session.getAttribute(key_timestamps) != null) { tsMap = (TreeMap)session.getAttribute(key_timestamps); } else { tsMap = new TreeMap(); session.setAttribute(key_timestamps, tsMap); } // then setup the lastResult map if (session.getAttribute(key_lastresults) != null) { lastResultMap = (TreeMap)session.getAttribute(key_lastresults); } else { lastResultMap = new TreeMap(); session.setAttribute(key_lastresults, lastResultMap); } } String processBuildFile(HttpSession session, String uri) { // lets check to see if its boolean failedTests = false; String file = dir + uri; BufferedReader reader = null; File f = new File(file); if (!f.exists() || !f.isFile()) { // log file is missing return "NOT AVAILABLE"; } String result = null; String durationText = convertToDuration(System.currentTimeMillis() - f.lastModified()); try { System.out.println("Processing: " + file); if (f.lastModified() + ACTIVITY_TIME_OUT >= System.currentTimeMillis()) { return "BUILDING"; } // speed up processing of page - if no change was made to the // file, then we do not need to read it again if (lastResultMap != null && lastResultMap.containsKey(uri) && tsMap != null && tsMap.containsKey(uri) && f.lastModified() == ((Long)tsMap.get(uri)).longValue()) { String lastRes = (String)lastResultMap.get(uri); String searchTerm = null; if (lastRes.indexOf("SUCCESS (with failures) ") != -1) { searchTerm = "SUCCESS (with failures) "; } else if (lastRes.indexOf("SUCCESS ") != -1) { searchTerm = "SUCCESS "; } else if (lastRes.indexOf("FAILURE ") != -1) { searchTerm = "FAILURE "; } else if (lastRes.indexOf("UNKNOWN ") != -1) { searchTerm = "UNKNOWN "; } else { return lastRes; } if (searchTerm.equalsIgnoreCase("UNKNOWN ") && System.currentTimeMillis() - f.lastModified() > RE_READ_TIMER) { lastResultMap.remove(uri); tsMap.remove(uri); } else { String updatedRes = lastRes.substring(0, lastRes.indexOf(searchTerm) + searchTerm.length()); updatedRes += durationText + ""; return updatedRes; } } reader = new BufferedReader(new FileReader(file)); while (true) { String line = reader.readLine(); if (line == null) { break; } else { if (line.contains(failedTestsCheck)) { failedTests = true; } else if (line.contains(errorTest) || line.contains(otherErrorsTest) || line.contains(fatalErrorTest)) { result = "FAILURE"; } else if (line.contains(successTest)) { result = "SUCCESS"; } } } } catch (IOException e) { return "" + e + " " + durationText + ""; } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } if (result == null) { // UNKNOWN STATUS result = "UNKNOWN " + durationText + ""; } else if (result.equalsIgnoreCase("SUCCESS")) { // SUCCESS WITH OR WITHOUT TEST FAILURES if (failedTests) { result = "SUCCESS (with failures) " + durationText + ""; } else { result = "SUCCESS " + durationText + ""; } } else if (result.equalsIgnoreCase("FAILURE")) { // FAILURE result = "FAILURE " + durationText + ""; } saveResult(session, f.lastModified(), uri, result); return result; } void saveResult(HttpSession session, long ts, String uri, String result) { // remember the last time we accessed the file tsMap.put(uri, new Long(ts)); // remember the result lastResultMap.put(uri, result); // session handling session.setAttribute(key_timestamps, tsMap); session.setAttribute(key_lastresults, lastResultMap); } String convertToDuration(long millis) { StringBuffer buffer = new StringBuffer(); double minutes = millis / (60 * 1000); long roundedMins = Math.round(minutes); if (roundedMins < 60L) { if (roundedMins >= 1) { buffer.append(roundedMins); buffer.append(" minute"); if (roundedMins > 1) { buffer.append("s"); } } else { buffer.append("less than a minute"); } } else { double hours = minutes / 60; long roundedHours = Math.round(hours); if (roundedHours < 24) { buffer.append("about "); buffer.append(roundedHours); buffer.append(" hour"); if (roundedHours > 1) { buffer.append("s"); } } else { double days = hours / 24; long rounded = Math.round(days); buffer.append("about "); buffer.append(rounded); buffer.append(" day"); if (rounded > 1) { buffer.append("s"); } } } buffer.append(" ago..."); return buffer.toString(); } %> <% // ensure the map is filled setupMaps(request.getSession()); Iterator it = prjMap.keySet().iterator(); int cnt = 0; while (it.hasNext()) { String projectName = (String)it.next(); String logFileName = (String)prjMap.get(projectName); out.write(""); out.write(" "); out.write(processBuildFile(request.getSession(), logFileName)); out.write(""); cnt++; } %>
"); out.write(projectName); out.write("