示例#1
0
 private File[] getCommandFiles(Command cmd) {
   if (cmd instanceof AddCommand) {
     AddCommand c = (AddCommand) cmd;
     return c.getFiles();
   } else if (cmd instanceof BasicCommand) {
     BasicCommand c = (BasicCommand) cmd;
     return c.getFiles();
   } else {
     return new File[0];
   }
 }
示例#2
0
  /**
   * Creates a task that will execute the given command.
   *
   * @param cmd command to schedule
   * @param globalOptions options to use when running the command
   * @param mgr listener for command events
   * @return RequestProcessor.Task a task ready to execute the command
   * @throws IllegalCommandException if the command is not valid, e.g. it contains files that cannot
   *     be processed by a single command (they do not have a common filesystem root OR their CVS
   *     Roots differ)
   */
  public RequestProcessor.Task createTask(
      Command cmd, GlobalOptions globalOptions, final ExecutorSupport mgr)
      throws IllegalCommandException {

    File[] files = getCommandFiles(cmd);
    if ((cmd instanceof CheckoutCommand) == false && !(cmd instanceof RlogCommand)) { // XXX
      ensureValidCommand(files);
    }

    if (globalOptions.getCVSRoot() == null) {
      globalOptions = (GlobalOptions) globalOptions.clone();
      globalOptions.setCVSRoot(cvsRoot);
    }

    Client client = createClient();
    if ((cmd instanceof RlogCommand)) { // XXX
    } else if ((cmd instanceof CheckoutCommand)) { // XXX
      BasicCommand bc = (BasicCommand) cmd;
      if (bc.getFiles() != null) {
        String path = bc.getFiles()[0].getAbsolutePath();
        client.setLocalPath(path);
      } else {
        // #67315: use some default working dir
        client.setLocalPath(System.getProperty("user.dir")); // NOI18N
      }
    } else if (cmd instanceof ImportCommand) {
      client.setLocalPath(((ImportCommand) cmd).getImportDirectory());
    } else {
      setLocalDirectory(client, files);
    }

    client.getEventManager().addCVSListener(mgr);
    final CommandRunnable cr = new CommandRunnable(client, globalOptions, cmd, mgr);
    mgr.commandEnqueued(cr);
    RequestProcessor.Task task = requestProcessor.create(cr);
    task.addTaskListener(
        new TaskListener() {
          public void taskFinished(Task task) {
            try {
              // There are times when 'commandTerminated()' is not the last method called, therefore
              // I introduced
              // this event that really marks the very end of a command (thread end)
              mgr.commandTerminated(new TerminationEvent(new Result(cr)));
            } catch (Throwable e) {
              ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
            } finally {
              flushLog();
            }
          }
        });
    return task;
  }
示例#3
0
 @Override
 protected void addArgumentRequests() {
   if (isForceCommit()) {
     Iterator it = requests.iterator();
     String directory = "";
     List args = new LinkedList();
     while (it.hasNext()) {
       Object req = it.next();
       if (req instanceof org.netbeans.lib.cvsclient.request.DirectoryRequest) {
         org.netbeans.lib.cvsclient.request.DirectoryRequest dirReq =
             (org.netbeans.lib.cvsclient.request.DirectoryRequest) req;
         // haven't checked but I'm almost sure that within the Argument request always the local
         // directory is used.
         directory = dirReq.getLocalDirectory();
       } else if (req instanceof org.netbeans.lib.cvsclient.request.EntryRequest) {
         org.netbeans.lib.cvsclient.request.EntryRequest entReq =
             (org.netbeans.lib.cvsclient.request.EntryRequest) req;
         String argument = null;
         if (directory.length() == 0) {
           argument = entReq.getEntry().getName();
         } else {
           argument = directory + '/' + entReq.getEntry().getName();
         }
         args.add(new ArgumentRequest(argument));
       }
     }
     it = args.iterator();
     while (it.hasNext()) {
       requests.add(it.next());
     }
   } else {
     super.addArgumentRequests();
   }
 }
示例#4
0
  /**
   * Executes this command.
   *
   * @param client the client services object that provides any necessary services to this command,
   *     including the ability to actually process all the requests.
   */
  public void execute(ClientServices clientServices, EventManager eventManager)
      throws CommandException {
    this.clientServices = clientServices;
    try {
      clientServices.ensureConnection();

      super.execute(clientServices, eventManager);

      addArgumentRequest(isCheckThatUnedited(), "-c"); // NOI18N
      addArgumentRequest(isForceEvenIfEdited(), "-f"); // NOI18N

      // now add the request that indicates the working directory for the
      // command
      addRequestForWorkingDirectory(clientServices);
      addRequest(CommandRequest.NOOP);

      clientServices.processRequests(requests);
    } catch (AuthenticationException ex) {
      // TODO: handle case, where connection wasn't possible to establish
    } catch (CommandException ex) {
      throw ex;
    } catch (EOFException ex) {
      throw new CommandException(
          ex, CommandException.getLocalMessage("CommandException.EndOfFile", null)); // NOI18N
    } catch (Exception ex) {
      throw new CommandException(ex, ex.getLocalizedMessage());
    } finally {
      requests.clear();
      this.clientServices = null;
    }
  }
示例#5
0
  /**
   * Execute the command.
   *
   * @param client the client services object that provides any necessary services to this command,
   *     including the ability to actually process all the requests
   */
  @Override
  public void execute(ClientServices client, EventManager em)
      throws CommandException, AuthenticationException {
    client.ensureConnection();

    super.execute(client, em);

    try {
      // add arguments.
      if (isForceCommit()) {
        requests.add(1, new ArgumentRequest("-f")); // NOI18N
        if (isRecursive()) {
          requests.add(1, new ArgumentRequest("-R")); // NOI18N
        }
      }
      if (isNoModuleProgram()) {
        requests.add(1, new ArgumentRequest("-n")); // NOI18N
      }
      if (getToRevisionOrBranch() != null) {
        requests.add(1, new ArgumentRequest("-r")); // NOI18N
        requests.add(2, new ArgumentRequest(getToRevisionOrBranch()));
      }

      // build the message to send
      String message = getMessage();
      if (getLogMessageFromFile() != null) {
        message = loadLogFile(getLogMessageFromFile());
      }
      if (message != null) {
        message = message.trim();
      }
      if (message == null || message.length() == 0) {
        message = "no message"; // NOI18N
      }
      addMessageRequest(message);

      addRequestForWorkingDirectory(client);
      requests.addAll(argumentRequests);
      argumentRequests.clear(); // MK sanity check.
      addArgumentRequests();
      requests.add(CommandRequest.COMMIT);

      client.processRequests(requests);
    } catch (CommandException ex) {
      throw ex;
    } catch (Exception ex) {
      throw new CommandException(ex, ex.getLocalizedMessage());
    } finally {
      requests.clear();
    }
  }