Beispiel #1
0
  /**
   * Get a list of files which are in the repository, but which are not in the local project. This
   * includes both files which have been locally deleted, and files which have been added to the
   * repository from another location.
   *
   * <p>Throws CommandAbortedException if command aborted.
   *
   * @param client the client for processing the commands
   * @param files the list to store the discovered files in (may be null)
   * @param path the path to look at
   * @param remoteDirs a set to store all encountered remote directories in
   * @param localDirs whether to only look at directories which also exist locally
   * @throws InvalidCvsRootException
   * @throws AuthenticationException
   * @throws CommandException
   */
  private void getRemoteFiles(
      Client client, List files, File path, Set remoteDirs, boolean localDirs)
      throws AuthenticationException, CommandAbortedException, CommandException {
    UpdateServerResponse updateResponse = getUpdateServerResponse(client, path.getAbsolutePath());
    List updated = updateResponse.getUpdated();
    Iterator i = updated.iterator();
    while (i.hasNext()) {
      CvsUpdateResult ur = (CvsUpdateResult) i.next();
      File f = new File(path, ur.getFilename());
      remoteDirs.add(f.getParentFile());
      if (files != null && !f.exists()) {
        files.add(f);
      }
    }

    // Now recurse into any new directories which were discovered.
    List newDirs = updateResponse.getNewDirectoryNames();
    i = newDirs.iterator();
    while (i.hasNext()) {
      String newDirName = i.next().toString();
      File localPath = new File(path, newDirName);
      if (!localDirs || localPath.isDirectory()) {
        remoteDirs.add(localPath);
        getRemoteFiles(client, files, localPath, remoteDirs, localDirs);
      }
    }
  }
Beispiel #2
0
 /**
  * Get the locally deleted files (files which are under version control, and which existed
  * locally, but which have been deleted locally).
  *
  * @param set The set to store the locally deleted files in
  * @param dir The directory to look for deleted files in (non-recursively)
  * @throws IOException
  */
 public void getLocallyDeletedFiles(Set set, File dir) throws IOException {
   Iterator i = adminHandler.getEntries(dir);
   while (i.hasNext()) {
     Entry entry = (Entry) i.next();
     File file = new File(dir, entry.getName());
     if (!file.exists() && !entry.isDirectory()) {
       set.add(new File(dir, entry.getName()));
     }
   }
 }
Beispiel #3
0
  /**
   * Convert a List of Files to an array of Files.
   *
   * @param fileList
   */
  static File[] listToFileArray(Collection<File> fileList) {
    File[] files = new File[fileList.size()];
    int j = 0;

    for (Iterator<File> i = fileList.iterator(); i.hasNext(); ) {
      File file = (File) i.next();
      files[j++] = file;
    }

    return files;
  }
Beispiel #4
0
  /*
   * (non-Javadoc)
   * @see bluej.groupwork.Repository#getAllLocallyDeletedFiles()
   */
  public void getAllLocallyDeletedFiles(Set files) {
    LinkedList stack = new LinkedList();
    stack.add(projectPath);
    Set tempSet = new HashSet();
    FileFilter reposFilter = getMetadataFilter();

    while (!stack.isEmpty()) {
      File dir = (File) stack.remove(0);
      File[] subDirs = dir.listFiles(new DirectoryFilter());
      for (int i = 0; i < subDirs.length; i++) {
        if (reposFilter.accept(subDirs[i])) {
          stack.add(subDirs[i]);
        }
      }
      try {
        getLocallyDeletedFiles(files, dir);
      } catch (IOException ioe) {
      }
    }

    File delDir = new File(projectPath, "CVS");
    delDir = new File(delDir, "deleted");
    if (delDir.exists()) {
      stack.add(delDir);
    }

    while (!stack.isEmpty()) {
      File dir = (File) stack.remove(0);
      File[] subDirs = dir.listFiles(new DirectoryFilter());
      for (int i = 0; i < subDirs.length; i++) {
        if (reposFilter.accept(subDirs[i])) {
          stack.add(subDirs[i]);
        }
      }
      try {
        getLocallyDeletedFiles(tempSet, dir);
        for (Iterator i = tempSet.iterator(); i.hasNext(); ) {
          File file = (File) i.next();
          // map the file back to the real directory
          String fileStr = file.getPath();
          fileStr = fileStr.substring(delDir.getPath().length());
          file = new File(projectPath, fileStr);
          files.add(file);
        }
        tempSet.clear();
      } catch (IOException ioe) {
      }
    }
  }
Beispiel #5
0
  /**
   * Get a list of modules in the repository.
   *
   * @throws InvalidCvsRootException
   * @throws AuthenticationException
   * @throws CommandAbortedException
   * @throws CommandException
   */
  public synchronized UpdateServerResponse doGetModules(Client client, List modules)
      throws AuthenticationException, CommandAbortedException, CommandException {
    // Client client = getClient();
    setupConnection(client);
    client.setAdminHandler(new EmptyAdminHandler());

    CheckoutCommand checkoutCommand = new CheckoutCommand(true, ".");
    checkoutCommand.setRecursive(true);
    checkoutCommand.setPruneDirectories(false);
    globalOptions.setDoNoChanges(true);

    UpdateServerResponse updateServerResponse = new UpdateServerResponse(null, null);
    client.getEventManager().addCVSListener(updateServerResponse);
    client.setLocalPath(projectPath.getAbsolutePath());
    printCommand(checkoutCommand, client);

    try {
      client.executeCommand(checkoutCommand, globalOptions);
      updateServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(updateServerResponse);
      disconnect(client);
      client.setAdminHandler(adminHandler);
      globalOptions.setDoNoChanges(false);
    }

    List projects = updateServerResponse.getNewDirectoryNames();
    for (Iterator i = projects.iterator(); i.hasNext(); ) {
      String projectName = i.next().toString();
      if (!projectName.equals("CVSROOT")) {
        modules.add(projectName);
      }
    }

    return updateServerResponse;
  }