@Override
  public void deactivate() {
    FrameStateManager.getInstance().removeListener(myFrameStateListener);

    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
    if (myVcsListener != null) {
      vcsManager.removeVcsListener(myVcsListener);
    }

    if (myEntriesFileListener != null) {
      VirtualFileManager.getInstance().removeVirtualFileListener(myEntriesFileListener);
    }
    SvnApplicationSettings.getInstance().svnDeactivated();
    if (myCommittedChangesProvider != null) {
      myCommittedChangesProvider.deactivate();
    }
    if (myChangeListListener != null && !myProject.isDefault()) {
      ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListListener);
    }
    vcsManager.removeVcsListener(myRootsToWorkingCopies);
    myRootsToWorkingCopies.clear();

    myAuthNotifier.stop();
    myAuthNotifier.clear();

    mySvnBranchPointsCalculator.deactivate();
    mySvnBranchPointsCalculator = null;
    myWorkingCopiesContent.deactivate();
    myLoadedBranchesStorage.deactivate();
    myPool.dispose();
    myPool = null;
  }
Example #2
0
  public SvnVcs(
      final Project project,
      MessageBus bus,
      SvnConfiguration svnConfiguration,
      final SvnLoadedBrachesStorage storage) {
    super(project, VCS_NAME);
    myLoadedBranchesStorage = storage;
    LOG.debug("ct");
    myRootsToWorkingCopies = new RootsToWorkingCopies(this);
    myConfiguration = svnConfiguration;
    myAuthNotifier = new SvnAuthenticationNotifier(this);

    dumpFileStatus(FileStatus.ADDED);
    dumpFileStatus(FileStatus.DELETED);
    dumpFileStatus(FileStatus.MERGE);
    dumpFileStatus(FileStatus.MODIFIED);
    dumpFileStatus(FileStatus.NOT_CHANGED);
    dumpFileStatus(FileStatus.UNKNOWN);

    dumpFileStatus(SvnFileStatus.REPLACED);
    dumpFileStatus(SvnFileStatus.EXTERNAL);
    dumpFileStatus(SvnFileStatus.OBSTRUCTED);

    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    myAddConfirmation =
        vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, this);
    myDeleteConfirmation =
        vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, this);
    myCheckoutOptions =
        vcsManager.getStandardOption(VcsConfiguration.StandardOption.CHECKOUT, this);

    if (myProject.isDefault()) {
      myChangeListListener = null;
      myEntriesFileListener = null;
    } else {
      myEntriesFileListener = new SvnEntriesFileListener(project);
      upgradeIfNeeded(bus);

      myChangeListListener = new SvnChangelistListener(myProject, this);

      myVcsListener =
          new VcsListener() {
            @Override
            public void directoryMappingChanged() {
              invokeRefreshSvnRoots(true);
            }
          };
    }

    myFrameStateListener =
        project.isDefault()
            ? null
            : new MyFrameStateListener(
                ChangeListManager.getInstance(project), VcsDirtyScopeManager.getInstance(project));
    myWorkingCopiesContent = new WorkingCopiesContent(this);

    // remove used some time before old notification group ids
    correctNotificationIds();
    myChecker = new SvnExecutableChecker(myProject);
  }
 public void processChangeLists(final List<LocalChangeList> lists) {
   final ProjectLevelVcsManager plVcsManager =
       ProjectLevelVcsManager.getInstanceChecked(myProject);
   plVcsManager.startBackgroundVcsOperation();
   try {
     final SVNChangelistClient client = createChangelistClient();
     for (LocalChangeList list : lists) {
       if (!list.isDefault()) {
         final Collection<Change> changes = list.getChanges();
         for (Change change : changes) {
           correctListForRevision(
               plVcsManager, change.getBeforeRevision(), client, list.getName());
           correctListForRevision(plVcsManager, change.getAfterRevision(), client, list.getName());
         }
       }
     }
   } finally {
     final Application appManager = ApplicationManager.getApplication();
     if (appManager.isDispatchThread()) {
       appManager.executeOnPooledThread(
           new Runnable() {
             @Override
             public void run() {
               plVcsManager.stopBackgroundVcsOperation();
             }
           });
     } else {
       plVcsManager.stopBackgroundVcsOperation();
     }
   }
 }
 /**
  * This method is called when user invokes "Enable VCS Integration" and selects a particular VCS.
  * By default it sets up a single mapping {@code <Project> -> selected VCS}.
  */
 @CalledInAwt
 public void enableIntegration() {
   ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
   if (vcsManager != null) {
     vcsManager.setDirectoryMappings(Arrays.asList(new VcsDirectoryMapping("", getName())));
   }
 }
  private RemoteRevisionsCache(final Project project) {
    myProject = project;
    myLock = new Object();

    myRemoteRevisionsNumbersCache = new RemoteRevisionsNumbersCache(myProject);
    myRemoteRevisionsStateCache = new RemoteRevisionsStateCache(myProject);

    myChangeDecorator = new RemoteStatusChangeNodeDecorator(this);

    myVcsManager = ProjectLevelVcsManager.getInstance(project);
    myVcsManager.addVcsListener(this);
    myKinds = new HashMap<String, RemoteDifferenceStrategy>();
    Disposer.register(
        project,
        new Disposable() {
          public void dispose() {
            myVcsManager.removeVcsListener(RemoteRevisionsCache.this);
          }
        });
    final VcsConfiguration vcsConfiguration = VcsConfiguration.getInstance(myProject);
    myControlledCycle =
        new ControlledCycle(
            project,
            new Getter<Boolean>() {
              @Override
              public Boolean get() {
                final boolean shouldBeDone =
                    vcsConfiguration.isChangedOnServerEnabled() && myVcsManager.hasActiveVcss();

                if (shouldBeDone) {
                  boolean somethingChanged = myRemoteRevisionsNumbersCache.updateStep();
                  somethingChanged |= myRemoteRevisionsStateCache.updateStep();
                  if (somethingChanged) {
                    myProject.getMessageBus().syncPublisher(REMOTE_VERSION_CHANGED).run();
                  }
                }
                return shouldBeDone;
              }
            },
            "Finishing \"changed on server\" update",
            DEFAULT_REFRESH_INTERVAL);

    updateRoots();

    if ((!myProject.isDefault()) && vcsConfiguration.isChangedOnServerEnabled()) {
      ((ProjectLevelVcsManagerImpl) myVcsManager)
          .addInitializationRequest(
              VcsInitObject.REMOTE_REVISIONS_CACHE,
              new Runnable() {
                public void run() {
                  // do not start if there're no vcses
                  if (!myVcsManager.hasActiveVcss() || !vcsConfiguration.isChangedOnServerEnabled())
                    return;
                  myControlledCycle.startIfNotStarted(-1);
                }
              });
    }
  }
Example #6
0
 public static void addMappingIfSubRoot(
     @NotNull Project project, @NotNull String newRepositoryPath, @NotNull String vcsName) {
   if (project.getBasePath() != null
       && FileUtil.isAncestor(project.getBasePath(), newRepositoryPath, true)) {
     ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
     manager.setDirectoryMappings(
         VcsUtil.addMapping(manager.getDirectoryMappings(), newRepositoryPath, vcsName));
   }
 }
  public void loadSettings() {
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);

    if (getUpdateEnvironment() != null) {
      myUpdateOption = vcsManager.getStandardOption(VcsConfiguration.StandardOption.UPDATE, this);
    }

    if (getStatusEnvironment() != null) {
      myStatusOption = vcsManager.getStandardOption(VcsConfiguration.StandardOption.STATUS, this);
    }
  }
Example #8
0
 @Nullable
 public static HgVcs getInstance(Project project) {
   if (project == null || project.isDisposed()) {
     return null;
   }
   final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
   if (vcsManager == null) {
     return null;
   }
   return (HgVcs) vcsManager.findVcsByName(VCS_NAME);
 }
 private void returnConfirmationBack() {
   if (mySystemOperation) {
     final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
     final VcsShowConfirmationOption addConfirmation =
         vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, null);
     addConfirmation.setValue(myAddconfirmationvalue);
     final VcsShowConfirmationOption deleteConfirmation =
         vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, null);
     deleteConfirmation.setValue(myDeleteconfirmationvalue);
   }
 }
 @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;
 }
Example #11
0
  @Nullable
  private static VirtualFile guessRootForVcs(
      @NotNull Project project, @Nullable AbstractVcs vcs, @Nullable String defaultRootPathValue) {
    if (project.isDisposed()) return null;
    LOG.debug("Guessing vcs root...");
    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    if (vcs == null) {
      LOG.debug("Vcs not found.");
      return null;
    }
    String vcsName = vcs.getDisplayName();
    VirtualFile[] vcsRoots = vcsManager.getRootsUnderVcs(vcs);
    if (vcsRoots.length == 0) {
      LOG.debug("No " + vcsName + " roots in the project.");
      return null;
    }

    if (vcsRoots.length == 1) {
      VirtualFile onlyRoot = vcsRoots[0];
      LOG.debug("Only one " + vcsName + " root in the project, returning: " + onlyRoot);
      return onlyRoot;
    }

    // get remembered last visited repository root
    if (defaultRootPathValue != null) {
      VirtualFile recentRoot = VcsUtil.getVirtualFile(defaultRootPathValue);
      if (recentRoot != null) {
        LOG.debug("Returning the recent root: " + recentRoot);
        return recentRoot;
      }
    }

    // otherwise return the root of the project dir or the root containing the project dir, if there
    // is such
    VirtualFile projectBaseDir = project.getBaseDir();
    if (projectBaseDir == null) {
      VirtualFile firstRoot = vcsRoots[0];
      LOG.debug("Project base dir is null, returning the first root: " + firstRoot);
      return firstRoot;
    }
    VirtualFile rootCandidate;
    for (VirtualFile root : vcsRoots) {
      if (root.equals(projectBaseDir) || VfsUtilCore.isAncestor(root, projectBaseDir, true)) {
        LOG.debug("The best candidate: " + root);
        return root;
      }
    }
    rootCandidate = vcsRoots[0];
    LOG.debug("Returning the best candidate: " + rootCandidate);
    return rootCandidate;
  }
    private void setConfirmationToDefault() {
      if (mySystemOperation) {
        final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
        final VcsShowConfirmationOption addConfirmation =
            vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.ADD, null);
        myAddconfirmationvalue = addConfirmation.getValue();
        addConfirmation.setValue(VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY);

        final VcsShowConfirmationOption deleteConfirmation =
            vcsManager.getStandardConfirmation(VcsConfiguration.StandardConfirmation.REMOVE, null);
        myDeleteconfirmationvalue = deleteConfirmation.getValue();
        deleteConfirmation.setValue(VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY);
      }
    }
 public Collection<AbstractVcs> getAffectedVcses() {
   final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
   final Set<AbstractVcs> vcses =
       new HashSet<AbstractVcs>(Arrays.asList(vcsManager.getAllActiveVcss()));
   final Set<AbstractVcs> result = new HashSet<AbstractVcs>();
   for (Change change : myBrowser.myAllChanges) {
     if (vcses.isEmpty()) break;
     final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, myBrowser.myProject);
     if (vcs != null) {
       result.add(vcs);
       vcses.remove(vcs);
     }
   }
   return result;
 }
  public void loadState(final SvnMappingSavedPart state) {
    ((ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject))
        .addInitializationRequest(
            VcsInitObject.AFTER_COMMON,
            new DumbAwareRunnable() {
              public void run() {
                ApplicationManager.getApplication()
                    .executeOnPooledThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            final SvnMapping mapping = new SvnMapping();
                            final SvnMapping realMapping = new SvnMapping();
                            try {
                              fillMapping(mapping, state.getMappingRoots());
                              fillMapping(realMapping, state.getMoreRealMappingRoots());
                            } catch (ProcessCanceledException e) {
                              throw e;
                            } catch (Throwable t) {
                              LOG.info(t);
                              return;
                            }

                            synchronized (myMonitor) {
                              myMapping.copyFrom(mapping);
                              myMoreRealMapping.copyFrom(realMapping);
                            }
                          }
                        });
              }
            });
  }
 @Override
 public void directoryMappingChanged() {
   GitVcs vcs = GitVcs.getInstance(myProject);
   if (vcs == null) {
     return;
   }
   final VirtualFile[] roots = myVcsManager.getRootsUnderVcs(vcs);
   final Collection<VirtualFile> rootsToCheck =
       ContainerUtil.filter(
           roots,
           new Condition<VirtualFile>() {
             @Override
             public boolean value(VirtualFile root) {
               return getUser(root) == null;
             }
           });
   if (!rootsToCheck.isEmpty()) {
     ApplicationManager.getApplication()
         .executeOnPooledThread(
             new Runnable() {
               public void run() {
                 for (VirtualFile root : rootsToCheck) {
                   getOrReadUser(root);
                 }
               }
             });
   }
 }
  /** call in setUp */
  public DuringChangeListManagerUpdateTestScheme(final Project project, final String tmpDirPath) {
    final MockAbstractVcs vcs = new MockAbstractVcs(project);
    myChangeProvider = new MockDelayingChangeProvider();
    vcs.setChangeProvider(myChangeProvider);

    final File mockVcsRoot = new File(tmpDirPath, "mock");
    mockVcsRoot.mkdir();
    final VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mockVcsRoot);

    final ProjectLevelVcsManagerImpl projectLevelVcsManager =
        (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project);
    projectLevelVcsManager.registerVcs(vcs);
    // projectLevelVcsManager.setDirectoryMapping(mockVcsRoot.getAbsolutePath(), vcs.getName());
    final ArrayList<VcsDirectoryMapping> list =
        new ArrayList<VcsDirectoryMapping>(projectLevelVcsManager.getDirectoryMappings());
    list.add(new VcsDirectoryMapping(vRoot.getPath(), vcs.getName()));
    projectLevelVcsManager.setDirectoryMappings(list);

    AbstractVcs vcsFound = projectLevelVcsManager.findVcsByName(vcs.getName());
    final VirtualFile[] roots = projectLevelVcsManager.getRootsUnderVcs(vcsFound);
    assert roots.length == 1
        : Arrays.asList(roots)
            + "; "
            + vcs.getName()
            + "; "
            + Arrays.toString(AllVcses.getInstance(project).getAll());

    myDirtyScopeManager = VcsDirtyScopeManager.getInstance(project);
    myClManager = ChangeListManager.getInstance(project);
  }
  public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    final DataContext dataContext = e.getDataContext();

    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if ((project == null)
        || (ProjectLevelVcsManager.getInstance(project).isBackgroundVcsOperationRunning())) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    if (files == null || files.length == 0) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }
    boolean enabled = false;
    boolean visible = false;
    if (files.length == 1 && files[0].isDirectory()) {
      visible = true;
      if (!SvnStatusUtil.isUnderControl(project, files[0])) {
        enabled = true;
      }
    }
    presentation.setEnabled(enabled);
    presentation.setVisible(visible);
  }
 public RootsCalculator(
     final Project project, final AbstractVcs vcs, final RepositoryLocationCache locationCache) {
   myProject = project;
   myLocationCache = locationCache;
   myPlManager = ProjectLevelVcsManager.getInstance(myProject);
   myVcs = vcs;
 }
Example #19
0
 @Nullable
 public static GitVcs getInstance(Project project) {
   if (project == null || project.isDisposed()) {
     return null;
   }
   return (GitVcs) ProjectLevelVcsManager.getInstance(project).findVcsByName(NAME);
 }
  @NotNull
  public Change[] getSelectedChanges() {
    Set<Change> changes = new LinkedHashSet<Change>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) {
      return new Change[0];
    }

    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
      changes.addAll(node.getAllChangesUnder());
    }

    if (changes.isEmpty()) {
      final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing();
      if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) {
        for (VirtualFile file : selectedModifiedWithoutEditing) {
          AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
          if (vcs == null) continue;
          final VcsCurrentRevisionProxy before =
              VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod());
          if (before != null) {
            ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file));
            changes.add(new Change(before, afterRevision, FileStatus.HIJACKED));
          }
        }
      }
    }

    return changes.toArray(new Change[changes.size()]);
  }
 @NotNull
 private Map<VirtualFile, GitUpdater> tryFastForwardMergeForRebaseUpdaters(
     @NotNull Map<VirtualFile, GitUpdater> updaters) {
   Map<VirtualFile, GitUpdater> modifiedUpdaters = new HashMap<VirtualFile, GitUpdater>();
   Map<VirtualFile, Collection<Change>> changesUnderRoots =
       new LocalChangesUnderRoots(
               ChangeListManager.getInstance(myProject),
               ProjectLevelVcsManager.getInstance(myProject))
           .getChangesUnderRoots(updaters.keySet());
   for (Map.Entry<VirtualFile, GitUpdater> updaterEntry : updaters.entrySet()) {
     VirtualFile root = updaterEntry.getKey();
     GitUpdater updater = updaterEntry.getValue();
     Collection<Change> changes = changesUnderRoots.get(root);
     if (updater instanceof GitRebaseUpdater && changes != null && !changes.isEmpty()) {
       // check only if there are local changes, otherwise stash won't happen anyway and there
       // would be no optimization
       GitRebaseUpdater rebaseUpdater = (GitRebaseUpdater) updater;
       if (rebaseUpdater.fastForwardMerge()) {
         continue;
       }
     }
     modifiedUpdaters.put(root, updater);
   }
   return modifiedUpdaters;
 }
Example #22
0
  public void perform(
      @NotNull Project project,
      com.assembla.git.GitVcs mksVcs,
      @NotNull List<VcsException> exceptions,
      @NotNull VirtualFile[] affectedFiles)
      throws VcsException {
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                FileDocumentManager.getInstance().saveAllDocuments();
              }
            });

    if (!ProjectLevelVcsManager.getInstance(project)
        .checkAllFilesAreUnder(com.assembla.git.GitVcs.getInstance(project), affectedFiles)) return;

    final Map<VirtualFile, List<VirtualFile>> roots =
        com.assembla.git.GitUtil.sortFilesByVcsRoot(project, affectedFiles);

    for (VirtualFile root : roots.keySet()) {
      com.assembla.git.commands.GitCommand command =
          new com.assembla.git.commands.GitCommand(
              project, com.assembla.git.GitVcsSettings.getInstance(project), root);
      command.delete(roots.get(root));
    }

    VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project);
    for (VirtualFile file : affectedFiles) {
      mgr.fileDirty(file);
      file.refresh(true, true);
    }
  }
 @NotNull
 public Map<VirtualFile, VcsLogProvider> findLogProviders() {
   Map<VirtualFile, VcsLogProvider> logProviders = ContainerUtil.newHashMap();
   VcsLogProvider[] allLogProviders = Extensions.getExtensions(LOG_PROVIDER_EP, myProject);
   for (AbstractVcs vcs : myVcsManager.getAllActiveVcss()) {
     for (VcsLogProvider provider : allLogProviders) {
       if (provider.getSupportedVcs().equals(vcs.getKeyInstanceMethod())) {
         for (VirtualFile root : myVcsManager.getRootsUnderVcs(vcs)) {
           logProviders.put(root, provider);
         }
         break;
       }
     }
   }
   return logProviders;
 }
  @Override
  protected void update(@NotNull VcsContext context, @NotNull Presentation presentation) {
    Project project = context.getProject();

    presentation.setEnabled(isEnabled(context));
    presentation.setVisible(
        project != null && ProjectLevelVcsManager.getInstance(project).hasActiveVcss());
  }
 private VcsRootProblemNotifier(@NotNull Project project) {
   myProject = project;
   mySettings = VcsConfiguration.getInstance(myProject);
   myChangeListManager = ChangeListManager.getInstance(project);
   myProjectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
   myVcsManager = ProjectLevelVcsManager.getInstance(project);
   myReportedUnregisteredRoots = new HashSet<>(mySettings.IGNORED_UNREGISTERED_ROOTS);
 }
 RemoteRevisionsStateCache(final Project project) {
   myVcsManager = ProjectLevelVcsManager.getInstance(project);
   myChanged = new HashMap<String, Pair<Boolean, VcsRoot>>();
   myQueries = new MultiMap<VcsRoot, String>();
   myTs = new HashMap<VcsRoot, Long>();
   myLock = new Object();
   myVcsConfiguration = VcsConfiguration.getInstance(project);
 }
 @Nullable
 public AnnotationProvider getCachingAnnotationProvider() {
   final AnnotationProvider ap = getAnnotationProvider();
   if (ourUseAnnotationCache && ap instanceof VcsCacheableAnnotationProvider) {
     return new VcsAnnotationCachedProxy(
         this, ProjectLevelVcsManager.getInstance(myProject).getVcsHistoryCache());
   }
   return ap;
 }
Example #28
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;
  }
 private void updateRoots() {
   final VcsRoot[] roots = myVcsManager.getAllVcsRoots();
   synchronized (myLock) {
     for (VcsRoot root : roots) {
       final AbstractVcs vcs = root.getVcs();
       if (!myKinds.containsKey(vcs.getName())) {
         myKinds.put(vcs.getName(), vcs.getRemoteDifferenceStrategy());
       }
     }
   }
 }
 @NotNull
 private List<AbstractVcs> getVcsListFor(@NotNull VirtualFile dir) {
   VcsRootChecker[] checkers = Extensions.getExtensions(VcsRootChecker.EXTENSION_POINT_NAME);
   List<AbstractVcs> vcsList = new ArrayList<AbstractVcs>();
   for (VcsRootChecker checker : checkers) {
     if (checker.isRoot(dir.getPath())) {
       vcsList.add(myVcsManager.findVcsByName(checker.getSupportedVcs().getName()));
     }
   }
   return vcsList;
 }