private static void excludeDirFromContent( ContentEntry content, VirtualFile root, String excludeDir) { VirtualFile excludeDirFile = root.findChild(excludeDir); if (excludeDirFile != null) { content.addExcludeFolder(excludeDirFile); } }
private static void unexcludeRootIfNeccessary( @NotNull VirtualFile root, @NotNull ModuleRootManager manager) { Set<VirtualFile> excludedRoots = new HashSet<VirtualFile>(Arrays.asList(manager.getExcludeRoots())); VirtualFile excludedRoot = root; while (excludedRoot != null && !excludedRoots.contains(excludedRoot)) { excludedRoot = excludedRoot.getParent(); } if (excludedRoot == null) { return; } Set<VirtualFile> rootsToExclude = new HashSet<VirtualFile>(); collectChildrenRecursively(excludedRoot, root, rootsToExclude); final ModifiableRootModel model = manager.getModifiableModel(); ContentEntry contentEntry = findContentEntryForRoot(model, excludedRoot); if (contentEntry != null) { ExcludeFolder excludedFolder = null; for (ExcludeFolder folder : contentEntry.getExcludeFolders()) { if (folder.getFile() == excludedRoot) { excludedFolder = folder; break; } } if (excludedFolder != null) { contentEntry.removeExcludeFolder(excludedFolder); } for (VirtualFile rootToExclude : rootsToExclude) { if (!excludedRoots.contains(rootToExclude)) { contentEntry.addExcludeFolder(rootToExclude); } } } ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { model.commit(); } }); }