mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-05 08:06:56 +07:00
This introduces WorkspaceFileIndex, which uses information provided by WorkspaceFileIndexContributor extensions to associate files with entities from Workspace Model. The index is updated incrementally when entities from the workspace model are changed, the parts of it taken from AdditionalLibraryRootsProvider and DirectoryIndexExcludePolicy are updated non-incrementally on rootsChanged as before. Implementations of the existing ProjectFileIndex and ModuleFileIndex are changed to delegate to WorkspaceFileIndex if 'platform.projectModel.workspace.model.file.index' registry option is enabled. Some methods of ProjectFileIndex and ModuleFileIndex still use the old DirectoryIndex, also there is some code which use it directly. GitOrigin-RevId: 6acb68dd461b372a387354c5234004efca3f2931
214 lines
6.5 KiB
Kotlin
214 lines
6.5 KiB
Kotlin
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
|
package com.intellij.projectView
|
|
|
|
import com.intellij.ide.highlighter.ModuleFileType
|
|
import com.intellij.ide.impl.runUnderModalProgressIfIsEdt
|
|
import com.intellij.openapi.application.WriteAction
|
|
import com.intellij.openapi.module.Module
|
|
import com.intellij.openapi.module.ModuleManager
|
|
import com.intellij.openapi.ui.Queryable
|
|
import com.intellij.project.stateStore
|
|
import com.intellij.testFramework.PsiTestUtil
|
|
import com.intellij.util.io.directoryContent
|
|
import com.intellij.util.io.generateInVirtualTempDir
|
|
import com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexEx
|
|
|
|
// directory-based project must be used to ensure that .iws/.ipr file won't break the test (they may be created if workspace model is used)
|
|
class ModulesInProjectViewTest : BaseProjectViewTestCase() {
|
|
init {
|
|
myPrintInfo = Queryable.PrintInfo()
|
|
}
|
|
|
|
override fun setUp() {
|
|
super.setUp()
|
|
myStructure.isShowLibraryContents = false
|
|
}
|
|
|
|
fun `test unloaded modules`() {
|
|
val root = directoryContent {
|
|
dir("loaded") {
|
|
dir("unloaded-inner") {
|
|
dir("subdir") { }
|
|
file("y.txt")
|
|
}
|
|
}
|
|
dir("unloaded") {
|
|
dir("loaded-inner") {
|
|
dir("subdir") { }
|
|
file("z.txt")
|
|
}
|
|
}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("loaded"), root.findChild("loaded")!!)
|
|
PsiTestUtil.addContentRoot(createModule("unloaded-inner"), root.findFileByRelativePath("loaded/unloaded-inner")!!)
|
|
PsiTestUtil.addContentRoot(createModule("unloaded"), root.findChild("unloaded")!!)
|
|
PsiTestUtil.addContentRoot(createModule("loaded-inner"), root.findFileByRelativePath("unloaded/loaded-inner")!!)
|
|
val expected = """
|
|
Project
|
|
loaded
|
|
unloaded-inner
|
|
subdir
|
|
y.txt
|
|
unloaded
|
|
loaded-inner
|
|
subdir
|
|
z.txt
|
|
|
|
""".trimIndent()
|
|
assertStructureEqual(expected)
|
|
|
|
runUnderModalProgressIfIsEdt {
|
|
ModuleManager.getInstance(myProject).setUnloadedModules(listOf("unloaded", "unloaded-inner"))
|
|
}
|
|
if (!WorkspaceFileIndexEx.IS_ENABLED) {
|
|
//todo temporarily dispose until events are fired after unloading
|
|
assertStructureEqual("""
|
|
Project
|
|
loaded
|
|
unloaded-inner
|
|
subdir
|
|
y.txt
|
|
unloaded
|
|
loaded-inner
|
|
subdir
|
|
z.txt
|
|
""".trimIndent())
|
|
}
|
|
}
|
|
|
|
fun `test unloaded module with qualified name`() {
|
|
val root = directoryContent {
|
|
dir("unloaded") {
|
|
dir("subdir") {}
|
|
file("y.txt")
|
|
}
|
|
dir("unloaded2") {
|
|
dir("subdir") {}
|
|
}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("foo.bar.unloaded"), root.findChild("unloaded")!!)
|
|
PsiTestUtil.addContentRoot(createModule("unloaded2"), root.findChild("unloaded2")!!)
|
|
|
|
val expected = """
|
|
Project
|
|
Group: foo.bar
|
|
unloaded
|
|
subdir
|
|
y.txt
|
|
unloaded2
|
|
subdir
|
|
""".trimIndent()
|
|
assertStructureEqual(expected)
|
|
|
|
runUnderModalProgressIfIsEdt {
|
|
ModuleManager.getInstance(myProject).setUnloadedModules(listOf("unloaded"))
|
|
}
|
|
assertStructureEqual(expected)
|
|
}
|
|
|
|
fun `test do not show parent groups for single module`() {
|
|
val root = directoryContent {
|
|
dir("module") {
|
|
dir("subdir") {}
|
|
}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("foo.bar.module"), root.findChild("module")!!)
|
|
assertStructureEqual("""
|
|
|Project
|
|
| module
|
|
| subdir
|
|
|
|
|
""".trimMargin())
|
|
}
|
|
|
|
fun `test flatten modules option`() {
|
|
val root = directoryContent {
|
|
dir("module1") {}
|
|
dir("module2") {}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("foo.bar.module1"), root.findChild("module1")!!)
|
|
PsiTestUtil.addContentRoot(createModule("foo.bar.module2"), root.findChild("module2")!!)
|
|
myStructure.isFlattenModules = true
|
|
assertStructureEqual("""
|
|
|Project
|
|
| module1
|
|
| module2
|
|
|
|
|
""".trimMargin())
|
|
}
|
|
|
|
fun `test do not show groups duplicating module names`() {
|
|
val root = directoryContent {
|
|
dir("foo") {}
|
|
dir("foo.bar") {}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("xxx.foo"), root.findChild("foo")!!)
|
|
PsiTestUtil.addContentRoot(createModule("xxx.foo.bar"), root.findChild("foo.bar")!!)
|
|
assertStructureEqual("""
|
|
|Project
|
|
| Group: xxx
|
|
| foo
|
|
| foo.bar
|
|
|
|
|
""".trimMargin())
|
|
}
|
|
|
|
fun `test modules with common parent group`() {
|
|
val root = directoryContent {
|
|
dir("module1") {
|
|
dir("subdir") {}
|
|
}
|
|
dir("module2") {
|
|
dir("subdir") {}
|
|
}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("foo.bar.module1"), root.findChild("module1")!!)
|
|
PsiTestUtil.addContentRoot(createModule("foo.baz.module2"), root.findChild("module2")!!)
|
|
assertStructureEqual("""
|
|
|Project
|
|
| Group: foo
|
|
| Group: bar
|
|
| module1
|
|
| subdir
|
|
| Group: baz
|
|
| module2
|
|
| subdir
|
|
|
|
|
""".trimMargin())
|
|
}
|
|
|
|
fun `test modules in nested groups`() {
|
|
val root = directoryContent {
|
|
dir("module1") {
|
|
dir("subdir") {}
|
|
}
|
|
dir("module2") {
|
|
dir("subdir") {}
|
|
}
|
|
}.generateInVirtualTempDir()
|
|
PsiTestUtil.addContentRoot(createModule("foo.bar.module1"), root.findChild("module1")!!)
|
|
PsiTestUtil.addContentRoot(createModule("foo.module2"), root.findChild("module2")!!)
|
|
assertStructureEqual("""
|
|
|Project
|
|
| Group: foo
|
|
| Group: bar
|
|
| module1
|
|
| subdir
|
|
| module2
|
|
| subdir
|
|
|
|
|
""".trimMargin())
|
|
}
|
|
|
|
override fun doCreateRealModule(moduleName: String): Module {
|
|
return WriteAction.computeAndWait<Module, RuntimeException> {
|
|
/* iml files are created under .idea directory to ensure that they won't affect expected structure of Project View;
|
|
this is needed to ensure that tests work the same way under the old project model and under workspace model where all modules
|
|
are saved when a single module is unloaded */
|
|
val imlPath = project.stateStore.projectBasePath.resolve(".idea/$moduleName${ModuleFileType.DOT_DEFAULT_EXTENSION}")
|
|
ModuleManager.getInstance(myProject).newModule(imlPath, moduleType.id)
|
|
}
|
|
}
|
|
|
|
override fun getTestPath(): String? = null
|
|
} |