IDEA-333730 Persist compiler plugins model in data nodes

... to allow data importers to always produce the same
result, even if data nodes are retrieved from cache.

Also, variant switching in Android Studio relies on this.
It restores data nodes from the cache, to avoid invoking
full Gradle sync.

closes https://github.com/JetBrains/intellij-community/pull/2582

#KTIJ-27235 Fixed

GitOrigin-RevId: c03227a1c6cd3177ed9f7f5438075ac482743878
This commit is contained in:
Ivan Gavrilovic
2023-09-29 16:38:53 +01:00
committed by intellij-monorepo-bot
parent 963141d5a8
commit ef29e034b1
6 changed files with 13 additions and 12 deletions

View File

@@ -2,13 +2,13 @@
package org.jetbrains.kotlin.idea.compilerPlugin.allopen.gradleJava
import com.intellij.openapi.util.Key
import com.intellij.openapi.externalSystem.model.Key
import org.jetbrains.kotlin.idea.gradleTooling.model.allopen.AllOpenModel
import org.jetbrains.kotlin.idea.gradleJava.compilerPlugin.AnnotationBasedPluginProjectResolverExtension
class AllOpenProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<AllOpenModel>() {
companion object {
val KEY = Key<AllOpenModel>("AllOpenModel")
val KEY = Key.create(AllOpenModel::class.java, 1)
}
override val modelClass get() = AllOpenModel::class.java

View File

@@ -5,13 +5,13 @@
package org.jetbrains.kotlin.idea.compilerPlugin.assignment.gradleJava
import com.intellij.openapi.util.Key
import com.intellij.openapi.externalSystem.model.Key
import org.jetbrains.kotlin.idea.gradleJava.compilerPlugin.AnnotationBasedPluginProjectResolverExtension
import org.jetbrains.kotlin.idea.gradleTooling.model.assignment.AssignmentModel
class AssignmentProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<AssignmentModel>() {
companion object {
val KEY = Key<AssignmentModel>("AssignmentModel")
val KEY = Key.create(AssignmentModel::class.java, 1)
}
override val modelClass get() = AssignmentModel::class.java

View File

@@ -3,10 +3,10 @@
package org.jetbrains.kotlin.idea.gradleJava.compilerPlugin
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.Key
import com.intellij.openapi.externalSystem.model.ProjectKeys
import com.intellij.openapi.externalSystem.model.project.ModuleData
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.idea.compilerPlugin.CompilerPluginSetup.PluginOption
import org.jetbrains.kotlin.idea.gradleTooling.model.annotation.AnnotationBasedPluginModel
import org.jetbrains.kotlin.idea.compilerPlugin.CompilerPluginSetup
@@ -57,7 +57,8 @@ abstract class AbstractCompilerPluginGradleImportHandler<T> : GradleProjectImpor
protected open fun getOptions(model: T): List<PluginOption> = emptyList()
private fun getPluginSetupByModule(moduleNode: DataNode<ModuleData>): CompilerPluginSetup? {
val model = moduleNode.getCopyableUserData(modelKey)?.takeIf { isEnabled(it) } ?: return null
val modelNode = ExternalSystemApiUtil.find(moduleNode, modelKey)?: return null
val model = modelNode.data.takeIf { isEnabled(it) } ?: return null
val options = getOptions(model)
// For now we can't use plugins from Gradle cause they're shaded and may have an incompatible version.

View File

@@ -4,8 +4,8 @@ package org.jetbrains.kotlin.idea.gradleJava.compilerPlugin
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.Key
import com.intellij.openapi.externalSystem.model.project.ModuleData
import com.intellij.openapi.util.Key
import org.gradle.tooling.model.idea.IdeaModule
import org.jetbrains.kotlin.idea.gradleTooling.model.annotation.AnnotationBasedPluginModel
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
@@ -34,7 +34,7 @@ abstract class AnnotationBasedPluginProjectResolverExtension<T : AnnotationBased
@Suppress("UNCHECKED_CAST")
val refurbishedModel = Class.forName(className).constructors.single().newInstance(*args) as T
ideModule.putCopyableUserData(userDataKey, refurbishedModel)
ideModule.createChild(userDataKey, refurbishedModel)
}
super.populateModuleExtraModels(gradleModule, ideModule)

View File

@@ -2,13 +2,13 @@
package org.jetbrains.kotlin.idea.compilerPlugin.noarg.gradleJava
import com.intellij.openapi.util.Key
import com.intellij.openapi.externalSystem.model.Key
import org.jetbrains.kotlin.idea.gradleJava.compilerPlugin.AnnotationBasedPluginProjectResolverExtension
import org.jetbrains.kotlin.idea.gradleTooling.model.noarg.NoArgModel
class NoArgProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<NoArgModel>() {
companion object {
val KEY = Key<NoArgModel>("NoArgModel")
val KEY = Key.create(NoArgModel::class.java, 1)
}
override val modelClass get() = NoArgModel::class.java

View File

@@ -2,13 +2,13 @@
package org.jetbrains.kotlin.idea.compilerPlugin.samWithReceiver.gradleJava
import com.intellij.openapi.util.Key
import com.intellij.openapi.externalSystem.model.Key
import org.jetbrains.kotlin.idea.gradleJava.compilerPlugin.AnnotationBasedPluginProjectResolverExtension
import org.jetbrains.kotlin.idea.gradleTooling.model.samWithReceiver.SamWithReceiverModel
class SamWithReceiverProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<SamWithReceiverModel>() {
companion object {
val KEY = Key<SamWithReceiverModel>("SamWithReceiverModel")
val KEY = Key.create(SamWithReceiverModel::class.java, 1)
}
override val modelClass get() = SamWithReceiverModel::class.java