示例#1
0
 @NotNull
 public static List<VcsDirectoryMapping> addMapping(
     @NotNull List<VcsDirectoryMapping> existingMappings,
     @NotNull String path,
     @NotNull String vcs) {
   List<VcsDirectoryMapping> mappings = new ArrayList<VcsDirectoryMapping>(existingMappings);
   for (Iterator<VcsDirectoryMapping> iterator = mappings.iterator(); iterator.hasNext(); ) {
     VcsDirectoryMapping mapping = iterator.next();
     if (mapping.isDefaultMapping() && StringUtil.isEmptyOrSpaces(mapping.getVcs())) {
       LOG.debug("Removing <Project> -> <None> mapping");
       iterator.remove();
     } else if (FileUtil.pathsEqual(mapping.getDirectory(), path)) {
       if (!StringUtil.isEmptyOrSpaces(mapping.getVcs())) {
         LOG.warn(
             "Substituting existing mapping ["
                 + path
                 + "] -> ["
                 + mapping.getVcs()
                 + "] with ["
                 + vcs
                 + "]");
       } else {
         LOG.debug("Removing [" + path + "] -> <None> mapping");
       }
       iterator.remove();
     }
   }
   mappings.add(new VcsDirectoryMapping(path, vcs));
   return mappings;
 }
  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;
  }
 public boolean hasExplicitMapping(final VirtualFile vFile) {
   final VcsDirectoryMapping mapping = myMappings.getMappingFor(vFile);
   return mapping != null && !mapping.isDefaultMapping();
 }