From d971c1aedc5f4f105e5bde9f1a363fe26d1c8ba9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 2 Jun 2020 12:26:55 +0200 Subject: [PATCH] Refresh plugins on startup to avoid plugin reloads when jar file isn't actually changed (IDEA-242175) GitOrigin-RevId: ec91b55c17f71a59aaa5024abc4dc1398f4f6608 --- .../ide/plugins/DynamicPluginVfsListener.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/DynamicPluginVfsListener.kt b/platform/platform-impl/src/com/intellij/ide/plugins/DynamicPluginVfsListener.kt index 6d15fe402c20..51634b4b125a 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/DynamicPluginVfsListener.kt +++ b/platform/platform-impl/src/com/intellij/ide/plugins/DynamicPluginVfsListener.kt @@ -5,10 +5,12 @@ import com.intellij.ide.FrameStateListener import com.intellij.notification.NotificationType import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.PathManager +import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.AsyncFileListener import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VfsUtilCore +import com.intellij.openapi.vfs.newvfs.RefreshQueue import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent import com.intellij.openapi.vfs.newvfs.events.VFileEvent import com.intellij.util.SystemProperties @@ -19,6 +21,8 @@ import com.intellij.util.SystemProperties private const val AUTO_RELOAD_PLUGINS_SYSTEM_PROPERTY = "idea.auto.reload.plugins" class DynamicPluginVfsListener : AsyncFileListener { + private var initialRefreshDone = false + init { if (SystemProperties.`is`(AUTO_RELOAD_PLUGINS_SYSTEM_PROPERTY)) { val pluginsPath = PathManager.getPluginsPath() @@ -27,18 +31,23 @@ class DynamicPluginVfsListener : AsyncFileListener { if (pluginsRoot != null) { // ensure all plugins are in VFS VfsUtilCore.processFilesRecursively(pluginsRoot) { true } + RefreshQueue.getInstance().refresh(true, true, Runnable { initialRefreshDone = true }, pluginsRoot) } } } override fun prepareChange(events: List): AsyncFileListener.ChangeApplier? { if (!SystemProperties.`is`(AUTO_RELOAD_PLUGINS_SYSTEM_PROPERTY)) return null + if (!initialRefreshDone) return null val pluginsToReload = hashSetOf() for (event in events) { if (!event.isFromRefresh) continue if (event is VFileContentChangeEvent) { - findPluginByPath(event.path)?.let { pluginsToReload.add(it) } + findPluginByPath(event.path)?.let { + LOG.info("Detected plugin .jar file change ${event.path}, reloading plugin") + pluginsToReload.add(it) + } } } val descriptorsToReload = pluginsToReload @@ -75,6 +84,10 @@ class DynamicPluginVfsListener : AsyncFileListener { FileUtil.isAncestor(it.pluginPath.toAbsolutePath().toString(), path, false) } as IdeaPluginDescriptorImpl? } + + companion object { + val LOG = Logger.getInstance(DynamicPluginVfsListener::class.java) + } } class DynamicPluginsFrameStateListener : FrameStateListener {