From 8a0969156f86b7d1ae09ce140794ff554109c25f Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Tue, 23 Nov 2021 11:34:17 +0100 Subject: [PATCH] Do not set "idea.plugins.compatible.build" -- fix plugin update issue In the IDEA plugin update there are a code that used system property "idea.plugins.compatible.build" to calculate the IDEA version that will be sent to plugin marketplace to download last version of the plugins. It seems like by some reason setupIdeaStandaloneExecution() was called from the IDEA thread and because of that idea version was calculated incorrectly and incorrect version of the plugins was downloaded. It is still unclear how the setupIdeaStandaloneExecution() could be called from the IDEA, so added logging for that. Relevant issue: MP-3702 Relevant code in the IDEA: - ApplicationInfoImpl.getPluginsCompatibleBuildAsNumber --- .../kotlin/cli/jvm/compiler/compat.kt | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/compat.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/compat.kt index 0fac43918da..1b8de704c72 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/compat.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/compat.kt @@ -5,13 +5,32 @@ package org.jetbrains.kotlin.cli.jvm.compiler -fun setupIdeaStandaloneExecution() { - System.getProperties().setProperty("idea.plugins.compatible.build", "201.6668.13") - System.getProperties().setProperty("project.structure.add.tools.jar.to.new.jdk", "false") - System.getProperties().setProperty("psi.track.invalidation", "true") - System.getProperties().setProperty("psi.incremental.reparse.depth.limit", "1000") - System.getProperties().setProperty("ide.hide.excluded.files", "false") - System.getProperties().setProperty("ast.loading.filter", "false") - System.getProperties().setProperty("idea.ignore.disabled.plugins", "true") - System.getProperties().setProperty("idea.home.path", System.getProperty("java.io.tmpdir")) -} \ No newline at end of file +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.diagnostic.Logger + +object IdeaStandaloneExecutionSetup { + private val LOG: Logger = Logger.getInstance(IdeaStandaloneExecutionSetup::class.java) + + fun doSetup() { + checkInHeadlessMode() + + System.getProperties().setProperty("project.structure.add.tools.jar.to.new.jdk", "false") + System.getProperties().setProperty("psi.track.invalidation", "true") + System.getProperties().setProperty("psi.incremental.reparse.depth.limit", "1000") + System.getProperties().setProperty("ide.hide.excluded.files", "false") + System.getProperties().setProperty("ast.loading.filter", "false") + System.getProperties().setProperty("idea.ignore.disabled.plugins", "true") + System.getProperties().setProperty("idea.home.path", System.getProperty("java.io.tmpdir")) + } + + private fun checkInHeadlessMode() { + // if application is null it means that we are in progress of set-up application environment i.e. we are not in the running IDEA + val application = ApplicationManager.getApplication() ?: return + if (!application.isHeadlessEnvironment) { + LOG.error(Throwable("IdeaStandaloneExecutionSetup should be called only in headless environment")) + } + } +} + +// We safe this function to minimize the patch for release branches +fun setupIdeaStandaloneExecution() = IdeaStandaloneExecutionSetup.doSetup() \ No newline at end of file