1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import java.io.PrintWriter ; 40 import java.util.ArrayList ; 41 import java.util.StringTokenizer ; 42 43 import net.sourceforge.cruisecontrol.Bootstrapper; 44 import net.sourceforge.cruisecontrol.CruiseControlException; 45 import net.sourceforge.cruisecontrol.util.Commandline; 46 import net.sourceforge.cruisecontrol.util.StreamPumper; 47 import net.sourceforge.cruisecontrol.util.ValidationHelper; 48 49 import org.apache.log4j.Logger; 50 51 70 public class ClearCaseViewstrapper implements Bootstrapper { 71 72 73 private static Logger log = Logger.getLogger(ClearCaseViewstrapper.class); 74 75 private String viewpath; 76 private String voblist; 77 78 82 public void setViewpath(String path) { 83 viewpath = path; 84 } 85 86 90 public void setVoblist(String list) { 91 voblist = list; 92 } 93 94 97 public void bootstrap() { 98 99 Commandline commandLine = buildStartViewCommand(); 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 p.waitFor(); 107 p.getInputStream().close(); 108 p.getOutputStream().close(); 109 p.getErrorStream().close(); 110 } catch (Exception e) { 111 log.error("Error executing ClearCase startview command", e); 112 } 113 114 if (voblist != null) { 116 String [] vobs = getVobsFromList(voblist); 117 for (int i = 0; i < vobs.length; i++) { 118 commandLine = buildMountVOBCommand(vobs[i]); 119 log.debug("Executing: " + commandLine); 120 try { 121 Process p = Runtime.getRuntime().exec(commandLine.getCommandline()); 122 StreamPumper errorPumper = 123 new StreamPumper(p.getErrorStream(), new PrintWriter (System.err, true)); 124 new Thread (errorPumper).start(); 125 p.waitFor(); 126 p.getInputStream().close(); 127 p.getOutputStream().close(); 128 p.getErrorStream().close(); 129 } catch (Exception e) { 130 log.error("Error executing ClearCase mount command", e); 131 } 132 } 133 } 134 } 135 136 private String [] getVobsFromList(String voblist) { 137 ArrayList vobs = simpleSplitReplacement(voblist, ','); 139 return (String []) vobs.toArray(new String []{}); 140 } 141 142 145 public void validate() throws CruiseControlException { 146 ValidationHelper.assertIsSet(viewpath, "viewpath", this.getClass()); 147 } 148 149 152 protected Commandline buildStartViewCommand() { 153 Commandline commandLine = new Commandline(); 154 commandLine.setExecutable("cleartool"); 155 156 commandLine.createArgument().setValue("startview"); 157 commandLine.createArgument().setValue(getViewName()); 158 159 return commandLine; 160 } 161 162 165 protected Commandline buildMountVOBCommand(String vob) { 166 Commandline commandLine = new Commandline(); 167 commandLine.setExecutable("cleartool"); 168 169 commandLine.createArgument().setValue("mount"); 170 commandLine.createArgument().setValue(vob); 171 172 return commandLine; 173 } 174 175 178 private String getViewName() { 179 String viewname = ""; 180 try { 181 if (isWindows()) { 182 viewname = getWindowsViewname(viewpath); 183 } else { 184 viewname = getUnixViewname(viewpath); 185 } 186 } catch (ArrayIndexOutOfBoundsException ex) { 187 188 } 189 return viewname; 190 } 191 192 private String getUnixViewname(String viewpath) { 194 ArrayList parts = simpleSplitReplacement(viewpath, '/'); 198 return (String ) parts.get(1); 199 } 200 201 private String getWindowsViewname(String viewpath) { 203 ArrayList parts = simpleSplitReplacement(viewpath, '\\'); 207 return (String ) parts.get(1); 208 } 209 210 private ArrayList simpleSplitReplacement(String string, char tokenizeOn) { 211 ArrayList parts = new ArrayList (); 212 StringTokenizer tokenizer = new StringTokenizer (string, String.valueOf(tokenizeOn)); 213 while (tokenizer.hasMoreTokens()) { 214 parts.add(tokenizer.nextToken()); 215 } 216 return parts; 217 } 218 219 protected boolean isWindows() { 220 return getOsName().indexOf("Windows") >= 0; 221 } 222 223 protected String getOsName() { 224 return System.getProperty("os.name"); 225 } 226 227 228 public static void main(String [] args) { 229 ClearCaseViewstrapper bootstrapper = new ClearCaseViewstrapper(); 230 bootstrapper.setViewpath("M:\\RatlBankModel_rel\\RatlBankSources"); 231 bootstrapper.setVoblist("\\RatlBankSources,\\RatlBankReleases"); 232 bootstrapper.bootstrap(); 233 } 234 235 } | Popular Tags |