Пример #1
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 Map<VirtualFile, RepositoryLocation> getRoots() {
    myContentRoots = myPlManager.getRootsUnderVcs(myVcs);

    List<VirtualFile> roots = new ArrayList<>();
    final List<VcsDirectoryMapping> mappings = myPlManager.getDirectoryMappings(myVcs);
    for (VcsDirectoryMapping mapping : mappings) {
      if (mapping.isDefaultMapping()) {
        if (myVcs.equals(myPlManager.getVcsFor(myProject.getBaseDir()))) {
          roots.add(myProject.getBaseDir());
        }
      } else {
        VirtualFile newFile = LocalFileSystem.getInstance().findFileByPath(mapping.getDirectory());
        if (newFile == null) {
          newFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(mapping.getDirectory());
        }
        if (newFile != null) {
          roots.add(newFile);
        } else {
          LOG.info("Can not file virtual file for root: " + mapping.getDirectory());
        }
      }
    }
    ContainerUtil.addAll(roots, myContentRoots);
    final Map<VirtualFile, RepositoryLocation> result = new HashMap<>();
    for (Iterator<VirtualFile> iterator = roots.iterator(); iterator.hasNext(); ) {
      final VirtualFile vf = iterator.next();
      final RepositoryLocation location =
          myLocationCache.getLocation(myVcs, VcsUtil.getFilePath(vf), false);
      if (location != null) {
        result.put(vf, location);
      } else {
        iterator.remove();
      }
    }
    roots = myVcs.filterUniqueRoots(roots, IntoSelfVirtualFileConvertor.getInstance());
    result.keySet().retainAll(roots);

    logRoots(roots);
    return result;
  }
 @Override
 protected void hyperlinkActivated(
     @NotNull Notification notification, @NotNull HyperlinkEvent event) {
   if (event.getDescription().equals("configure") && !myProject.isDisposed()) {
     ShowSettingsUtil.getInstance()
         .showSettingsDialog(myProject, ActionsBundle.message("group.VcsGroup.text"));
     Collection<VcsRootError> errorsAfterPossibleFix = getInstance(myProject).scan();
     if (errorsAfterPossibleFix.isEmpty() && !notification.isExpired()) {
       notification.expire();
     }
   } else if (event.getDescription().equals("ignore")) {
     mySettings.addIgnoredUnregisteredRoots(
         ContainerUtil.map(myImportantUnregisteredRoots, PATH_FROM_ROOT_ERROR));
     notification.expire();
   } else if (event.getDescription().equals("add")) {
     List<VcsDirectoryMapping> mappings = myVcsManager.getDirectoryMappings();
     for (VcsRootError root : myImportantUnregisteredRoots) {
       mappings = VcsUtil.addMapping(mappings, root.getMapping(), root.getVcsKey().getName());
     }
     myVcsManager.setDirectoryMappings(mappings);
   }
 }