Search in sources :

Example 6 with DirectoryIndex

use of com.intellij.openapi.roots.impl.DirectoryIndex in project intellij-community by JetBrains.

the class DumpDirectoryInfoAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final DirectoryIndex index = DirectoryIndex.getInstance(project);
    if (project != null) {
        final VirtualFile root = e.getData(CommonDataKeys.VIRTUAL_FILE);
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ContentIterator contentIterator = new ContentIterator() {

                @Override
                public boolean processFile(VirtualFile fileOrDir) {
                    LOG.info(fileOrDir.getPath());
                    LOG.info(index.getInfoForFile(fileOrDir).toString());
                    return true;
                }
            };
            if (root != null) {
                ProjectRootManager.getInstance(project).getFileIndex().iterateContentUnderDirectory(root, contentIterator);
            } else {
                ProjectRootManager.getInstance(project).getFileIndex().iterateContent(contentIterator);
            }
        }, "Dumping directory index", true, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ContentIterator(com.intellij.openapi.roots.ContentIterator) DirectoryIndex(com.intellij.openapi.roots.impl.DirectoryIndex)

Example 7 with DirectoryIndex

use of com.intellij.openapi.roots.impl.DirectoryIndex in project intellij-community by JetBrains.

the class MavenClasspathsAndSearchScopesTest method testDirIndexOrderEntriesStartingFromRegularModule.

public void testDirIndexOrderEntriesStartingFromRegularModule() throws IOException {
    final List<Module> modules = setupDirIndexTestModulesWithScope("compile");
    assertEquals(6, modules.size());
    final Module nonMavenM1 = createModule("nonMavenM1");
    final Module nonMavenM2 = createModule("nonMavenM2");
    new WriteCommandAction.Simple(myProject) {

        @Override
        protected void run() throws Throwable {
            ModuleRootModificationUtil.addDependency(nonMavenM1, nonMavenM2, DependencyScope.COMPILE, true);
            ModuleRootModificationUtil.addDependency(nonMavenM2, modules.get(0), DependencyScope.COMPILE, true);
            createProjectSubDirs("nonMavenM1/src/main/java", "nonMavenM1/src/test/java", "nonMavenM2/src/main/java", "nonMavenM2/src/test/java");
            VirtualFile nonMavenM1JavaDir = VfsUtil.findFileByIoFile(new File(getProjectPath(), "nonMavenM1/src/main/java"), true);
            assertNotNull(nonMavenM1JavaDir);
            PsiTestUtil.addSourceContentToRoots(nonMavenM1, nonMavenM1JavaDir);
            VirtualFile nonMavenM2JavaDir = VfsUtil.findFileByIoFile(new File(getProjectPath(), "nonMavenM2/src/main/java"), true);
            assertNotNull(nonMavenM2JavaDir);
            PsiTestUtil.addSourceContentToRoots(nonMavenM2, nonMavenM2JavaDir);
        }
    }.execute().throwException();
    assertModuleModuleDeps("nonMavenM1", "nonMavenM2");
    assertModuleModuleDeps("nonMavenM2", "m1");
    assertModuleModuleDeps("m1", "m2", "m3", "m5", "m6");
    DirectoryIndex index = DirectoryIndex.getInstance(myProject);
    VirtualFile m3JavaDir = VfsUtil.findFileByIoFile(new File(getProjectPath(), "m3/src/main/java"), true);
    assertNotNull(m3JavaDir);
    // Should be: m1 -> m3, m2 -> m3, m3 -> source, and m4 -> m3
    // It doesn't trace back to nonMavenM1 and nonMavenM2.
    List<OrderEntry> orderEntries = index.getOrderEntries(index.getInfoForFile(m3JavaDir));
    List<Module> ownerModules = orderEntriesToOwnerModules(orderEntries);
    List<Module> depModules = orderEntriesToDepModules(orderEntries);
    assertOrderedElementsAreEqual(ownerModules, Arrays.asList(modules.get(0), modules.get(1), modules.get(2), modules.get(3)));
    assertOrderedElementsAreEqual(depModules, Arrays.asList(modules.get(2), modules.get(2), null, modules.get(2)));
    VirtualFile m6javaDir = VfsUtil.findFileByIoFile(new File(getProjectPath(), "m6/src/main/java"), true);
    assertNotNull(m6javaDir);
    // Should be m1 -> m6, m2 -> m6, m5 -> m6, m6 -> source
    List<OrderEntry> m6OrderEntries = index.getOrderEntries(index.getInfoForFile(m6javaDir));
    List<Module> m6OwnerModules = orderEntriesToOwnerModules(m6OrderEntries);
    List<Module> m6DepModules = orderEntriesToDepModules(m6OrderEntries);
    assertOrderedElementsAreEqual(m6OwnerModules, Arrays.asList(modules.get(0), modules.get(1), modules.get(4), modules.get(5)));
    assertOrderedElementsAreEqual(m6DepModules, Arrays.asList(modules.get(5), modules.get(5), modules.get(5), null));
    VirtualFile nonMavenM2JavaDir = VfsUtil.findFileByIoFile(new File(getProjectPath(), "nonMavenM2/src/main/java"), true);
    assertNotNull(nonMavenM2JavaDir);
    // Should be nonMavenM1 -> nonMavenM2, nonMavenM2 -> source
    List<OrderEntry> nonMavenM2JavaOrderEntries = index.getOrderEntries(index.getInfoForFile(nonMavenM2JavaDir));
    List<Module> nonMavenM2OwnerModules = orderEntriesToOwnerModules(nonMavenM2JavaOrderEntries);
    List<Module> nonMavenM2DepModules = orderEntriesToDepModules(nonMavenM2JavaOrderEntries);
    assertOrderedElementsAreEqual(nonMavenM2OwnerModules, Arrays.asList(nonMavenM1, nonMavenM2));
    assertOrderedElementsAreEqual(nonMavenM2DepModules, Arrays.asList(nonMavenM2, null));
}
Also used : DirectoryIndex(com.intellij.openapi.roots.impl.DirectoryIndex) Module(com.intellij.openapi.module.Module) File(java.io.File)

Aggregations

DirectoryIndex (com.intellij.openapi.roots.impl.DirectoryIndex)7 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)3 Project (com.intellij.openapi.project.Project)2 Nullable (org.jetbrains.annotations.Nullable)2 ContentIterator (com.intellij.openapi.roots.ContentIterator)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiManager (com.intellij.psi.PsiManager)1