platform: fix automatic unloading of newly added modules if some modules point to non-existing iml files (IDEA-208237)

UnloadedModuleDescriptionImpl.createFromPaths doesn't return entries for non-existing iml files, so we shouldn't try to unload such modules.
This commit is contained in:
nik
2019-03-04 14:16:31 +03:00
parent 58588e8002
commit ea74c86bcc
2 changed files with 20 additions and 2 deletions
@@ -88,6 +88,23 @@ class AutomaticModuleUnloaderTest : ModuleTestCase() {
doTest("b", listOf("c"), {}, "b", "c")
}
fun `test deleted iml file`() = runBlocking {
createModule("a")
createModule("b")
val deletedIml = createModule("deleted")
val moduleManager = ModuleManager.getInstance(project)
moduleManager.setUnloadedModules(listOf("a"))
createModule("c")
val moduleFiles = createNewModuleFiles(listOf("d")) {}
reloadProjectWithNewModules(moduleFiles) {
File(deletedIml.moduleFilePath).delete()
}
ModuleTestCase.assertSameElements(moduleManager.unloadedModuleDescriptions.map { it.name }, "a", "d")
}
private suspend fun doTest(initiallyUnloaded: String,
newModulesName: List<String>,
setup: (Map<String, Module>) -> Unit,
@@ -125,13 +142,14 @@ class AutomaticModuleUnloaderTest : ModuleTestCase() {
return moduleFiles
}
private suspend fun reloadProjectWithNewModules(moduleFiles: List<File>) {
private suspend fun reloadProjectWithNewModules(moduleFiles: List<File>, beforeReload: () -> Unit = {}) {
val moduleManager = ModuleManagerImpl.getInstanceImpl(myProject)
val modulePaths = LinkedHashSet<ModulePath>()
moduleManager.modules.forEach { it.stateStore.save() }
moduleManager.modules.mapTo(modulePaths) { ModulePath(it.moduleFilePath, null) }
moduleManager.unloadedModuleDescriptions.mapTo(modulePaths) { (it as UnloadedModuleDescriptionImpl).modulePath }
moduleFiles.mapTo(modulePaths) { ModulePath(FileUtil.toSystemIndependentName(it.absolutePath), null) }
beforeReload()
moduleManager.loadStateFromModulePaths(modulePaths)
}
@@ -42,7 +42,7 @@ class AutomaticModuleUnloader(private val project: Project) : PersistentStateCom
val newLoadedNames = oldLoadedWithDependencies.mapTo(LinkedHashSet()) { it.name }
val toLoad = modulesToLoad.filter { it.moduleName in newLoadedNames && it.moduleName !in oldLoaded}
val toUnload = modulesToLoad.filter { it.moduleName !in newLoadedNames }
val toUnload = modulesToLoad.filter { it.moduleName !in newLoadedNames && it.moduleName in moduleDescriptions}
loadedModulesListStorage.modules.clear()
modulesToLoad.filter { it.moduleName in newLoadedNames }.mapTo(loadedModulesListStorage.modules) { it.moduleName }
val change = UnloadedModulesListChange(toLoad, toUnload, toUnload.map { moduleDescriptions[it.moduleName]!! })