From 23fcadafc110b86cedeca895c077d99e680c866b Mon Sep 17 00:00:00 2001 From: Mikhail Mazurkevich Date: Fri, 9 Apr 2021 17:00:15 +0300 Subject: [PATCH] [workspace model] Fix deadlock for the `ExternalStorageConfigurationManagerImpl` component initialization from the AWT and background thread GitOrigin-RevId: 3f919a1c185aedb070642fe6a53caa7fb12375a5 --- ...ExternalStorageConfigurationManagerImpl.kt | 30 ++++++++----------- .../ExternalSystemStorageTest.kt | 6 ++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt b/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt index ccc9db893de9..cfc820020575 100644 --- a/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt +++ b/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt @@ -28,34 +28,28 @@ internal class ExternalStorageConfigurationManagerImpl(private val project: Proj */ override fun setEnabled(value: Boolean) { state.enabled = value - updateEntitySource() + if (project.isDefault || !WorkspaceModel.isEnabled) return + val app = ApplicationManager.getApplication() + app.invokeAndWait { app.runWriteAction(::updateEntitySource) } } override fun loadState(state: ExternalStorageConfiguration) { super.loadState(state) - updateEntitySource() + if (project.isDefault || !WorkspaceModel.isEnabled) return + val app = ApplicationManager.getApplication() + app.invokeLater { app.runWriteAction(::updateEntitySource) } } private fun updateEntitySource() { val value = state.enabled - if (project.isDefault || !WorkspaceModel.isEnabled) return - val runnable = Runnable { - WorkspaceModel.getInstance(project).updateProjectModel { updater -> - val entitiesMap = updater.entitiesBySource { it is JpsImportedEntitySource && it.storedExternally != value } - entitiesMap.values.asSequence().flatMap { it.values.asSequence().flatMap { entities -> entities.asSequence() } }.forEach { entity -> - val source = entity.entitySource - if (source is JpsImportedEntitySource) { - updater.changeSource(entity, JpsImportedEntitySource(source.internalFile, source.externalSystemId, value)) - } + WorkspaceModel.getInstance(project).updateProjectModel { updater -> + val entitiesMap = updater.entitiesBySource { it is JpsImportedEntitySource && it.storedExternally != value } + entitiesMap.values.asSequence().flatMap { it.values.asSequence().flatMap { entities -> entities.asSequence() } }.forEach { entity -> + val source = entity.entitySource + if (source is JpsImportedEntitySource) { + updater.changeSource(entity, JpsImportedEntitySource(source.internalFile, source.externalSystemId, value)) } } } - val app = ApplicationManager.getApplication() - if (!app.isDispatchThread && app.isReadAccessAllowed) { - app.invokeLater { app.runWriteAction(runnable) } - } - else { - WriteAction.runAndWait { runnable.run() } - } } } \ No newline at end of file diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorageTest.kt b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorageTest.kt index dbc91658e9c1..0876f3ed31e1 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorageTest.kt +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorageTest.kt @@ -531,6 +531,9 @@ class ExternalSystemStorageTest { VfsUtil.markDirtyAndRefresh(false, false, false, miscFile) StoreReloadManager.getInstance().flushChangedProjectFileAlarm() } + ApplicationManager.getApplication().invokeAndWait{ + PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() + } } } @@ -550,6 +553,9 @@ class ExternalSystemStorageTest { VfsUtil.markDirtyAndRefresh(false, false, false, miscFile) StoreReloadManager.getInstance().flushChangedProjectFileAlarm() } + ApplicationManager.getApplication().invokeAndWait{ + PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() + } } }