1 6 package net.sourceforge.cvsgrab; 7 8 import java.io.BufferedWriter ; 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import java.io.FileReader ; 12 import java.io.FileWriter ; 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.io.LineNumberReader ; 16 import java.io.PrintWriter ; 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.Map ; 20 import java.util.Properties ; 21 22 import net.sourceforge.cvsgrab.util.CVSGrabLog; 23 import net.sourceforge.cvsgrab.util.ThreadPool; 24 25 import org.apache.commons.cli.CommandLine; 26 import org.apache.commons.cli.CommandLineParser; 27 import org.apache.commons.cli.GnuParser; 28 import org.apache.commons.cli.HelpFormatter; 29 import org.apache.commons.cli.Option; 30 import org.apache.commons.cli.OptionBuilder; 31 import org.apache.commons.cli.OptionGroup; 32 import org.apache.commons.cli.Options; 33 import org.apache.commons.cli.ParseException; 34 import org.apache.commons.httpclient.methods.GetMethod; 35 import org.apache.commons.lang.SystemUtils; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.apache.commons.logging.impl.LogFactoryImpl; 39 40 49 public class CVSGrab { 50 51 54 public static final String DUMMY_ROOT = ":pserver:anonymous@dummyhost:/dummyroot"; 55 56 public static final String CONNECTIONS_OPTION = "connections"; 57 public static final String WEB_PASSWORD_OPTION = "webPassword"; 58 public static final String WEB_USER_OPTION = "webUser"; 59 public static final String PROXY_PASSWORD_OPTION = "proxyPassword"; 60 public static final String PROXY_USER_OPTION = "proxyUser"; 61 public static final String PROXY_NTDOMAIN_OPTION = "proxyNTDomain"; 62 public static final String PROXY_PORT_OPTION = "proxyPort"; 63 public static final String PROXY_HOST_OPTION = "proxyHost"; 64 public static final String PRUNE_OPTION = "prune"; 65 public static final String QUIET_OPTION = "quiet"; 66 public static final String VERBOSE_OPTION = "verbose"; 67 public static final String DEBUG_WIRE_OPTION = "debugWire"; 68 public static final String DEBUG_OPTION = "debug"; 69 public static final String CVS_ROOT_OPTION = "cvsRoot"; 70 public static final String WEB_INTERFACE_OPTION = "webInterface"; 71 public static final String PROJECT_ROOT_OPTION = "projectRoot"; 72 public static final String QUERY_PARAMS_OPTION = "queryParams"; 73 public static final String TAG_OPTION = "tag"; 74 public static final String PACKAGE_DIR_OPTION = "packageDir"; 75 public static final String DEST_DIR_OPTION = "destDir"; 76 public static final String PACKAGE_PATH_OPTION = "packagePath"; 77 public static final String ROOT_URL_OPTION = "rootUrl"; 78 public static final String URL_OPTION = "url"; 79 public static final String CLEAN_UPDATE_OPTION = "clean"; 80 public static final String LIST_WEB_INTERFACES_CMD = "listWebInterfaces"; 81 public static final String DIFF_CMD = "diff"; 82 public static final String HELP_CMD = "help"; 83 84 private static final String [] WEB_OPTIONS = {ROOT_URL_OPTION, PACKAGE_PATH_OPTION, 85 PROJECT_ROOT_OPTION, TAG_OPTION, QUERY_PARAMS_OPTION, WEB_INTERFACE_OPTION, 86 PROXY_HOST_OPTION, PROXY_PORT_OPTION, PROXY_NTDOMAIN_OPTION, PROXY_USER_OPTION, 87 PROXY_PASSWORD_OPTION, WEB_USER_OPTION, WEB_PASSWORD_OPTION}; 88 private static final String FORUM_URL = "http://sourceforge.net/forum/forum.php?forum_id=174128"; 89 private static final String VERSION = "2.2.2"; 90 private static final String DEFAULT_DEST_DIR = "."; 91 private static Log LOG; 92 93 private boolean _pruneEmptyDirs = false; 94 private boolean _cleanUpdate; 95 private boolean _error = false; 96 private String _packageDir; 97 private String _destDir = DEFAULT_DEST_DIR; 98 private String _cvsRoot = DUMMY_ROOT; 99 private Options _options; 100 private WebOptions _webOptions = new WebOptions(); 101 private CvsWebInterface _webInterface; 102 103 public static Log getLog() { 104 if (LOG == null) { 105 LOG = LogFactory.getLog(CVSGrab.class); 106 } 107 return LOG; 108 } 109 110 public static void setLog(Log log) { 111 LOG = log; 112 } 113 114 117 public CVSGrab() { 118 _options = new Options(); 119 _options.addOption(HELP_CMD, false, "[Command] Prints this help message"); 120 _options.addOption(LIST_WEB_INTERFACES_CMD, false, "[Command] Lists the web interfaces to the CVS repository that are" 121 + "\t supported by this tool"); 122 _options.addOption(new OptionBuilder() 123 .withDescription("[Command] Builds the differences against the same remote version. Result is stored in the file patch.txt") 124 .create(DIFF_CMD)); 125 _options.addOption(new OptionBuilder().withArgName("url") 126 .hasArg() 127 .withDescription("The full url used to access the CVS repository from a web browser") 128 .create(URL_OPTION)); 129 _options.addOption(new OptionBuilder().withArgName("url") 130 .hasArg() 131 .withDescription("[if full url not used] The root url used to access the CVS repository from a web browser") 132 .create(ROOT_URL_OPTION)); 133 _options.addOption(new OptionBuilder().withArgName("path") 134 .hasArg() 135 .withDescription("[if full url not used] The path relative to rootUrl of the package or module to download") 136 .create(PACKAGE_PATH_OPTION)); 137 _options.addOption(new OptionBuilder().withArgName("root") 138 .hasArg() 139 .withDescription("[optional] The project root, for cvs with multiple repositories") 140 .create(PROJECT_ROOT_OPTION)); 141 _options.addOption(new OptionBuilder().withArgName("version tag") 142 .hasArg() 143 .withDescription("[optional] The version tag of the files to download") 144 .create(TAG_OPTION)); 145 _options.addOption(new OptionBuilder().withArgName("query params") 146 .hasArg() 147 .withDescription("[optional] Additional query parameters") 148 .create(QUERY_PARAMS_OPTION)); 149 _options.addOption(new OptionBuilder().withArgName("web interface id") 150 .hasArg() 151 .withDescription("[optional] The id for the web interface for the CVS repository to use. " + 152 "If this option is not set, autodetect the web interface." + 153 "Call cvsgrab -listWebInterfaces to get a list of valid values for this option.") 154 .create(WEB_INTERFACE_OPTION)); 155 _options.addOption(new OptionBuilder().withArgName("dir") 156 .hasArg() 157 .withDescription("[optional] The destination directory.") 158 .create(DEST_DIR_OPTION)); 159 _options.addOption(new OptionBuilder().withArgName("dir") 160 .hasArg() 161 .withDescription("The name of the package to use locally, relative to destDir, overrides packagePath") 162 .create(PACKAGE_DIR_OPTION)); 163 _options.addOption(new OptionBuilder().withArgName("cvs root") 164 .hasArg() 165 .withDescription("[optional] The original cvs root, used to maintain compatibility with a standard CVS client") 166 .create(CVS_ROOT_OPTION)); 167 _options.addOption(new OptionBuilder() 168 .withDescription("[optional] Prune (remove) the empty directories.") 169 .create(PRUNE_OPTION)); 170 _options.addOption(new OptionBuilder() 171 .withDescription("[optional] Clean update. Backup locally modified files and download anyway the latest version of the file.") 172 .create(CLEAN_UPDATE_OPTION)); 173 Option debugOption = new OptionBuilder() 174 .withDescription("[optional] Turn debugging on.") 175 .create(DEBUG_OPTION); 176 Option debugWireOption = new OptionBuilder() 177 .withDescription("[optional] Turn debugging on, including very verbose network traffic.") 178 .create(DEBUG_WIRE_OPTION); 179 Option verboseOption = new OptionBuilder() 180 .withDescription("[optional] Turn verbosity on.") 181 .create(VERBOSE_OPTION); 182 Option quietOption = new OptionBuilder() 183 .withDescription("[optional] Be extra quiet.") 184 .create(QUIET_OPTION); 185 _options.addOptionGroup(new OptionGroup().addOption(debugOption) 186 .addOption(debugWireOption) 187 .addOption(verboseOption) 188 .addOption(quietOption)); 189 _options.addOption(new OptionBuilder().withArgName("nb of connections") 190 .hasArg() 191 .withDescription("[optional] The number of simultaneous connections to use for downloads, default 1") 192 .create(CONNECTIONS_OPTION)); 193 _options.addOption(new OptionBuilder().withArgName("host") 194 .hasArg() 195 .withDescription("[optional] Proxy host") 196 .create(PROXY_HOST_OPTION)); 197 _options.addOption(new OptionBuilder().withArgName("port") 198 .hasArg() 199 .withDescription("[optional] Proxy port") 200 .create(PROXY_PORT_OPTION)); 201 _options.addOption(new OptionBuilder().withArgName("domain") 202 .hasArg() 203 .withDescription("[optional] NT Domain for the authentification on a MS proxy") 204 .create(PROXY_NTDOMAIN_OPTION)); 205 _options.addOption(new OptionBuilder().withArgName("user") 206 .hasArg() 207 .withDescription("[optional] Username for the proxy") 208 .create(PROXY_USER_OPTION)); 209 _options.addOption(new OptionBuilder().withArgName("password") 210 .hasArg() 211 .withDescription("[optional] Password for the proxy. If this option is omitted, then cvsgrab will prompt securely for the password.") 212 .create(PROXY_PASSWORD_OPTION)); 213 _options.addOption(new OptionBuilder().withArgName("user") 214 .hasArg() 215 .withDescription("[optional] Username for the web server") 216 .create(WEB_USER_OPTION)); 217 _options.addOption(new OptionBuilder().withArgName("password") 218 .hasArg() 219 .withDescription("[optional] Password for the web server. If this option is omitted, then cvsgrab will prompt securely for the password.") 220 .create(WEB_PASSWORD_OPTION)); 221 } 222 223 228 public static void main(String [] args) { 229 System.setProperty(LogFactoryImpl.LOG_PROPERTY, CVSGrabLog.class.getName()); 230 CVSGrab grabber = new CVSGrab(); 231 try { 232 grabber.run(args); 233 } catch (ParseException e) { 234 System.err.println(e.getMessage()); 235 grabber.printHelp(); 236 } 237 } 238 239 private void run(String [] args) throws ParseException { 240 CommandLineParser parser = new GnuParser(); 241 CommandLine cmd = parser.parse( _options, args); 242 243 if (cmd.hasOption(HELP_CMD)) { 245 printHelp(); 246 return; 247 } 248 if (cmd.hasOption(LIST_WEB_INTERFACES_CMD)) { 249 printWebInterfaces(); 250 return; 251 } 252 253 cvsgrabLogLevel("info", "WARNING"); 255 httpclientLogLevel("error", "SEVERE"); 256 257 if (cmd.hasOption(DEBUG_OPTION)) { 258 cvsgrabLogLevel("trace", "FINEST"); 259 httpclientLogLevel("info", "INFO"); 260 } 261 if (cmd.hasOption(DEBUG_WIRE_OPTION)) { 262 httpclientLogLevel("trace", "FINEST"); 263 logLevel("httpclient.wire", "trace", "FINE"); 264 } 265 if (cmd.hasOption(VERBOSE_OPTION)) { 266 cvsgrabLogLevel("debug", "INFO"); 267 httpclientLogLevel("error", "SEVERE"); 268 } 269 if (cmd.hasOption(QUIET_OPTION)) { 270 cvsgrabLogLevel("warn", "INFO"); 271 httpclientLogLevel("error", "SEVERE"); 272 } 273 274 Properties webProperties = new Properties (); 276 for (int i = 0; i < WEB_OPTIONS.length; i++) { 277 String option = WEB_OPTIONS[i]; 278 if (cmd.hasOption(option)) { 279 webProperties.put(option, cmd.getOptionValue(option)); 280 } 281 } 282 _webOptions.readProperties(webProperties); 283 284 286 if (cmd.hasOption(PROJECT_ROOT_OPTION)) { 292 setCvsRoot(cmd.getOptionValue(PROJECT_ROOT_OPTION)); 293 } 294 if (cmd.hasOption(CVS_ROOT_OPTION)) { 295 setCvsRoot(cmd.getOptionValue(CVS_ROOT_OPTION)); 296 } 297 if (cmd.hasOption(DEST_DIR_OPTION)) { 298 setDestDir(cmd.getOptionValue(DEST_DIR_OPTION)); 299 } 300 if (cmd.hasOption(PACKAGE_DIR_OPTION)) { 301 setPackageDir(cmd.getOptionValue(PACKAGE_DIR_OPTION)); 302 } 303 if (cmd.hasOption(PRUNE_OPTION)) { 304 setPruneEmptyDirs(true); 305 } 306 if (cmd.hasOption(CLEAN_UPDATE_OPTION)) { 307 setCleanUpdate(true); 308 } 309 310 _webOptions.setupConnectionSettings(); 312 if (cmd.hasOption(CONNECTIONS_OPTION)) { 313 int connections = Integer.parseInt(cmd.getOptionValue(CONNECTIONS_OPTION)); 314 if (connections > 1) { 315 ThreadPool.init(connections); 316 WebBrowser.getInstance().useMultithreading(); 317 } 318 } 319 320 String cvsGrabHome = System.getProperty("cvsgrab.home"); 322 File file = new File (cvsGrabHome, "FileTypes.properties"); 323 try { 324 Properties fileTypes = new Properties (); 325 InputStream is = new FileInputStream (file); 326 fileTypes.load(is); 327 RemoteFile.setFileTypes(fileTypes); 328 } catch (IOException ex) { 329 getLog().error("Cannot read the file " + file.getPath()); 330 } 331 332 if (cmd.hasOption(URL_OPTION)) { 334 setUrl(cmd.getOptionValue(URL_OPTION)); 335 } 336 337 if (cmd.hasOption(DIFF_CMD)) { 338 diffCVSRepository(); 339 } else { 340 grabCVSRepository(); 341 } 342 } 343 344 private static void cvsgrabLogLevel(String simpleLevel, String jdk14Level) { 345 logLevel("net.sourceforge.cvsgrab", simpleLevel, jdk14Level); 346 } 347 348 private static void httpclientLogLevel(String simpleLevel, String jdk14Level) { 349 logLevel("org.apache.commons.httpclient", simpleLevel, jdk14Level); 350 } 351 352 private static void logLevel(String packageName, String simpleLevel, String jdk14Level) { 353 if (SystemUtils.isJavaVersionAtLeast(1.4f)) { 354 setJdk14LogLevel(packageName + ".level", jdk14Level); 355 } 356 System.setProperty("org.apache.commons.logging.simplelog.log." + packageName, simpleLevel); 357 } 358 359 362 private static void setJdk14LogLevel(String className, String level) { 363 try { 364 Class loggerClass = Class.forName("java.util.logging.Logger"); 365 Class levelClass = Class.forName("java.util.logging.Level"); 366 Object logger = loggerClass.getMethod("getLogger", new Class [] {String .class}).invoke(null, new Object [] {className}); 367 Object levelObj = levelClass.getField(level).get(null); 368 loggerClass.getMethod("setLevel", new Class [] {levelClass}).invoke(logger, new Object [] {levelObj}); 369 } catch (Exception ex) { 370 System.err.println("Cannot change the configuration of the Java 1.4 logger"); 371 ex.printStackTrace(); 372 } 373 } 374 375 378 public void printHelp() { 379 HelpFormatter formatter = new HelpFormatter(); 381 formatter.printHelp(HelpFormatter.DEFAULT_WIDTH, "cvsgrab", "where options are", 382 _options, "CVSGrab version " + VERSION +", copyright (c) 2002-2004 - Ludovic Claude.", false); 383 } 384 385 388 public static void printWebInterfaces() { 389 System.out.println("CVSGrab version " + VERSION); 390 System.out.println("Currently supporting the following web interfaces:"); 391 String [] webInterfaces = CvsWebInterface.getInterfaceIds(new CVSGrab()); 392 for (int i = 0; i < webInterfaces.length; i++) { 393 System.out.println("\t" + webInterfaces[i]); 394 } 395 System.out.println("Those ids can be use with the -webInterface option to force cvsgrab to use a specific web interface."); 396 } 397 398 403 public boolean getPruneEmptyDirs() { 404 return _pruneEmptyDirs; 405 } 406 407 412 public void setPruneEmptyDirs(boolean value) { 413 _pruneEmptyDirs = value; 414 } 415 416 421 public boolean isCleanUpdate() { 422 return _cleanUpdate; 423 } 424 425 430 public void setCleanUpdate(boolean cleanUpdate) { 431 _cleanUpdate = cleanUpdate; 432 } 433 434 437 public String getRootUrl() { 438 return _webOptions.getRootUrl(); 439 } 440 441 444 public String getPackagePath() { 445 return _webOptions.getPackagePath(); 446 } 447 448 451 public String getDestDir() { 452 return _destDir; 453 } 454 455 459 public void setDestDir(String destDir) { 460 _destDir = WebBrowser.forceFinalSlash(destDir); 461 } 462 463 466 public String getPackageDir() { 467 if (_packageDir == null) { 468 return getPackagePath(); 469 } 470 return _packageDir; 471 } 472 473 476 public void setPackageDir(String packageDir) { 477 _packageDir = WebBrowser.forceFinalSlash(packageDir); 478 } 479 480 483 public String getCvsRoot() { 484 return _cvsRoot; 485 } 486 487 492 public void setCvsRoot(String cvsRoot) { 493 _cvsRoot = WebBrowser.forceFinalSlash(cvsRoot); 494 } 495 496 499 public String getProjectRoot() { 500 return _webOptions.getProjectRoot(); 501 } 502 503 506 public String getVersionTag() { 507 return _webOptions.getVersionTag(); 508 } 509 510 513 public String getQueryParams() { 514 return _webOptions.getQueryParams(); 515 } 516 517 521 public String getWebInterfaceId() { 522 return _webOptions.getWebInterfaceId(); 523 } 524 525 528 public WebOptions getWebOptions() { 529 return _webOptions; 530 } 531 532 535 public void setUrl(String url) { 536 Properties webProperties; 537 if (getWebInterfaceId() != null) { 538 try { 539 webProperties = getWebInterface().guessWebProperties(url); 540 } catch (Exception e) { 541 getLog().error(e.getMessage()); 542 _error = true; 543 return; 544 } 545 } else { 546 webProperties = CvsWebInterface.getWebProperties(this, url); 547 _webInterface = (CvsWebInterface) webProperties.get(CvsWebInterface.DETECTED_WEB_INTERFACE); 548 } 549 _webOptions.readProperties(webProperties); 551 } 552 553 556 public void grabCVSRepository() { 557 printHeader(); 558 loadExistingAdminFiles(); 559 560 if (!checkMandatoryParameters()) return; 561 562 try { 563 checkDestDir(); 564 checkWebConnection(); 565 566 CvsWebInterface webInterface = getWebInterface(); 567 568 LocalRepository localRepository = new LocalRepository(this); 569 RemoteRepository remoteRepository = new RemoteRepository(getRootUrl(), localRepository); 570 remoteRepository.setWebInterface(webInterface); 571 572 RemoteDirectory remoteDir = new RemoteDirectory(remoteRepository, getPackagePath(), getPackageDir()); 573 remoteRepository.registerDirectoryToProcess(remoteDir); 574 while (remoteRepository.hasDirectoryToProcess()) { 575 try { 576 remoteDir = remoteRepository.nextDirectoryToProcess(); 577 remoteDir.loadContents(); 578 localRepository.cleanRemovedFiles(remoteDir); 579 } catch (Exception ex) { 580 ex.printStackTrace(); 581 getLog().error("Error while getting files from " + remoteDir.getUrl()); 582 _error = true; 583 } 584 } 585 if (_pruneEmptyDirs) { 586 localRepository.pruneEmptyDirectories(); 587 } 588 589 int newFileCount = localRepository.getNewFileCount(); 591 int updatedFileCount = localRepository.getUpdatedFileCount(); 592 int removedFileCount = localRepository.getRemovedFileCount(); 593 int failedUpdateCount = localRepository.getFailedUpdateCount(); 594 getLog().info("-----"); 595 if (newFileCount > 0) { 596 getLog().info(newFileCount + " new files"); 597 } 598 if (updatedFileCount > 0) { 599 getLog().info(updatedFileCount + " updated files"); 600 } 601 if (removedFileCount > 0) { 602 getLog().info(removedFileCount + " removed files"); 603 } 604 if (failedUpdateCount > 0) { 605 getLog().error(failedUpdateCount + " files could not be downloaded"); 606 } 607 } catch (Exception ex) { 608 getLog().error(ex.getMessage()); 609 _error = true; 610 } 611 612 if (ThreadPool.getInstance() != null) { 613 ThreadPool.getInstance().destroy(); 614 } 615 616 if (_error) { 617 getLog().error("There were some errors."); 618 getLog().error("If you cannot find an obvious answer, report the problem to " + FORUM_URL); 619 } 620 } 621 622 625 public void diffCVSRepository() { 626 printHeader(); 627 loadExistingAdminFiles(); 628 629 if (!checkMandatoryParameters()) return; 630 631 try { 632 checkDestDir(); 633 checkWebConnection(); 634 635 CvsWebInterface webInterface = getWebInterface(); 636 File diffFile = new File ("patch.txt"); 637 PrintWriter writer = new PrintWriter (new BufferedWriter (new FileWriter (diffFile))); 638 639 LocalRepository localRepository = new LocalRepository(this); 640 RemoteRepository remoteRepository = new RemoteRepository(getRootUrl(), localRepository); 641 remoteRepository.setWebInterface(webInterface); 642 643 RemoteDirectory remoteDir = new RemoteDirectory(remoteRepository, getPackagePath(), getPackageDir()); 644 remoteRepository.registerDirectoryToProcess(remoteDir); 645 while (remoteRepository.hasDirectoryToProcess()) { 646 try { 647 remoteDir = remoteRepository.nextDirectoryToProcess(); 648 remoteDir.diffContents(writer); 649 writer.flush(); 650 } catch (Exception ex) { 651 ex.printStackTrace(); 652 getLog().error("Error while getting files from " + remoteDir.getUrl()); 653 _error = true; 654 } 655 } 656 writer.close(); 657 658 int newFileCount = localRepository.getNewFileCount(); 660 int updatedFileCount = localRepository.getUpdatedFileCount(); 661 int removedFileCount = localRepository.getRemovedFileCount(); 662 int failedUpdateCount = localRepository.getFailedUpdateCount(); 663 getLog().info("-----"); 664 if (newFileCount > 0) { 665 getLog().info(newFileCount + " new files"); 666 } 667 if (updatedFileCount > 0) { 668 getLog().info(updatedFileCount + " updated files"); 669 } 670 if (removedFileCount > 0) { 671 getLog().info(removedFileCount + " removed files"); 672 } 673 if (failedUpdateCount > 0) { 674 getLog().error(failedUpdateCount + " files could not be downloaded"); 675 } 676 getLog().info("Differences stored in " + diffFile.getAbsolutePath()); 677 } catch (Exception ex) { 678 ex.printStackTrace(); 679 getLog().error(ex.getMessage()); 680 _error = true; 681 } 682 683 if (ThreadPool.getInstance() != null) { 684 ThreadPool.getInstance().destroy(); 685 } 686 687 if (_error) { 688 getLog().error("There were some errors."); 689 getLog().error("If you cannot find an obvious answer, report the problem to " + FORUM_URL); 690 } 691 } 692 693 private CvsWebInterface getWebInterface() throws Exception { 694 if (_webInterface == null) { 695 if (getWebInterfaceId() != null) { 696 _webInterface = CvsWebInterface.getInterface(this, getWebInterfaceId()); 698 } else { 699 _webInterface = detectWebInterface(); 701 } 702 } 703 if (_webInterface == null) { 704 getLog().error("Could not detect the type of the web interface"); 705 throw new RuntimeException ("Could not detect the type of the web interface"); 706 } else { 707 getLog().info("Detected cvs web interface: " + _webInterface.getType()); 708 } 709 710 _webInterface.setQueryParams(getQueryParams()); 711 if (getVersionTag() != null) { 712 _webInterface.setVersionTag(getVersionTag()); 713 } 714 return _webInterface; 715 } 716 717 private void checkWebConnection() throws Exception { 718 String [] urls = CvsWebInterface.getBaseUrls(this); 720 Map errors = new HashMap (); 721 for (int i = 0; i < urls.length; i++) { 722 try { 723 getLog().debug("Connecting to " + urls[i]); 724 GetMethod connectMethod = new GetMethod(urls[i]); 725 WebBrowser.getInstance().executeMethod(connectMethod, urls[i]); 726 getLog().debug("Connection successful"); 727 return; 728 } catch (Exception ex) { 729 errors.put(urls[i], ex.getMessage()); 730 } 731 } 732 for (Iterator i = errors.keySet().iterator(); i.hasNext();) { 733 String url = (String ) i.next(); 734 System.err.println("When attempting to connect to " + url + ", got error: " + errors.get(url)); 735 } 736 throw new Exception ("Cannot connect to the website, check your proxy settings"); 737 } 738 739 private void checkDestDir() { 740 File dd = new File (_destDir); 741 if (!dd.exists()) { 742 throw new RuntimeException ("Destination directory " + _destDir + " doesn't exist"); 743 } 744 if (!dd.isDirectory()) { 745 throw new RuntimeException ("Destination " + _destDir + " is not a directory"); 746 } 747 try { 748 _destDir = dd.getCanonicalPath().replace(File.separatorChar, '/'); 749 } catch (IOException ex) { 750 throw new IllegalArgumentException ("Could not locate the destination directory " + _destDir + ", error was " + ex.getMessage()); 751 } 752 } 753 754 private boolean checkMandatoryParameters() { 755 if (getRootUrl() == null || getPackagePath() == null) { 756 if (getRootUrl() == null) { 757 System.out.println("Error: rootUrl parameter is mandatory"); 758 } 759 if (getPackagePath() == null) { 760 System.out.println("Error: packagePath parameter is mandatory"); 761 } 762 printHelp(); 763 return false; 764 } 765 return true; 766 } 767 768 private void loadExistingAdminFiles() { 769 File webRepositoryAdmin = new File (_destDir, "CVS/WebRepository"); 771 if (webRepositoryAdmin.exists()) { 772 Properties webProperties = new Properties (); 773 try { 774 webProperties.load(new FileInputStream (webRepositoryAdmin)); 775 _webOptions.writeProperties(webProperties); 777 _webOptions.readProperties(webProperties); 779 if (getDestDir().equals(DEFAULT_DEST_DIR)) { 781 File currentDir = new File ("."); 782 currentDir = currentDir.getAbsoluteFile(); 783 setPackageDir(currentDir.getName()); 784 } 785 } catch (IOException e) { 786 getLog().warn("Cannot read file " + webRepositoryAdmin.getAbsolutePath(), e); 787 } 788 } 789 File rootAdmin = new File (_destDir, "CVS/Root"); 791 if (rootAdmin.exists() && _cvsRoot.equals(DUMMY_ROOT)) { 792 try { 793 FileReader reader = new FileReader (rootAdmin); 794 LineNumberReader lnReader = new LineNumberReader (reader); 795 _cvsRoot = lnReader.readLine(); 796 } catch (IOException e) { 797 getLog().warn("Cannot read file " + rootAdmin.getAbsolutePath(), e); 798 } 799 } 800 } 801 802 private void printHeader() { 803 if (getLog().isInfoEnabled()) { 804 getLog().info("CVSGrab version " + VERSION + " starting..."); 805 } else { 806 System.out.println("CVSGrab version " + VERSION + " starting..."); 807 } 808 } 809 810 private CvsWebInterface detectWebInterface() { 811 CvsWebInterface webInterface = null; 812 try { 813 webInterface = CvsWebInterface.findInterface(this); 814 } catch (Exception ex) { 815 ex.printStackTrace(); 816 } 817 return webInterface; 818 } 819 820 } 821 | Popular Tags |