示例#1
0
 public Command createCommand(String[] args, int index, GlobalOptions gopt, String workDir) {
   RemoveCommand command = new RemoveCommand();
   command.setBuilder(null);
   final String getOptString = command.getOptString();
   GetOpt go = new GetOpt(args, getOptString);
   int ch = -1;
   go.optIndexSet(index);
   boolean usagePrint = false;
   while ((ch = go.getopt()) != go.optEOF) {
     boolean ok = command.setCVSCommand((char) ch, go.optArgGet());
     if (!ok) {
       usagePrint = true;
     }
   }
   if (usagePrint) {
     throw new IllegalArgumentException(getUsage());
   }
   int fileArgsIndex = go.optIndexGet();
   // test if we have been passed any file arguments
   if (fileArgsIndex < args.length) {
     File[] fileArgs = new File[args.length - fileArgsIndex];
     // send the arguments as absolute paths
     if (workDir == null) {
       workDir = System.getProperty("user.dir");
     }
     File workingDir = new File(workDir);
     for (int i = fileArgsIndex; i < args.length; i++) {
       fileArgs[i - fileArgsIndex] = new File(workingDir, args[i]);
     }
     command.setFiles(fileArgs);
   }
   return command;
 }
示例#2
0
  /**
   * Remove the files in an array of Files from the repository.
   *
   * @param files the files to remove.
   * @throws CommandException
   * @throws CommandAbortedException
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   */
  BasicServerResponse removeFromRepository(Client client, Collection files)
      throws CommandException, CommandAbortedException, AuthenticationException {
    BasicServerResponse basicServerResponse = new BasicServerResponse();

    if (files.size() < 1) {
      basicServerResponse.commandTerminated(null);
      return basicServerResponse;
    }

    setupConnection(client);
    // setupConnection();
    // Client client = getClient();

    RemoveCommand removeCommand = new RemoveCommand();
    removeCommand.setFiles(listToFileArray(files));

    client.getEventManager().addCVSListener(basicServerResponse);
    client.setLocalPath(projectPath.getAbsolutePath());

    printCommand(removeCommand, client);
    try {
      adminHandler.setMildManneredMode(true);
      client.executeCommand(removeCommand, globalOptions);
      basicServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(basicServerResponse);
      disconnect(client);
      adminHandler.setMildManneredMode(false);
    }

    return basicServerResponse;
  }