1 6 package net.sourceforge.cvsgrab; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.tools.ant.BuildException; 10 import org.apache.tools.ant.Project; 11 import org.apache.tools.ant.Task; 12 13 20 21 public class CVSGrabTask extends Task { 22 23 private CVSGrab _grabber = new CVSGrab(); 24 private boolean _verbose = true; 25 private int _connections; 26 private WebOptions _webOptions; 27 28 31 public CVSGrabTask() { 32 super(); 33 _webOptions = _grabber.getWebOptions(); 34 } 35 36 41 public void setUrl(String value) { 42 _grabber.setUrl(value); 43 } 44 45 50 public void setRootUrl(String value) { 51 _webOptions.setRootUrl(value); 52 } 53 54 59 public void setPackagePath(String value) { 60 _webOptions.setPackagePath(value); 61 } 62 63 public void setProjectRoot(String value) { 64 _webOptions.setProjectRoot(value); 65 } 66 67 72 public void setDestDir(String value) { 73 _grabber.setDestDir(value); 74 } 75 76 81 public void setPackageDir(String value) { 82 _grabber.setPackageDir(value); 83 } 84 85 90 public void setCvsRoot(String value) { 91 _grabber.setCvsRoot(value); 92 } 93 94 99 public void setTag(String value) { 100 _webOptions.setVersionTag(value); 101 } 102 103 public void setWebInterface(String value) { 104 _webOptions.setWebInterfaceId(value); 105 } 106 107 112 public void setVerbose(boolean value) { 113 _verbose = value; 114 } 115 116 121 public void setPruneEmptyDirs(boolean value) { 122 _grabber.setPruneEmptyDirs(value); 123 } 124 125 130 public void setCleanUpdate(boolean value) { 131 _grabber.setCleanUpdate(value); 132 } 133 134 138 public void setConnections(int connections) { 139 _connections = connections; 140 } 141 142 147 public WebOptions.HttpProxy createProxy() { 148 WebOptions.HttpProxy proxy = _webOptions.new HttpProxy(); 149 _webOptions.setHttpProxy(proxy); 150 return proxy; 151 } 152 153 158 public WebOptions.WebAuthentification createWeb() { 159 WebOptions.WebAuthentification auth = _webOptions.new WebAuthentification(); 160 _webOptions.setWebAuthentification(auth); 161 return auth; 162 } 163 164 169 public void execute() throws BuildException { 170 if (_grabber.getRootUrl() == null) { 171 throw new BuildException("rootUrl argument is not specified"); 172 } 173 if (_grabber.getDestDir() == null) { 174 throw new BuildException("destDir argument is not specified"); 175 } 176 if (_grabber.getPackagePath() == null) { 177 throw new BuildException("packagePath argument is not specified"); 178 } 179 180 AntLogger log = new AntLogger(getProject()); 181 log.setVerbose(_verbose); 182 CVSGrab.setLog(log); 183 _webOptions.setupConnectionSettings(); 184 185 if (_connections > 1) { 186 ThreadPool.init(_connections); 187 WebBrowser.getInstance().useMultithreading(); 188 } 189 _grabber.grabCVSRepository(); 190 } 191 192 198 class AntLogger implements Log { 199 private boolean verbose; 200 private Project antProject; 201 202 207 public AntLogger(Project project) { 208 antProject = project; 209 } 210 211 216 public void setVerbose(boolean value) { 217 this.verbose = value; 218 } 219 220 225 public void setDebug(boolean value) { 226 } 228 229 234 public void debug(Object msg) { 235 antProject.log(msg.toString(), Project.MSG_VERBOSE); 237 } 238 239 244 public void verbose(Object msg) { 245 if (verbose) { 246 antProject.log(msg.toString(), Project.MSG_INFO); 247 } else { 248 antProject.log(msg.toString(), Project.MSG_VERBOSE); 249 } 250 } 251 252 257 public void info(Object msg) { 258 antProject.log(msg.toString(), Project.MSG_INFO); 259 } 260 261 266 public void warn(Object msg) { 267 antProject.log(msg.toString(), Project.MSG_WARN); 268 } 269 270 275 public void error(Object msg) { 276 antProject.log(msg.toString(), Project.MSG_ERR); 277 } 278 279 283 public boolean isDebugEnabled() { 284 return true; 285 } 286 287 291 public boolean isErrorEnabled() { 292 return true; 293 } 294 295 299 public boolean isFatalEnabled() { 300 return true; 301 } 302 303 307 public boolean isInfoEnabled() { 308 return true; 309 } 310 311 315 public boolean isTraceEnabled() { 316 return false; 317 } 318 319 323 public boolean isWarnEnabled() { 324 return true; 325 } 326 327 331 public void trace(Object arg0) { 332 } 334 335 340 public void trace(Object arg0, Throwable arg1) { 341 } 343 344 349 public void debug(Object arg0, Throwable arg1) { 350 } 352 353 358 public void info(Object arg0, Throwable arg1) { 359 } 361 362 367 public void warn(Object arg0, Throwable arg1) { 368 } 370 371 376 public void error(Object arg0, Throwable arg1) { 377 } 379 380 384 public void fatal(Object arg0) { 385 } 387 388 393 public void fatal(Object arg0, Throwable arg1) { 394 } 396 } 397 } 398 | Popular Tags |