Example #1
0
  /**
   * Execute a command. Do not forget to initialize the CVS Root on globalOptions first! Example:
   * <code>
   *   GlobalOptions options = new GlobalOptions();
   *   options.setCVSRoot(":pserver:"+userName+"@"+hostName+":"+cvsRoot);
   * </code>
   *
   * @param command the command to execute
   * @param options the global options to use for executing the command
   * @throws CommandException if an error occurs when executing the command
   * @throws CommandAbortedException if the command is aborted
   */
  public boolean executeCommand(Command command, GlobalOptions globalOptions)
      throws CommandException, CommandAbortedException, AuthenticationException {
    BugLog.getInstance().assertNotNull(command);
    BugLog.getInstance().assertNotNull(globalOptions);

    this.globalOptions = globalOptions;

    getUncompressedFileHandler().setGlobalOptions(globalOptions);
    getGzipFileHandler().setGlobalOptions(globalOptions);

    try {
      eventManager.addCVSListener(command);
      command.execute(this, eventManager);
    } finally {
      eventManager.removeCVSListener(command);
    }
    return !command.hasFailed();
  }
Example #2
0
  /**
   * Ensures, that the connection is open.
   *
   * @throws AuthenticationException if it wasn't possible to connect
   */
  public void ensureConnection() throws AuthenticationException {
    BugLog.getInstance().assertNotNull(getConnection());

    if (getConnection().isOpen()) {
      return;
    }

    // #69689 detect silent servers, possibly caused by proxy errors
    final Throwable ex[] = new Throwable[1];
    final boolean opened[] = new boolean[] {false};
    Runnable probe =
        new Runnable() {
          public void run() {
            try {
              getConnection().open();
              synchronized (opened) {
                opened[0] = true;
              }
            } catch (Throwable e) {
              synchronized (ex) {
                ex[0] = e;
              }
            }
          }
        };

    Thread probeThread = new Thread(probe, "CVS Server Probe"); // NOI18N
    probeThread.start();
    try {

      probeThread.join(60 * 1000); // 1 min

      Throwable wasEx;
      synchronized (ex) {
        wasEx = ex[0];
      }
      if (wasEx != null) {
        if (wasEx instanceof CommandAbortedException) {
          // User cancelled
          abort();
          return;
        } else if (wasEx instanceof AuthenticationException) {
          throw (AuthenticationException) wasEx;
        } else if (wasEx instanceof RuntimeException) {
          throw (RuntimeException) wasEx;
        } else if (wasEx instanceof Error) {
          throw (Error) wasEx;
        } else {
          assert false : wasEx;
        }
      }

      boolean wasOpened;
      synchronized (opened) {
        wasOpened = opened[0];
      }
      if (wasOpened == false) {
        probeThread.interrupt();
        throw new AuthenticationException(
            "Timeout, no response from server.", "Timeout, no response from server.");
      }

    } catch (InterruptedException e) {

      // User cancelled
      probeThread.interrupt();
      abort();
    }
  }