1 37 package net.sourceforge.cruisecontrol.buildloggers; 38 39 import java.io.BufferedReader ; 40 import java.io.File ; 41 import java.io.IOException ; 42 import java.io.InputStreamReader ; 43 import java.io.PrintWriter ; 44 import java.util.ArrayList ; 45 import java.util.StringTokenizer ; 46 47 import net.sourceforge.cruisecontrol.BuildLogger; 48 import net.sourceforge.cruisecontrol.CruiseControlException; 49 import net.sourceforge.cruisecontrol.util.Commandline; 50 import net.sourceforge.cruisecontrol.util.StreamPumper; 51 import net.sourceforge.cruisecontrol.util.ValidationHelper; 52 53 import org.apache.log4j.Logger; 54 import org.jdom.Element; 55 56 63 public class ClearCaseAuditLogger implements BuildLogger { 64 65 private static final Logger LOG = Logger.getLogger(ClearCaseAuditLogger.class); 66 67 private String doFiles; 68 69 73 public void setDoFiles(String files) { 74 this.doFiles = files; 75 } 76 77 80 public void validate() throws CruiseControlException { 81 ValidationHelper.assertIsSet(doFiles , "dofiles", this.getClass()); 83 } 84 85 90 public void log(Element buildLog) throws CruiseControlException { 91 String [] doList = splitOnComma(doFiles); 92 for (int i = 0; i < doList.length; i++) { 93 94 Element auditElement = new Element("audit"); 96 auditElement.setAttribute("name", doList[i]); 97 buildLog.addContent(auditElement); 98 99 Commandline commandLine = buildConfigRecCommand(doList[i]); 100 LOG.debug("Executing: " + commandLine); 101 try { 102 Process p = Runtime.getRuntime().exec(commandLine.getCommandline()); 103 StreamPumper errorPumper = 104 new StreamPumper(p.getErrorStream(), new PrintWriter (System.err, true)); 105 new Thread (errorPumper).start(); 106 try { 107 InputStreamReader isr = new InputStreamReader (p.getInputStream()); 108 BufferedReader br = new BufferedReader (isr); 109 String line; 110 while ((line = br.readLine()) != null) { 111 if (line.startsWith("---")) { 112 } else if (line.startsWith("MVFS")) { 114 } else { 116 Element doElement = new Element("do"); 117 line = line.substring(line.indexOf(File.separator), line.length()); 119 if (line.indexOf("@") > 0) { 120 doElement.setAttribute("name", line.substring(0, line.indexOf("@"))); 121 } else { 122 doElement.setAttribute("name", line.substring(0, line.indexOf("<") - 1)); 123 } 124 if (line.endsWith(">")) { 126 doElement.setAttribute("type", "version"); 128 if (line.indexOf("@") > 0) { 129 doElement.setAttribute("version", line.substring(line.indexOf("@") 130 + 2, line.lastIndexOf("<") - 1)); 131 } else { 132 doElement.setAttribute("version", line.substring(line.indexOf("<") 133 + 1, line.lastIndexOf(">") - 1)); 134 } 135 } else { 136 doElement.setAttribute("type", "do"); 138 doElement.setAttribute("version", line.substring(line.indexOf("@") 139 + 2, line.length())); 140 } 141 auditElement.addContent(doElement); 142 } 143 } 144 } catch (IOException ioe) { 145 LOG.error("Error executing ClearCase catcr command", ioe); 146 } 147 p.waitFor(); 148 p.getInputStream().close(); 149 p.getOutputStream().close(); 150 p.getErrorStream().close(); 151 } catch (Exception e) { 152 LOG.error("Error executing ClearCase catcr command", e); 153 } 154 } 155 } 156 157 private String [] splitOnComma(String doFiles) { 158 ArrayList parts = new ArrayList (); 160 StringTokenizer tokenizer = new StringTokenizer (doFiles, ","); 161 while (tokenizer.hasMoreTokens()) { 162 parts.add(tokenizer.nextToken()); 163 } 164 return (String []) parts.toArray(new String []{}); 165 } 166 167 170 protected Commandline buildConfigRecCommand(String file) { 171 Commandline commandLine = new Commandline(); 172 commandLine.setExecutable("cleartool"); 173 commandLine.createArgument().setValue("catcr"); 174 commandLine.createArgument().setValue("-union"); 175 commandLine.createArgument().setValue(file); 176 return commandLine; 177 } 178 179 } 180 | Popular Tags |