mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
migrate DirectoryIndexExcludePolicy.getExcludeRootsForProject() to getExcludeUrlsForProject() to be able to monitor creation/deletion of excluded directories (provided by extension point) and fire corresponding rootsChanged
This commit is contained in:
+5
-5
@@ -19,8 +19,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -38,13 +38,13 @@ public class ExcludeCompilerOutputPolicy implements DirectoryIndexExcludePolicy
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getExcludeRootsForProject() {
|
||||
public String[] getExcludeUrlsForProject() {
|
||||
CompilerProjectExtension projectExtension = CompilerProjectExtension.getInstance(myProject);
|
||||
VirtualFile outputPath = projectExtension == null ? null : projectExtension.getCompilerOutput();
|
||||
String outputPath = projectExtension == null ? null : projectExtension.getCompilerOutputUrl();
|
||||
if (outputPath != null) {
|
||||
return new VirtualFile[] { outputPath };
|
||||
return new String[] { outputPath };
|
||||
}
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@@ -49,9 +50,7 @@ public class DumpVfsInfoForExcludedFilesAction extends DumbAwareAction {
|
||||
Collections.addAll(excludeRoots, ModuleRootManager.getInstance(module).getExcludeRootUrls());
|
||||
}
|
||||
for (DirectoryIndexExcludePolicy policy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(project)) {
|
||||
for (VirtualFile file : policy.getExcludeRootsForProject()) {
|
||||
excludeRoots.add(file.getUrl());
|
||||
}
|
||||
ContainerUtil.addAll(excludeRoots, policy.getExcludeUrlsForProject());
|
||||
}
|
||||
|
||||
if (excludeRoots.isEmpty()) {
|
||||
|
||||
+7
@@ -218,6 +218,13 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen
|
||||
((VirtualFilePointerContainerImpl)container).addAllJarDirectories(recursiveDirUrls, true);
|
||||
files.forEach(path -> container.add(VfsUtilCore.pathToUrl(path)));
|
||||
|
||||
// changes in files provided by this method should be watched manually because no-one's bothered to setup correct pointers for them
|
||||
for (DirectoryIndexExcludePolicy excludePolicy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(getProject())) {
|
||||
for (String url : excludePolicy.getExcludeUrlsForProject()) {
|
||||
container.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
Disposer.dispose(oldDisposable); // dispose after the re-creating container to keep virtual file pointers from disposing and re-creating back
|
||||
|
||||
// module roots already fire validity change events, see usages of ProjectRootManagerComponent.getRootsValidityChangedListener
|
||||
|
||||
+3
-3
@@ -303,16 +303,16 @@ public abstract class ContentEntryEditor implements ContentRootPanel.ActionCallb
|
||||
public static boolean isExcludedOrUnderExcludedDirectory(@Nullable Project project,
|
||||
@NotNull ContentEntry entry,
|
||||
@NotNull VirtualFile file) {
|
||||
Set<VirtualFile> excludedFiles = ContainerUtil.newHashSet(entry.getExcludeFolderFiles());
|
||||
Set<String> excludedUrls = ContainerUtil.newHashSet(entry.getExcludeFolderUrls());
|
||||
if (project != null) {
|
||||
for (DirectoryIndexExcludePolicy policy : DirectoryIndexExcludePolicy.getExtensions(project)) {
|
||||
ContainerUtil.addAllNotNull(excludedFiles, policy.getExcludeRootsForProject());
|
||||
ContainerUtil.addAll(excludedUrls, policy.getExcludeUrlsForProject());
|
||||
}
|
||||
}
|
||||
Set<VirtualFile> sourceRoots = ContainerUtil.set(entry.getSourceFolderFiles());
|
||||
VirtualFile parent = file;
|
||||
while (parent != null) {
|
||||
if (excludedFiles.contains(parent)) return true;
|
||||
if (excludedUrls.contains(parent.getUrl())) return true;
|
||||
if (sourceRoots.contains(parent)) return false;
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
+17
-1
@@ -9,6 +9,7 @@ import com.intellij.openapi.roots.ModuleRootModel;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -20,8 +21,23 @@ import java.util.List;
|
||||
public interface DirectoryIndexExcludePolicy {
|
||||
ExtensionPointName<DirectoryIndexExcludePolicy> EP_NAME = ExtensionPointName.create("com.intellij.directoryIndexExcludePolicy");
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #getExcludeUrlsForProject()} instead
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
VirtualFile[] getExcludeRootsForProject();
|
||||
default VirtualFile[] getExcludeRootsForProject() {
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supply all file urls (existing as well as not yet created) that should be treated as 'excluded'
|
||||
*/
|
||||
@NotNull
|
||||
default String[] getExcludeUrlsForProject() {
|
||||
return ContainerUtil.map2Array(getExcludeRootsForProject(), String.class, VirtualFile::getUrl);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
default Function<Sdk, List<VirtualFile>> getExcludeSdkRootsStrategy() {
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.VirtualFileWithId;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.util.CollectionQuery;
|
||||
@@ -202,7 +203,8 @@ public class RootIndex {
|
||||
}
|
||||
}
|
||||
for (DirectoryIndexExcludePolicy policy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(project)) {
|
||||
info.excludedFromProject.addAll(ContainerUtil.filter(policy.getExcludeRootsForProject(), file -> ensureValid(file, policy)));
|
||||
List<VirtualFile> files = ContainerUtil.mapNotNull(policy.getExcludeUrlsForProject(), url -> VirtualFileManager.getInstance().findFileByUrl(url));
|
||||
info.excludedFromProject.addAll(ContainerUtil.filter(files, file -> ensureValid(file, policy)));
|
||||
|
||||
Function<Sdk, List<VirtualFile>> fun = policy.getExcludeSdkRootsStrategy();
|
||||
|
||||
|
||||
@@ -348,8 +348,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
|
||||
|
||||
void convertExcludedToIgnored() {
|
||||
for (DirectoryIndexExcludePolicy policy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(myProject)) {
|
||||
for (VirtualFile file : policy.getExcludeRootsForProject()) {
|
||||
addDirectoryToIgnoreImplicitly(file.getPath());
|
||||
for (String url : policy.getExcludeUrlsForProject()) {
|
||||
addDirectoryToIgnoreImplicitly(VfsUtilCore.urlToPath(url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -8,6 +8,7 @@ import com.intellij.openapi.roots.ProjectFileIndex
|
||||
import com.intellij.openapi.roots.impl.DirectoryIndexExcludePolicy
|
||||
import com.intellij.openapi.vcs.FilePath
|
||||
import com.intellij.openapi.vcs.changes.ui.ChangesComparator
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
|
||||
class ProjectExcludesIgnoredFileProvider : IgnoredFileProvider {
|
||||
|
||||
@@ -24,8 +25,11 @@ class ProjectExcludesIgnoredFileProvider : IgnoredFileProvider {
|
||||
val fileIndex = ProjectFileIndex.SERVICE.getInstance(project)
|
||||
|
||||
for (policy in DirectoryIndexExcludePolicy.EP_NAME.getExtensions(project)) {
|
||||
for (file in policy.excludeRootsForProject) {
|
||||
excludes.add(file)
|
||||
for (url in policy.excludeUrlsForProject) {
|
||||
val file = VirtualFileManager.getInstance().findFileByUrl(url)
|
||||
if (file != null) {
|
||||
excludes.add(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,12 @@ import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.roots.impl.DirectoryIndexExcludePolicy;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
@@ -47,16 +45,16 @@ public class PyDirectoryIndexExcludePolicy implements DirectoryIndexExcludePolic
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getExcludeRootsForProject() {
|
||||
List<VirtualFile> result = Lists.newArrayList();
|
||||
public String[] getExcludeUrlsForProject() {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (VirtualFile root : ProjectRootManager.getInstance(myProject).getContentRoots()) {
|
||||
VirtualFile file = root.findChild(".tox");
|
||||
if (file != null) {
|
||||
result.add(file);
|
||||
result.add(file.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(VirtualFile.EMPTY_ARRAY);
|
||||
return ArrayUtil.toStringArray(result);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user