1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import java.io.IOException ; 40 41 import net.sourceforge.cruisecontrol.Bootstrapper; 42 import net.sourceforge.cruisecontrol.CruiseControlException; 43 import net.sourceforge.cruisecontrol.util.Commandline; 44 import net.sourceforge.cruisecontrol.util.StreamPumper; 45 import net.sourceforge.cruisecontrol.util.ValidationHelper; 46 47 import org.apache.log4j.Logger; 48 49 56 public class P4Bootstrapper implements Bootstrapper { 57 private static final Logger LOG = Logger.getLogger(P4Bootstrapper.class); 58 private String view; 59 private String port; 60 private String client; 61 private String user; 62 private String passwd; 63 64 public void setPort(String port) { 65 this.port = port; 66 } 67 68 public void setClient(String client) { 69 this.client = client; 70 } 71 72 public void setUser(String user) { 73 this.user = user; 74 } 75 76 public void setView(String view) { 77 this.view = view; 78 } 79 80 public void setPasswd(String passwd) { 81 this.passwd = passwd; 82 } 83 84 87 public void setPath(String path) { 88 LOG.warn("The path attribute is deprecated, please use view attribute instead."); 89 this.view = path; 90 } 91 92 95 public void setP4Port(String p4Port) { 96 LOG.warn("The p4Port attribute is deprecated, please use port attribute instead."); 97 this.port = p4Port; 98 } 99 100 103 public void setP4Client(String p4Client) { 104 LOG.warn("The p4Client attribute is deprecated, please use client attribute instead."); 105 this.client = p4Client; 106 } 107 108 111 public void setP4User(String p4User) { 112 LOG.warn("The p4User attribute is deprecated, please use user attribute instead."); 113 this.user = p4User; 114 } 115 116 public void validate() throws CruiseControlException { 117 ValidationHelper.assertIsSet(view, "view", this.getClass()); 118 ValidationHelper.assertNotEmpty(view, "view", this.getClass()); 119 ValidationHelper.assertNotEmpty(port, "P4Port", this.getClass()); 120 ValidationHelper.assertNotEmpty(client, "P4Client", this.getClass()); 121 ValidationHelper.assertNotEmpty(user, "P4User", this.getClass()); 122 ValidationHelper.assertNotEmpty(passwd, "P4Passwd", this.getClass()); 123 } 124 125 public void bootstrap() throws CruiseControlException { 126 Commandline commandline = createCommandline(); 127 LOG.debug("Executing commandline [" + commandline + "]"); 128 executeCommandLine(commandline); 129 } 130 131 public Commandline createCommandline() throws CruiseControlException { 132 validate(); 133 Commandline cmd = new Commandline(); 134 cmd.setExecutable("p4"); 135 cmd.createArgument().setValue("-s"); 136 if (port != null) { 137 cmd.createArgument().setValue("-p"); 138 cmd.createArgument().setValue(port); 139 } 140 if (client != null) { 141 cmd.createArgument().setValue("-c"); 142 cmd.createArgument().setValue(client); 143 } 144 if (user != null) { 145 cmd.createArgument().setValue("-u"); 146 cmd.createArgument().setValue(user); 147 } 148 if (passwd != null) { 149 cmd.createArgument().setValue("-P"); 150 cmd.createArgument().setValue(passwd); 151 } 152 cmd.createArgument().setValue("sync"); 153 cmd.createArgument().setValue(view); 154 155 return cmd; 156 } 157 158 private void executeCommandLine(Commandline commandline) throws CruiseControlException { 160 try { 161 LOG.info(commandline.toString()); 162 Process p = Runtime.getRuntime().exec(commandline.getCommandline()); 163 164 new Thread (new StreamPumper(p.getInputStream())).start(); 165 new Thread (new StreamPumper(p.getErrorStream())).start(); 166 p.waitFor(); 167 168 } catch (IOException e) { 169 throw new CruiseControlException("Problem trying to execute command line process", e); 170 } catch (InterruptedException e) { 171 throw new CruiseControlException("Problem trying to execute command line process", e); 172 } 173 } 174 } 175 | Popular Tags |