1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import net.sourceforge.cruisecontrol.CruiseControlException; 40 import net.sourceforge.cruisecontrol.sourcecontrols.SSCM; 41 import net.sourceforge.cruisecontrol.util.StreamPumper; 42 import org.apache.log4j.Logger; 43 import java.io.IOException ; 44 45 50 public class SSCMBootstrapper implements net.sourceforge.cruisecontrol.Bootstrapper 51 { 52 public void validate() throws CruiseControlException { } 53 54 public void bootstrap() throws CruiseControlException { 55 java.util.ArrayList paramList = new java.util.ArrayList (); 56 SSCM.SSCMCLIStringParam strparamFile = new SSCM.SSCMCLIStringParam("file", "", false); 57 strparamFile.setData("/"); 58 paramList.add(strparamFile); 59 paramList.add(strparamBranch); 60 paramList.add(strparamRepository); 61 paramList.add(fparamMakeWritable); 62 paramList.add(fparamForceFetch); 63 64 paramList.add(strparamLabel); 65 if (strparamLabel.isSet()) { paramList.add(strparamIncludeRemovedFiles); } 66 67 paramList.add(fparamRecursive); 68 if (!fparamForceFetch.isSet()) { if (!strparamOverwrite.isSet()) { strparamOverwrite.setData("skip"); } paramList.add(strparamOverwrite); 71 } 72 73 paramList.add(strparamServerLogin); 74 paramList.add(strparamServerConnect); 75 76 executeCLICommand(paramList); 77 } 78 79 public void setBranch(String str) { strparamBranch.setData(str); } 80 public void setRepository(String str) { strparamRepository.setData(str); } 81 public void setLabel(String str) { strparamLabel.setData(str); } 82 public void setServerConnect(String str) { strparamServerConnect.setData(str); } 83 public void setServerLogin(String str) { strparamServerLogin.setData(str); } 84 public void setIncludeRemovedFiles(boolean f) { strparamIncludeRemovedFiles.setData(f ? "" : "-"); } 85 public void setOverwrite(boolean f) { strparamOverwrite.setData(f ? "replace" : "skip"); } 86 public void setRecursive(boolean f) { if (f) { fparamRecursive.setData(null); } } 87 public void setForceFetch(boolean f) { if (f) { fparamForceFetch.setData(null); } } 88 public void setMakeWritable(boolean f) { if (f) { fparamMakeWritable.setData(null); } } 89 90 private SSCM.SSCMCLIStringParam strparamBranch = new SSCM.SSCMCLIStringParam("branch", "-b", false); 91 private SSCM.SSCMCLIStringParam strparamRepository = new SSCM.SSCMCLIStringParam("repository", "-p", false); 92 private SSCM.SSCMCLIStringParam strparamLabel = new SSCM.SSCMCLIStringParam("label", "-l", false); 93 private SSCM.SSCMCLIStringParam strparamServerConnect = new SSCM.SSCMCLIStringParam("serverconnect", "-z", false); 94 private SSCM.SSCMCLIStringParam strparamServerLogin = new SSCM.SSCMCLIStringParam("serverlogin", "-y", false); 95 private SSCM.SSCMCLIStringParam strparamIncludeRemovedFiles = 96 new SSCM.SSCMCLIStringParam("includeremoved", "-i", false); 97 private SSCM.SSCMCLIStringParam strparamOverwrite = new SSCM.SSCMCLIStringParam("overwrite", "-w", false); 98 99 private SSCM.SSCMCLIBoolParam fparamRecursive = new SSCM.SSCMCLIBoolParam("recursive", "-r", false); 100 private SSCM.SSCMCLIBoolParam fparamForceFetch = new SSCM.SSCMCLIBoolParam("force", "-f", false); 101 private SSCM.SSCMCLIBoolParam fparamMakeWritable = new SSCM.SSCMCLIBoolParam("writable", "-e", false); 102 103 private static final Logger LOG = Logger.getLogger(SSCMBootstrapper.class); 104 105 protected void executeCLICommand(java.util.List paramList) throws CruiseControlException { 106 StringBuffer strbufferCmdLine = new StringBuffer ("sscm get "); 107 108 for (int i = 0; i < paramList.size(); ++i) { 110 SSCM.SSCMCLIParam param = (SSCM.SSCMCLIParam) paramList.get(i); 111 112 if (param == null) { 113 throw new IllegalArgumentException ("paramList may not contain null values"); 114 } 115 if (param.checkRequired()) { 116 String str = param.getFormatted(); 117 if (str != null) { 118 strbufferCmdLine.append(str); 119 strbufferCmdLine.append(' '); 120 } 121 } else { 122 throw new CruiseControlException("Required parameter '" + param.getParamName() + "' is missing!"); 123 } 124 } 125 126 LOG.debug(strbufferCmdLine.toString() + "\n"); 127 128 try { 129 Process process = Runtime.getRuntime().exec(strbufferCmdLine.toString()); 130 new Thread (new StreamPumper(process.getInputStream())).start(); 131 new Thread (new StreamPumper(process.getErrorStream())).start(); 132 133 process.waitFor(); 134 135 process.getInputStream().close(); 136 process.getOutputStream().close(); 137 process.getErrorStream().close(); 138 } catch (IOException e) { 139 throw new CruiseControlException("Problem trying to execute command line process", e); 140 } catch (InterruptedException e) { 141 throw new CruiseControlException("Problem trying to execute command line process", e); 142 } 143 } 144 145 } 146 147 | Popular Tags |