From 18f2b3e1d5abfb3d95fd862cb97d46366d7d0a90 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 28 Nov 2012 12:04:31 +0400 Subject: [PATCH] do not send ignored files to external build process & don't initialize VFS recursively for newly created non-project directories (IDEA-95885, IDEA-95573) --- .../impl/TranslatingCompilerFilesMonitor.java | 58 ++++++++++++++++--- .../intellij/testFramework/VfsTestUtil.java | 1 + 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index 6a24916eae1a..4d9aeb2edf7e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -1036,13 +1036,18 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { return; } + final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() { - @Override - public boolean visitFile(@NotNull VirtualFile file) { + @NotNull @Override + public Result visitFileEx(@NotNull VirtualFile file) { + if (fileTypeManager.isFileIgnored(file)) { + return SKIP_CHILDREN; + } + if (!file.isDirectory()) { processor.execute(file); } - return true; + return CONTINUE; } @Nullable @@ -1595,12 +1600,13 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { if (fromMove) { notifyFilesDeleted(pathsToMark); } - else { + else if (!isIgnoredOrUnderIgnoredDirectory(file)) { notifyFilesChanged(pathsToMark); } } private void processNewFile(final VirtualFile file, final boolean notifyServer) { + final Ref isInContent = Ref.create(false); ApplicationManager.getApplication().runReadAction(new Runnable() { // need read action to ensure that the project was not disposed during the iteration over the project list public void run() { @@ -1611,7 +1617,12 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { final int projectId = getProjectId(project); final boolean projectSuspended = isSuspended(projectId); final ProjectRootManager rootManager = ProjectRootManager.getInstance(project); - if (rootManager.getFileIndex().isInSourceContent(file)) { + ProjectFileIndex fileIndex = rootManager.getFileIndex(); + if (fileIndex.isInContent(file)) { + isInContent.set(true); + } + + if (fileIndex.isInSourceContent(file)) { final TranslatingCompiler[] translators = CompilerManager.getInstance(project).getCompilers(TranslatingCompiler.class); processRecursively(file, false, new FileProcessor() { public void execute(final VirtualFile file) { @@ -1642,9 +1653,10 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } }); - if (notifyServer) { + if (notifyServer && !isIgnoredOrUnderIgnoredDirectory(file)) { final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - processRecursively(file, false, new FileProcessor() { + boolean dbOnly = !isInContent.get(); + processRecursively(file, dbOnly, new FileProcessor() { @Override public void execute(VirtualFile file) { pathsToMark.add(new File(file.getPath())); @@ -1655,6 +1667,38 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } + private boolean isIgnoredOrUnderIgnoredDirectory(final VirtualFile file) { + FileTypeManager fileTypeManager = FileTypeManager.getInstance(); + if (fileTypeManager.isFileIgnored(file)) { + return true; + } + + //optimization: if file is in content of some project it's definitely not ignored + boolean isInContent = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public Boolean compute() { + for (Project project : myProjectManager.getOpenProjects()) { + if (project.isInitialized() && ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) { + return true; + } + } + return false; + } + }); + if (isInContent) { + return false; + } + + VirtualFile current = file.getParent(); + while (current != null) { + if (fileTypeManager.isFileIgnored(current)) { + return true; + } + current = current.getParent(); + } + return false; + } + private static void notifyFilesChanged(Collection paths) { if (!paths.isEmpty()) { BuildManager.getInstance().notifyFilesChanged(paths); diff --git a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java index e7dd782bf50e..6670a27f2fb2 100644 --- a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java @@ -68,6 +68,7 @@ public class VfsTestUtil { parent = child; } final VirtualFile file; + parent.getChildren();//need this to ensure that fileCreated event is fired if (dir) { file = parent.createChildDirectory(VfsTestUtil.class, PathUtil.getFileName(relativePath)); }