From 4d22f5e7fbe7ffb19a1e1d27c8010d1491cfb4a6 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 8 Nov 2013 15:51:02 +0400 Subject: [PATCH] DirectoryIndex: don't include roots from content to projectExcludeRoots set, update projectExcludeRoots on VFS change --- .../roots/impl/DirectoryIndexTest.java | 20 +++++++++++++++---- .../roots/impl/DirectoryIndexImpl.java | 17 ++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java index d86fd6b2f32a..dbdbb5aff9b9 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java @@ -412,7 +412,7 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfoNull(module2Output); checkInfoNull(module2TestOutput); - assertTrue(myIndex.isProjectExcludeRoot(excluded)); + assertFalse(myIndex.isProjectExcludeRoot(excluded)); excluded.delete(this); projectOutput.delete(this); @@ -430,7 +430,7 @@ public class DirectoryIndexTest extends IdeaTestCase { }; VirtualFileManager.getInstance().addVirtualFileListener(l, getTestRootDisposable()); excluded = myModule1Dir.createChildDirectory(this, excluded.getName()); - //todo assertTrue(myIndex.isProjectExcludeRoot(excluded)); + assertFalse(myIndex.isProjectExcludeRoot(excluded)); projectOutput = myModule1Dir.createChildDirectory(this, projectOutput.getName()); module2Output = myModule1Dir.createChildDirectory(this, module2Output.getName()); module2TestOutput = myModule2Dir.createChildDirectory(this, module2TestOutput.getName()); @@ -442,7 +442,7 @@ public class DirectoryIndexTest extends IdeaTestCase { assertEquals(created.toString(), 4, created.size()); - assertTrue(myIndex.isProjectExcludeRoot(excluded)); + assertFalse(myIndex.isProjectExcludeRoot(excluded)); } public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception { @@ -521,12 +521,24 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfo(myExcludedLibClsDir, null, true, false, "lib.cls.exc", null, myModule3); } - public void testExcludeCompilerOutputOutsideOfContentRoot() throws Exception { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); assertTrue(fileIndex.isIgnored(myOutputDir)); assertTrue(fileIndex.isIgnored(myModule1OutputDir)); assertFalse(fileIndex.isIgnored(myOutputDir.getParent())); + assertTrue(myIndex.isProjectExcludeRoot(myOutputDir)); + assertFalse(myIndex.isProjectExcludeRoot(myModule1OutputDir)); + String moduleOutputUrl = myModule1OutputDir.getUrl(); + + myOutputDir.delete(this); + + PsiTestUtil.setCompilerOutputPath(myModule, moduleOutputUrl, false); + myOutputDir = myRootVFile.createChildDirectory(this, "out"); + myModule1OutputDir = myOutputDir.createChildDirectory(this, "module1"); + + assertTrue(myIndex.isProjectExcludeRoot(myOutputDir)); + assertTrue(myIndex.isProjectExcludeRoot(myModule1OutputDir)); + assertTrue(fileIndex.isIgnored(myModule1OutputDir)); } private void checkInfo(VirtualFile dir, diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java index 05e47671122b..b01b058c2ac5 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/DirectoryIndexImpl.java @@ -226,14 +226,19 @@ public class DirectoryIndexImpl extends DirectoryIndex { } } - if (parentInfo == null) return state; - - Module module = parentInfo.getModule(); - for (DirectoryIndexExcludePolicy policy : myExcludePolicies) { - if (policy.isExcludeRoot(file)) return state; + if (policy.isExcludeRoot(file)) { + if (parentInfo == null || parentInfo.getContentRoot() == null) { + if (state == originalState) state = state.copy(null); + state.myProjectExcludeRoots.add(file.getId()); + } + return state; + } } + if (parentInfo == null) return state; + Module module = parentInfo.getModule(); + if (state == originalState) state = state.copy(null); VirtualFile parentContentRoot = parentInfo.getContentRoot(); state.fillMapWithModuleContent(file, module, (NewVirtualFile)parentContentRoot, null); @@ -1471,7 +1476,7 @@ public class DirectoryIndexImpl extends DirectoryIndex { for (VirtualFile excludeRoot : contentEntry.getExcludeFolderFiles()) { // Output paths should be excluded (if marked as such) regardless if they're under corresponding module's content root if (excludeRoot instanceof NewVirtualFile) { - if (!FileUtil.startsWith(contentRoot.getUrl(), excludeRoot.getUrl())) { + if (!FileUtil.startsWith(excludeRoot.getUrl(), contentRoot.getUrl())) { if (isExcludeRootForModule(module, excludeRoot)) { putForFileAndAllAncestors((NewVirtualFile)excludeRoot, excludeRoot.getUrl()); }