Ejemplo n.º 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;
    }
  }
Ejemplo n.º 2
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();
    }
  }
Ejemplo n.º 3
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);
  }