Example #1
0
  /**
   * Removes the specified file determined by pathName and repositoryName. In this implementation
   * the filename from repositoryPath is added to the localpath (which doesn't have the filename in
   * it) and that file is deleted.
   */
  public void removeLocalFile(String pathName, String repositoryName) throws IOException {
    int ind = repositoryName.lastIndexOf('/');
    if (ind <= 0) {
      return;
    }

    String fileName = repositoryName.substring(ind + 1);
    String localFile = pathName + fileName;
    File fileToDelete = new File(getLocalPath(), localFile);
    removeLocalFile(fileToDelete.getAbsolutePath());
    removeEntry(fileToDelete);
  }
Example #2
0
  /**
   * Process all the requests. The connection must have been opened and set first.
   *
   * @param requests the requets to process
   */
  public void processRequests(List requests)
      throws IOException, UnconfiguredRequestException, ResponseException, CommandAbortedException {

    if (requests == null || requests.size() == 0) {
      throw new IllegalArgumentException(
          "[processRequests] requests "
              + // NOI18N
              "was either null or empty."); // NOI18N
    }

    if (abort) {
      throw new CommandAbortedException(
          "Aborted during request processing", // NOI18N
          CommandException.getLocalMessage("Client.commandAborted", null)); // NOI18N
    }

    loggedDataInputStream = null;
    loggedDataOutputStream = null;

    // send the initialisation requests if we are handling the first
    // command
    boolean filterRootRequest = true;
    if (isFirstCommand()) {
      setIsFirstCommand(false);
      int pos = 0;
      if (!initialRequestsSent) {
        pos = fillInitialRequests(requests);
        initialRequestsSent = true;
        filterRootRequest = false;
      }
      if (globalOptions != null) {
        // sends the global options that are to be sent to server (-q, -Q, -t, -n, l)
        for (Iterator it = globalOptions.createRequestList().iterator(); it.hasNext(); ) {
          Request request = (Request) it.next();
          requests.add(pos++, request);
        }

        if (globalOptions.isUseGzip() && globalOptions.getCompressionLevel() != 0) {
          requests.add(pos++, new GzipFileContentsRequest(globalOptions.getCompressionLevel()));
        }
      }
    } else if (printConnectionReuseWarning) {
      if (System.getProperty("javacvs.multiple_commands_warning") == null) { // NOI18N
        System.err.println("WARNING TO DEVELOPERS:"); // NOI18N
        System.err.println(
            "Please be warned that attempting to reuse one open connection for more commands is not supported by cvs servers very well."); // NOI18N
        System.err.println("You are advised to open a new Connection each time."); // NOI18N
        System.err.println(
            "If you still want to proceed, please do: System.setProperty(\"javacvs.multiple_commands_warning\", \"false\")"); // NOI18N
        System.err.println("That will disable this message."); // NOI18N
      }
    }

    if (!ALLOWED_CONNECTION_REUSE_REQUESTS.contains(requests.get(requests.size() - 1).getClass())) {
      printConnectionReuseWarning = true;
    }

    final boolean fireEnhancedEvents = getEventManager().isFireEnhancedEventSet();
    int fileDetailRequestCount = 0;

    if (fireEnhancedEvents) {
      for (Iterator it = requests.iterator(); it.hasNext(); ) {
        Request request = (Request) it.next();

        FileDetails fileDetails = request.getFileForTransmission();
        if (fileDetails != null && fileDetails.getFile().exists()) {
          fileDetailRequestCount++;
        }
      }
      CVSEvent event =
          new EnhancedMessageEvent(
              this, EnhancedMessageEvent.REQUESTS_COUNT, new Integer(fileDetailRequestCount));
      getEventManager().fireCVSEvent(event);
    }

    LoggedDataOutputStream dos = connection.getOutputStream();
    loggedDataOutputStream = dos;

    // this list stores stream modification requests, each to be called
    // to modify the input stream the next time we need to process a
    // response
    List streamModifierRequests = new LinkedList();

    // sending files does not seem to allow compression
    transmitFileHandler = getUncompressedFileHandler();

    for (Iterator it = requests.iterator(); it.hasNext(); ) {
      if (abort) {
        throw new CommandAbortedException(
            "Aborted during request processing", // NOI18N
            CommandException.getLocalMessage("Client.commandAborted", null)); // NOI18N
      }

      final Request request = (Request) it.next();

      if (request instanceof GzipFileContentsRequest) {
        if (dontUseGzipFileHandler) {
          stderr.println(
              "Warning: The server is not supporting gzip-file-contents request, no compression is used.");
          continue;
        }
      }

      // skip the root request if already sent
      if (request instanceof RootRequest) {
        if (filterRootRequest) {
          continue;
        } else { // Even if we should not filter the RootRequest now, we must filter all successive
                 // RootRequests
          filterRootRequest = true;
        }
      }
      // send request to server
      String requestString = request.getRequestString();
      dos.writeBytes(requestString);

      // we must modify the outputstream now, but defer modification
      // of the inputstream until we are about to read a response.
      // This is because some modifiers (e.g. gzip) read the header
      // on construction, and obviously no header is present when
      // no response has been sent
      request.modifyOutputStream(connection);
      if (request.modifiesInputStream()) {
        streamModifierRequests.add(request);
      }
      dos = connection.getOutputStream();

      FileDetails fileDetails = request.getFileForTransmission();
      if (fileDetails != null) {
        final File file = fileDetails.getFile();
        // only transmit the file if it exists! When committing
        // a remove request you cannot transmit the file
        if (file.exists()) {
          Logger.logOutput(
              new String(
                      "<Sending file: "
                          + // NOI18N
                          file.getAbsolutePath()
                          + ">\n")
                  .getBytes("utf8")); // NOI18N

          if (fireEnhancedEvents) {
            CVSEvent event =
                new EnhancedMessageEvent(this, EnhancedMessageEvent.FILE_SENDING, file);
            getEventManager().fireCVSEvent(event);

            fileDetailRequestCount--;
          }

          if (fileDetails.isBinary()) {
            transmitFileHandler.transmitBinaryFile(file, dos);
          } else {
            transmitFileHandler.transmitTextFile(file, dos);
          }

          if (fireEnhancedEvents && fileDetailRequestCount == 0) {
            CVSEvent event =
                new EnhancedMessageEvent(this, EnhancedMessageEvent.REQUESTS_SENT, "Ok"); // NOI18N
            getEventManager().fireCVSEvent(event);
          }
        }
      }
      if (request.isResponseExpected()) {
        dos.flush();

        // now perform the deferred modification of the input stream
        Iterator modifiers = streamModifierRequests.iterator();
        while (modifiers.hasNext()) {
          System.err.println("Modifying the inputstream..."); // NOI18N
          final Request smRequest = (Request) modifiers.next();
          System.err.println(
              "Request is a: "
                  + // NOI18N
                  smRequest.getClass().getName());
          smRequest.modifyInputStream(connection);
        }
        streamModifierRequests.clear();

        handleResponse();
      }
    }
    dos.flush();

    transmitFileHandler = null;
  }
Example #3
0
 public String getRepositoryForDirectory(File directory) throws IOException {
   return adminHandler.getRepositoryForDirectory(directory.getAbsolutePath(), getRepository());
 }
Example #4
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);
  }