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.util.Commandline; 42 import net.sourceforge.cruisecontrol.util.StreamConsumer; 43 import net.sourceforge.cruisecontrol.util.StreamPumper; 44 import net.sourceforge.cruisecontrol.util.ValidationHelper; 45 46 import org.apache.log4j.Logger; 47 48 import java.io.File ; 49 50 65 public class CVSBootstrapper implements Bootstrapper { 66 67 private static final Logger LOG = Logger.getLogger(CVSBootstrapper.class); 68 69 private String localWorkingCopy; 70 private String filename; 71 private String cvsroot; 72 private boolean resetStickyTags = false; 73 private boolean overwriteChanges = false; 74 75 public void setCvsroot(String cvsroot) { 76 this.cvsroot = cvsroot; 77 } 78 79 public void setFile(String filename) { 80 this.filename = filename; 81 } 82 83 89 public void setLocalWorkingCopy(String local) { 90 localWorkingCopy = local; 91 } 92 93 96 public void bootstrap() { 97 try { 98 Commandline commandLine = buildUpdateCommand(); 99 Process p = commandLine.execute(); 100 StreamConsumer infoConsumer = new StreamConsumer() { 101 public void consumeLine(String line) { 102 LOG.warn(line); 103 } 104 }; 105 StreamConsumer warnConsumer = new StreamConsumer() { 106 public void consumeLine(String line) { 107 LOG.warn(line); 108 } 109 }; 110 StreamPumper errorPumper = 111 new StreamPumper(p.getErrorStream(), null, warnConsumer); 112 StreamPumper outPumper = new StreamPumper(p.getInputStream(), null, infoConsumer); 113 Thread errorPumperThread = new Thread (errorPumper); 114 Thread outPumperThread = new Thread (outPumper); 115 errorPumperThread.start(); 116 outPumperThread.start(); 117 p.waitFor(); 118 errorPumperThread.join(); 119 outPumperThread.join(); 120 p.getInputStream().close(); 121 p.getOutputStream().close(); 122 p.getErrorStream().close(); 123 } catch (Exception e) { 124 LOG.error("Error executing CVS update command", e); 125 } 126 } 127 128 public void validate() throws CruiseControlException { 129 ValidationHelper.assertTrue(filename != null || cvsroot != null || localWorkingCopy != null, 130 "at least one of 'file', 'cvsroot' or 'localworkingcopy' is required as an attribute for CVSBootstrapper"); 131 132 if (localWorkingCopy != null) { 133 File workingDir = new File (localWorkingCopy); 134 135 ValidationHelper.assertTrue(workingDir.exists(), 136 "'localWorkingCopy' must be an existing directory. Was <" 137 + localWorkingCopy + ">"); 138 ValidationHelper.assertTrue(workingDir.isDirectory(), 139 "'localWorkingCopy' must be an existing directory, not a file. Was <" 140 + localWorkingCopy + ">"); 141 } 142 } 143 144 protected Commandline buildUpdateCommand() throws CruiseControlException { 145 Commandline commandLine = new Commandline(); 146 147 if (localWorkingCopy != null) { 148 commandLine.setWorkingDirectory(localWorkingCopy); 149 } 150 151 commandLine.setExecutable("cvs"); 152 153 if (cvsroot != null) { 154 commandLine.createArgument().setValue("-d"); 155 commandLine.createArgument().setValue(cvsroot); 156 } 157 commandLine.createArgument().setValue("update"); 158 159 StringBuffer flags = new StringBuffer ("-dP"); 160 if (resetStickyTags) { 161 flags.append("A"); 162 } 163 if (overwriteChanges) { 164 flags.append("C"); 165 } 166 commandLine.createArgument().setValue(flags.toString()); 167 168 if (filename != null) { 169 commandLine.createArgument().setValue(filename); 170 } 171 172 return commandLine; 173 } 174 175 public void setResetStickyTags(boolean reset) { 176 resetStickyTags = reset; 177 } 178 179 public void setOverwriteChanges(boolean overwrite) { 180 overwriteChanges = overwrite; 181 } 182 183 } 184 | Popular Tags |