Пример #1
0
  @Nullable
  private static VirtualFile getVcsRootForLibraryFile(
      @NotNull Project project, @NotNull VirtualFile file) {
    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    // for a file inside .jar/.zip consider the .jar/.zip file itself
    VirtualFile root = vcsManager.getVcsRootFor(VfsUtilCore.getVirtualFileForJar(file));
    if (root != null) {
      LOGGER.debug("Found root for zip/jar file: " + root);
      return root;
    }

    // for other libs which don't have jars inside the project dir (such as JDK) take the owner
    // module of the lib
    List<OrderEntry> entries =
        ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
    Set<VirtualFile> libraryRoots = new HashSet<VirtualFile>();
    for (OrderEntry entry : entries) {
      if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
        VirtualFile moduleRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
        if (moduleRoot != null) {
          libraryRoots.add(moduleRoot);
        }
      }
    }

    if (libraryRoots.size() == 0) {
      LOGGER.debug("No library roots");
      return null;
    }

    // if the lib is used in several modules, take the top module
    // (for modules of the same level we can't guess anything => take the first one)
    Iterator<VirtualFile> libIterator = libraryRoots.iterator();
    VirtualFile topLibraryRoot = libIterator.next();
    while (libIterator.hasNext()) {
      VirtualFile libRoot = libIterator.next();
      if (VfsUtilCore.isAncestor(libRoot, topLibraryRoot, true)) {
        topLibraryRoot = libRoot;
      }
    }
    LOGGER.debug("Several library roots, returning " + topLibraryRoot);
    return topLibraryRoot;
  }
 @NotNull
 private Collection<VirtualFile> getSelectedRoots() {
   ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
   Collection<VirtualFile> result = new HashSet<VirtualFile>();
   for (FilePath path : ChangesUtil.getPaths(myPanel.getSelectedChanges())) {
     VirtualFile root = vcsManager.getVcsRootFor(path);
     if (root != null) {
       result.add(root);
     }
   }
   return result;
 }
 @Nullable
 private VirtualFile getRootForPath(final String s) {
   return myVcsManager.getVcsRootFor(VcsUtil.getFilePath(s, false));
 }
 @Nullable
 private VirtualFile getRootForPath(final String s) {
   return myVcsManager.getVcsRootFor(new FilePathImpl(new File(s), false));
 }