private void setLocalDirectory(Client client, File[] files) throws IllegalCommandException {
    if (files.length == 0) {
      return;
    }

    File commonParent;

    if (files[0].isDirectory()) { // XXX it does not work for checkout
      commonParent = files[0];
    } else {
      commonParent = files[0].getParentFile();
    }

    for (int i = 1; i < files.length; i++) {
      if (!Utils.isParentOrEqual(commonParent, files[i])) {
        for (; ; ) {
          commonParent = commonParent.getParentFile();
          if (commonParent == null)
            throw new IllegalCommandException("Files do not have common parent!"); // NOI18N
          if (Utils.isParentOrEqual(commonParent, files[i])) {
            break;
          }
        }
      }
    }

    // we must not run commands from within folders that are not yet in CVS, try to find the closest
    // uptodate parent
    FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache();
    for (File versionedCommonParent = commonParent;
        versionedCommonParent != null;
        versionedCommonParent = versionedCommonParent.getParentFile()) {
      FileInformation info = cache.getStatus(versionedCommonParent);
      if (info.getStatus() == FileInformation.STATUS_VERSIONED_UPTODATE) {
        commonParent = versionedCommonParent;
        break;
      }
    }
    client.setLocalPath(commonParent.getAbsolutePath());
  }
 private void ensureValidCommand(File[] files) throws IllegalCommandException {
   for (int i = 0; i < files.length; i++) {
     File file = files[i];
     try {
       String root = Utils.getCVSRootFor(file);
       if (!root.equals(cvsRoot))
         throw new IllegalCommandException(
             "#63547 command includes files from different CVS root.\n Expected: "
                 + cvsRoot
                 + "\nGot:     "
                 + root); // NOI18N
     } catch (IOException e) {
       throw new IllegalCommandException("Missing or invalid CVS/Root for: " + file); // NOI18N
     }
   }
 }
Beispiel #3
0
 /**
  * Returns the widest possible versioned context for the given file, the outter boundary is the
  * file's Project.
  *
  * @param file a file
  * @return Context a context
  */
 public static Context getProjectContext(Project project, File file) {
   Context context = Utils.getProjectsContext(new Project[] {project});
   if (context.getRootFiles().length == 0) {
     // the project itself is not versioned, try to search in the broadest context possible
     FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache();
     for (; ; ) {
       File parent = file.getParentFile();
       assert parent != null;
       if ((cache.getStatus(parent).getStatus() & FileInformation.STATUS_IN_REPOSITORY) == 0) {
         Set<File> files = new HashSet<File>(1);
         files.add(file);
         context = new Context(files, files, Collections.emptySet());
         break;
       }
       file = parent;
     }
   }
   return context;
 }