示例#1
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;
    }
  }
示例#2
0
  /** Create file CVS/Baserev with entries like BEntry.java/1.2/ */
  private void addBaserevEntry(ClientServices clientServices, File file) throws IOException {
    final Entry entry = clientServices.getEntry(file);
    if (entry == null
        || entry.getRevision() == null
        || entry.isNewUserFile()
        || entry.isUserFileToBeRemoved()) {
      throw new IllegalArgumentException(
          "File does not have an Entry or Entry is invalid!"); // NOI18N
    }

    File baserevFile = new File(file.getParentFile(), "CVS/Baserev"); // NOI18N
    File backupFile = new File(baserevFile.getAbsolutePath() + '~');
    BufferedReader reader = null;
    BufferedWriter writer = null;
    boolean append = true;
    boolean writeFailed = true;
    final String entryStart = 'B' + file.getName() + '/';
    try {
      writer = new BufferedWriter(new FileWriter(backupFile));
      writeFailed = false;
      reader = new BufferedReader(new FileReader(baserevFile));

      for (String line = reader.readLine(); line != null; line = reader.readLine()) {

        if (line.startsWith(entryStart)) {
          append = false;
        }
        writeFailed = true;
        writer.write(line);
        writer.newLine();
        writeFailed = false;
      }
    } catch (IOException ex) {
      if (writeFailed) {
        throw ex;
      }
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException ex) {
          // ignore
        }
      }
      if (writer != null) {
        try {
          if (append && !writeFailed) {
            writer.write(entryStart + entry.getRevision() + '/');
            writer.newLine();
          }
        } finally {
          try {
            writer.close();
          } catch (IOException ex) {
            // ignore
          }
        }
      }
    }
    baserevFile.delete();
    backupFile.renameTo(baserevFile);
  }