[workspace model] don't try to register module-level libraries from unloaded module (IDEA-246786, EA-236032)

GitOrigin-RevId: c31dadfb487ae8f0ac49a6c423996cac83a06e02
This commit is contained in:
Nikolay Chashnikov
2020-07-28 15:42:29 +00:00
committed by intellij-monorepo-bot
parent c853a18403
commit 341e9abb01
2 changed files with 25 additions and 14 deletions
@@ -5,5 +5,14 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="lib">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
@@ -288,25 +288,27 @@ class ModuleManagerComponentBridge(private val project: Project) : ModuleManager
}
}
is EntityChange.Added -> {
val moduleRootComponent = getModuleRootComponentByLibrary(change.entity)
val library = event.storageAfter.libraryMap.getDataByEntity(change.entity)
if (library == null && WorkspaceModelTopics.getInstance(project).modulesAreLoaded) {
moduleRootComponent.moduleLibraryTable.addLibrary(change.entity, null)
}
if (library != null) {
(library as LibraryBridgeImpl).entityStorage = entityStore
library.clearTargetBuilder()
val tableId = change.entity.tableId as LibraryTableId.ModuleLibraryTableId
val moduleEntity = entityStore.current.resolve(tableId.moduleId)
?: error("Could not find module for module library: ${change.entity.persistentId()}")
if (moduleEntity.name !in unloadedModules) {
val library = event.storageAfter.libraryMap.getDataByEntity(change.entity)
if (library == null && WorkspaceModelTopics.getInstance(project).modulesAreLoaded) {
val module = entityStore.current.moduleMap.getDataByEntity(moduleEntity)
?: error("Could not find module bridge for module entity $moduleEntity")
val moduleRootComponent = ModuleRootComponentBridge.getInstance(module)
moduleRootComponent.moduleLibraryTable.addLibrary(change.entity, null)
}
if (library != null) {
(library as LibraryBridgeImpl).entityStorage = entityStore
library.clearTargetBuilder()
}
}
}
}
}
private fun getModuleRootComponentByLibrary(entity: LibraryEntity): ModuleRootComponentBridge {
val tableId = entity.tableId as LibraryTableId.ModuleLibraryTableId
val module = findModuleByName(tableId.moduleId.name) ?: error("Could not find module for module library: ${entity.persistentId()}")
return ModuleRootComponentBridge.getInstance(module)
}
private fun addModule(moduleEntity: ModuleEntity): ModuleBridge {
val module = createModuleInstance(moduleEntity, entityStore, diff = null, isNew = false)
runWriteAction {