1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import net.sourceforge.cruisecontrol.Bootstrapper; 40 import net.sourceforge.cruisecontrol.CruiseControlException; 41 import net.sourceforge.cruisecontrol.sourcecontrols.VSSHelper; 42 import net.sourceforge.cruisecontrol.util.StreamPumper; 43 import net.sourceforge.cruisecontrol.util.ValidationHelper; 44 45 import org.apache.log4j.Logger; 46 47 import java.io.File ; 48 import java.io.IOException ; 49 import java.io.InputStream ; 50 import java.io.PrintWriter ; 51 52 public class VssBootstrapper implements Bootstrapper { 53 54 private static final Logger LOG = Logger.getLogger(VssBootstrapper.class); 55 56 private String ssDir; 57 private String serverPath; 58 59 private String vssPath; 60 private String localDirectory; 61 private String login; 62 63 public void bootstrap() throws CruiseControlException { 64 String commandLine = generateCommandLine(); 65 66 try { 67 String [] env = VSSHelper.loadVSSEnvironment(serverPath); 68 69 Process p = Runtime.getRuntime().exec(commandLine, env); 70 InputStream errorIn = p.getErrorStream(); 71 InputStream stdIn = p.getInputStream(); 72 PrintWriter errorOut = new PrintWriter (System.err, true); 73 PrintWriter stdOut = new PrintWriter (System.out, true); 74 StreamPumper errorPumper = new StreamPumper(errorIn, errorOut); 75 StreamPumper stdPumper = new StreamPumper(stdIn, stdOut); 76 new Thread (errorPumper).start(); 77 new Thread (stdPumper).start(); 78 p.waitFor(); 79 p.getInputStream().close(); 80 p.getOutputStream().close(); 81 p.getErrorStream().close(); 82 } catch (IOException ex) { 83 LOG.debug("exception trying to exec ss.exe", ex); 84 throw new CruiseControlException(ex); 85 } catch (InterruptedException ex) { 86 LOG.debug("interrupted during get", ex); 87 throw new CruiseControlException(ex); 88 } 89 } 90 91 public void validate() throws CruiseControlException { 92 ValidationHelper.assertTrue(vssPath != null && localDirectory != null, 93 "VssBootstrapper has required attributes vssPath and localDirectory"); 94 95 File localDirForFile = new File (localDirectory); 96 ValidationHelper.assertTrue(localDirForFile.exists(), 97 "file path attribute value " + localDirectory + " must specify an existing directory."); 98 99 ValidationHelper.assertTrue(localDirForFile.isDirectory(), 100 "file path attribute value " + localDirectory + " must specify an existing directory, not a file."); 101 102 setLocalDirectory(localDirForFile.getAbsolutePath()); 103 } 104 105 String generateCommandLine() { 106 StringBuffer commandLine = new StringBuffer (); 107 final String backslash = "\\"; 108 if (ssDir != null) { 110 commandLine.append(ssDir).append(ssDir.endsWith(backslash) ? "" : backslash); 111 } 112 final String quote = "\""; 113 commandLine.append("ss.exe get "); 114 if (vssPath != null) { 116 String pathPrefix = vssPath.startsWith("$") ? "" : "$"; 117 commandLine.append(quote).append(pathPrefix).append(vssPath).append(quote); 118 } 119 commandLine.append(" -GL"); 120 commandLine.append(quote).append(localDirectory).append(quote); 121 commandLine.append(" -I-N"); 122 if (login != null) { 123 commandLine.append(" -Y").append(login); 124 } 125 126 return commandLine.toString(); 127 } 128 129 133 public void setVssPath(String vssPath) { 134 this.vssPath = vssPath; 135 } 136 137 141 public void setSsDir(String ssDir) { 142 this.ssDir = ssDir; 143 } 144 145 149 public void setServerPath(String serverPath) { 150 this.serverPath = serverPath; 151 } 152 153 157 public void setLocalDirectory(String localDirectory) { 158 this.localDirectory = localDirectory; 159 } 160 161 165 public void setLogin(String login) { 166 this.login = login; 167 } 168 } | Popular Tags |