From ca342d3728f753614eab84feaee3e0fa33d047be Mon Sep 17 00:00:00 2001 From: Richard Li <742829+rli@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:38:54 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20infinite=20restart=20loop=20when=20disabl?= =?UTF-8?q?ed=20toolkit=202.x=20cannot=20be=20updated=E2=80=A6=20(#4523)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix infinite restart loop when disabled toolkit 2.x cannot be updated while installed with core 3.x --- ...-cb4ca29a-a3e2-4ea6-82fb-10bc2fcd8ac5.json | 4 ++ .../jetbrains/PluginVersionChecker.kt | 40 +++++++++++++------ 2 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 .changes/next-release/bugfix-cb4ca29a-a3e2-4ea6-82fb-10bc2fcd8ac5.json diff --git a/.changes/next-release/bugfix-cb4ca29a-a3e2-4ea6-82fb-10bc2fcd8ac5.json b/.changes/next-release/bugfix-cb4ca29a-a3e2-4ea6-82fb-10bc2fcd8ac5.json new file mode 100644 index 0000000000..9daeb2e9f7 --- /dev/null +++ b/.changes/next-release/bugfix-cb4ca29a-a3e2-4ea6-82fb-10bc2fcd8ac5.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Fix infinite restart loop on <=241 when an incompatible version of AWS Toolkit is installed alongside Amazon Q (#4519)" +} diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt index 36dd1171e8..c5704ccd6f 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/PluginVersionChecker.kt @@ -21,6 +21,7 @@ import software.aws.toolkits.core.utils.warn import software.aws.toolkits.jetbrains.AwsToolkit.TOOLKIT_PLUGIN_ID import software.aws.toolkits.jetbrains.core.plugin.PluginUpdateManager import software.aws.toolkits.resources.message +import javax.swing.SwingUtilities class PluginVersionChecker : ApplicationInitializedListener { override suspend fun execute(asyncScope: CoroutineScope) { @@ -51,19 +52,14 @@ class PluginVersionChecker : ApplicationInitializedListener { // defensively disable the old toolkit if we couldn't update it because we might deadlock during project open val toolkit = mismatch.firstOrNull { it.id == TOOLKIT_PLUGIN_ID && it.version?.startsWith("2.") == true } - val shouldDisableToolkit = (toolkit != null && updated.none { it == toolkit }) - if (shouldDisableToolkit) { - LOG.info { "Attempting to disable aws.toolkit due to known incompatibility" } - val descriptor = toolkit?.descriptor as? IdeaPluginDescriptor - - descriptor?.let { - PluginEnabler.getInstance().disable(listOf(descriptor)) - } ?: LOG.warn { "Expected toolkit descriptor to be IdeaPluginDescriptor, but was ${toolkit?.descriptor}" } - } - if (shouldDisableToolkit || updated.isNotEmpty()) { + if (shouldDisableToolkit(toolkit, updated) || updated.isNotEmpty()) { LOG.info { "Restarting due to forced update of plugins" } - ApplicationManagerEx.getApplicationEx().restart(true) + + // IDE invokeLater is not initialized yet + SwingUtilities.invokeAndWait { + ApplicationManagerEx.getApplicationEx().restart(true) + } return } @@ -82,7 +78,7 @@ class PluginVersionChecker : ApplicationInitializedListener { coreDescriptor?.let { descriptor -> PluginUpdateManager.updatePlugin(descriptor, EmptyProgressIndicator()) } } - PluginEnabler.getInstance().disable( + PluginEnabler.HEADLESS.disable( AwsToolkit.PLUGINS_INFO.values.mapNotNull { val descriptor = it.descriptor as? IdeaPluginDescriptor if (descriptor != null && descriptor != core.descriptor) { @@ -97,6 +93,26 @@ class PluginVersionChecker : ApplicationInitializedListener { } } + private fun shouldDisableToolkit(toolkit: PluginInfo?, updated: List): Boolean { + if (toolkit != null && updated.none { it == toolkit }) { + LOG.info { "Attempting to disable aws.toolkit due to known incompatibility" } + val descriptor = toolkit.descriptor as? IdeaPluginDescriptor ?: run { + LOG.warn { "Expected toolkit descriptor to be IdeaPluginDescriptor, but was ${toolkit.descriptor}" } + return false + } + + if (!descriptor.isEnabled) { + LOG.info { "Does not need to disable toolkit since it is already disabled" } + return false + } + + PluginEnabler.HEADLESS.disable(listOf(descriptor)) + return true + } + + return false + } + companion object { private val LOG = getLogger() }