Refresh plugins on startup to avoid plugin reloads when jar file isn't actually changed (IDEA-242175)

GitOrigin-RevId: ec91b55c17f71a59aaa5024abc4dc1398f4f6608
This commit is contained in:
Dmitry Jemerov
2020-06-02 21:35:35 +03:00
committed by intellij-monorepo-bot
parent 65edef9816
commit d971c1aedc
@@ -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<VFileEvent>): AsyncFileListener.ChangeApplier? {
if (!SystemProperties.`is`(AUTO_RELOAD_PLUGINS_SYSTEM_PROPERTY)) return null
if (!initialRefreshDone) return null
val pluginsToReload = hashSetOf<IdeaPluginDescriptorImpl>()
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 {