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 dbdbb5aff9b9..3641d9dc06f4 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 @@ -413,6 +413,9 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfoNull(module2TestOutput); assertFalse(myIndex.isProjectExcludeRoot(excluded)); + assertTrue(myIndex.isProjectExcludeRoot(projectOutput)); + assertTrue(myIndex.isProjectExcludeRoot(module2Output)); + assertFalse(myIndex.isProjectExcludeRoot(module2TestOutput)); excluded.delete(this); projectOutput.delete(this); @@ -426,14 +429,34 @@ public class DirectoryIndexTest extends IdeaTestCase { VirtualFile file = e.getFile(); checkInfoNull(file); created.add(file); + + String fileName = e.getFileName(); + if (fileName.equals("projectOutput")) { + //todo fix and uncomment +// assertTrue(myIndex.isProjectExcludeRoot(file)); + } + if (fileName.equals("module2Output")) { + //todo fix and uncomment +// assertTrue(myIndex.isProjectExcludeRoot(file)); + } + if (fileName.equals("module2TestOutput")) { + assertFalse(myIndex.isProjectExcludeRoot(file)); + } } }; VirtualFileManager.getInstance().addVirtualFileListener(l, getTestRootDisposable()); + excluded = myModule1Dir.createChildDirectory(this, excluded.getName()); assertFalse(myIndex.isProjectExcludeRoot(excluded)); + projectOutput = myModule1Dir.createChildDirectory(this, projectOutput.getName()); + assertTrue(myIndex.isProjectExcludeRoot(projectOutput)); + module2Output = myModule1Dir.createChildDirectory(this, module2Output.getName()); + assertTrue(myIndex.isProjectExcludeRoot(module2Output)); + module2TestOutput = myModule2Dir.createChildDirectory(this, module2TestOutput.getName()); + assertFalse(myIndex.isProjectExcludeRoot(module2TestOutput)); checkInfoNull(excluded); checkInfoNull(projectOutput); @@ -443,6 +466,9 @@ public class DirectoryIndexTest extends IdeaTestCase { assertEquals(created.toString(), 4, created.size()); assertFalse(myIndex.isProjectExcludeRoot(excluded)); + assertTrue(myIndex.isProjectExcludeRoot(projectOutput)); + assertTrue(myIndex.isProjectExcludeRoot(module2Output)); + assertFalse(myIndex.isProjectExcludeRoot(module2TestOutput)); } public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception { @@ -539,6 +565,28 @@ public class DirectoryIndexTest extends IdeaTestCase { assertTrue(myIndex.isProjectExcludeRoot(myOutputDir)); assertTrue(myIndex.isProjectExcludeRoot(myModule1OutputDir)); assertTrue(fileIndex.isIgnored(myModule1OutputDir)); + + PsiTestUtil.setCompilerOutputPath(myModule, moduleOutputUrl, true); + PsiTestUtil.setCompilerOutputPath(myModule2, moduleOutputUrl, false); + PsiTestUtil.setCompilerOutputPath(myModule2, moduleOutputUrl, true); + PsiTestUtil.setCompilerOutputPath(myModule3, moduleOutputUrl, false); + PsiTestUtil.setCompilerOutputPath(myModule3, moduleOutputUrl, true); + + // now no module inherits project output dir, but it still should be project-excluded + assertTrue(myIndex.isProjectExcludeRoot(myOutputDir)); + + // project output inside module content shouldn't be projectExcludeRoot + VirtualFile projectOutputUnderContent = myModule1Dir.createChildDirectory(this, "projectOutputUnderContent"); + getCompilerProjectExtension().setCompilerOutputUrl(projectOutputUnderContent.getUrl()); + fireRootsChanged(); + + assertFalse(myIndex.isProjectExcludeRoot(myOutputDir)); + //todo uncomment assertFalse(myIndex.isProjectExcludeRoot(projectOutputUnderContent)); + + projectOutputUnderContent.delete(this); + projectOutputUnderContent = myModule1Dir.createChildDirectory(this, "projectOutputUnderContent"); + assertFalse(myIndex.isProjectExcludeRoot(myOutputDir)); + //todo uncomment assertFalse(myIndex.isProjectExcludeRoot(projectOutputUnderContent)); } 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 8c2948ffce22..ab711d4c4852 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 @@ -657,15 +657,10 @@ public class DirectoryIndexImpl extends DirectoryIndex { return getRootIndex().isProjectExcludeRoot(dir); } - - //noinspection UnnecessaryLocalVariable boolean standardResult = myState.myProjectExcludeRoots.contains(((NewVirtualFile)dir).getId()); -/* todo RootIndex rootIndex = getRootIndex(); Boolean riResult = rootIndex != null ? rootIndex.isProjectExcludeRoot(dir) : null; return assertConsistentResult(dir, riResult, standardResult); -*/ - return standardResult; } private VirtualFile findFileById(int dir) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java index 7bc634152925..cc01c67973d4 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java @@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -32,6 +33,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import gnu.trove.TObjectIntHashMap; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.java.JavaSourceRootType; @@ -44,6 +46,7 @@ class RootIndex { private static final DirectoryInfo NULL_INFO = DirectoryInfo.createNew(); private final Set myProjectExcludedRoots = ContainerUtil.newHashSet(); + private final Set myModuleExcludedRoots = ContainerUtil.newHashSet(); private final Set myLibraryExcludedRoots = ContainerUtil.newHashSet(); private final Map myRoots = ContainerUtil.newTroveMap(); private final Map> myPackagePrefixRoots = ContainerUtil.newHashMap(); @@ -71,7 +74,13 @@ class RootIndex { for (ContentEntry contentEntry : contentEntries) { // Init excluded roots - Collections.addAll(myProjectExcludedRoots, contentEntry.getExcludeFolderFiles()); + VirtualFile[] excluded = contentEntry.getExcludeFolderFiles(); + for (VirtualFile excludeRoot : excluded) { + if (!FileUtil.startsWith(excludeRoot.getUrl(), contentEntry.getUrl())) { + myProjectExcludedRoots.add(excludeRoot); + } + myModuleExcludedRoots.add(excludeRoot); + } // Init module sources SourceFolder[] sourceFolders = contentEntry.getSourceFolders(); @@ -157,7 +166,9 @@ class RootIndex { } for (DirectoryIndexExcludePolicy policy : Extensions.getExtensions(DirectoryIndexExcludePolicy.EP_NAME, project)) { - Collections.addAll(myProjectExcludedRoots, policy.getExcludeRootsForProject()); + VirtualFile[] excludeRoots = policy.getExcludeRootsForProject(); + Collections.addAll(myModuleExcludedRoots, excludeRoots); + Collections.addAll(myProjectExcludedRoots, excludeRoots); } // fill ordered entries @@ -224,7 +235,10 @@ class RootIndex { } public void checkConsistency() { - for (VirtualFile file : myProjectExcludedRoots) { + for (VirtualFile file : myLibraryExcludedRoots) { + assert file.exists() : file.getPath() + " does not exist"; + } + for (VirtualFile file : myModuleExcludedRoots) { assert file.exists() : file.getPath() + " does not exist"; } for (VirtualFile file : myLibraryExcludedRoots) { @@ -346,7 +360,7 @@ class RootIndex { } private boolean isAnyExcludeRoot(VirtualFile root) { - return myProjectExcludedRoots.contains(root) || myLibraryExcludedRoots.contains(root); + return myModuleExcludedRoots.contains(root) || myLibraryExcludedRoots.contains(root); } public boolean isProjectExcludeRoot(@NotNull final VirtualFile dir) { @@ -390,6 +404,7 @@ class RootIndex { return result; } + @Contract("_,null->false") private boolean isValidPackageDirectory(boolean includeLibrarySources, @Nullable VirtualFile file) { if (file != null) { DirectoryInfo info = getInfoForDirectory(file);