[lombok] Support import from gradle to IDE
Introduce base module for ide compiler plugins
This commit is contained in:
committed by
TeamCityServer
parent
b58bea6fa1
commit
8afb6d2761
@@ -38,6 +38,7 @@ dependencies {
|
||||
testCompileOnly(project(":kotlin-sam-with-receiver-compiler-plugin"))
|
||||
testCompileOnly(project(":noarg-ide-plugin"))
|
||||
testCompileOnly(project(":sam-with-receiver-ide-plugin"))
|
||||
testCompileOnly(project(":plugins:lombok:lombok-ide-plugin"))
|
||||
testCompileOnly(project(":idea:idea-native"))
|
||||
testCompileOnly(project(":idea:idea-gradle-native"))
|
||||
testCompileOnly(projectTests(":idea:idea-test-framework"))
|
||||
|
||||
@@ -48,6 +48,7 @@ dependencies {
|
||||
testRuntime(project(":kotlinx-serialization-ide-plugin"))
|
||||
testRuntime(project(":plugins:lint"))
|
||||
testRuntime(project(":plugins:parcelize:parcelize-ide"))
|
||||
testRuntime(project(":plugins:lombok:lombok-ide-plugin"))
|
||||
testRuntime(intellijPluginDep("junit"))
|
||||
testRuntime(intellijPluginDep("IntelliLang"))
|
||||
testRuntime(intellijPluginDep("properties"))
|
||||
|
||||
+3
-14
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.annotation.plugin.ide
|
||||
@@ -70,4 +59,4 @@ abstract class AbstractGradleImportHandler<T : AnnotationBasedPluginModel> : Gra
|
||||
|
||||
private fun getPluginSetupBySourceSet(sourceSetNode: DataNode<GradleSourceSetData>) =
|
||||
ExternalSystemApiUtil.findParent(sourceSetNode, ProjectKeys.MODULE)?.let { getPluginSetupByModule(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":compiler:util"))
|
||||
compile(project(":compiler:frontend"))
|
||||
compile(project(":compiler:cli-common"))
|
||||
compile(project(":idea"))
|
||||
compile(project(":idea:idea-jvm"))
|
||||
compile(project(":idea:idea-jps-common"))
|
||||
compile(project(":idea:idea-gradle"))
|
||||
compile(project(":idea:idea-maven"))
|
||||
excludeInAndroidStudio(rootProject) { compileOnly(intellijPluginDep("maven")) }
|
||||
compileOnly(intellijPluginDep("gradle"))
|
||||
compileOnly(intellijDep())
|
||||
compileOnly(project(":idea:kotlin-gradle-tooling"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" {}
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.plugin.ide
|
||||
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
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.configuration.GradleProjectImportHandler
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractGradleImportHandler<T> : GradleProjectImportHandler {
|
||||
|
||||
abstract val modelKey: Key<T>
|
||||
abstract val pluginJarFileFromIdea: File
|
||||
abstract val compilerPluginId: String
|
||||
abstract val pluginName: String
|
||||
|
||||
abstract fun getOptions(model: T): List<CompilerPluginSetup.PluginOption>?
|
||||
|
||||
override fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode<GradleSourceSetData>) {
|
||||
modifyCompilerArgumentsForPlugin(
|
||||
facet, getPluginSetupBySourceSet(sourceSetNode),
|
||||
compilerPluginId = compilerPluginId,
|
||||
pluginName = pluginName
|
||||
)
|
||||
}
|
||||
|
||||
override fun importByModule(facet: KotlinFacet, moduleNode: DataNode<ModuleData>) {
|
||||
modifyCompilerArgumentsForPlugin(
|
||||
facet, getPluginSetupByModule(moduleNode),
|
||||
compilerPluginId = compilerPluginId,
|
||||
pluginName = pluginName
|
||||
)
|
||||
}
|
||||
|
||||
private fun getPluginSetupByModule(moduleNode: DataNode<ModuleData>): CompilerPluginSetup? {
|
||||
val pluginModel = moduleNode.getCopyableUserData(modelKey) ?: return null
|
||||
|
||||
val options = getOptions(pluginModel) ?: return null
|
||||
// For now we can't use plugins from Gradle cause they're shaded and may have an incompatible version.
|
||||
// So we use ones from the IDEA plugin.
|
||||
val classpath = listOf(pluginJarFileFromIdea.absolutePath)
|
||||
|
||||
return CompilerPluginSetup(options, classpath)
|
||||
}
|
||||
|
||||
private fun getPluginSetupBySourceSet(sourceSetNode: DataNode<GradleSourceSetData>) =
|
||||
ExternalSystemApiUtil.findParent(sourceSetNode, ProjectKeys.MODULE)?.let { getPluginSetupByModule(it) }
|
||||
}
|
||||
+2
-3
@@ -3,7 +3,7 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lombok.ide
|
||||
package org.jetbrains.kotlin.plugin.ide
|
||||
|
||||
import org.jdom.Element
|
||||
import org.jdom.Text
|
||||
@@ -13,12 +13,11 @@ import org.jetbrains.kotlin.idea.maven.MavenProjectImportHandler
|
||||
import org.jetbrains.kotlin.idea.maven.KotlinMavenImporter.Companion.KOTLIN_PLUGIN_GROUP_ID
|
||||
import org.jetbrains.kotlin.idea.maven.KotlinMavenImporter.Companion.KOTLIN_PLUGIN_ARTIFACT_ID
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.lombok.ide.CompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.plugin.ide.CompilerPluginSetup.PluginOption
|
||||
|
||||
abstract class AbstractMavenImportHandler : MavenProjectImportHandler {
|
||||
abstract val compilerPluginId: String
|
||||
abstract val pluginName: String
|
||||
// abstract val mavenPluginArtifactName: String
|
||||
abstract val pluginJarFileFromIdea: File
|
||||
|
||||
override fun invoke(facet: KotlinFacet, mavenProject: MavenProject) {
|
||||
+4
-1
@@ -3,12 +3,15 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lombok.ide
|
||||
package org.jetbrains.kotlin.plugin.ide
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import java.io.File
|
||||
|
||||
//todo this is basically a copy-paste of the same file from annotation-based-compiler-plugins-ide-support
|
||||
//and should be merged together later
|
||||
|
||||
class CompilerPluginSetup(val options: List<PluginOption>, val classpath: List<String>) {
|
||||
class PluginOption(val key: String, val value: String)
|
||||
}
|
||||
@@ -35,6 +35,7 @@ dependencies {
|
||||
testRuntime(project(":plugins:parcelize:parcelize-ide"))
|
||||
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
||||
testRuntime(project(":noarg-ide-plugin"))
|
||||
testRuntime(project(":plugins:lombok:lombok-ide-plugin"))
|
||||
testCompile(intellijDep())
|
||||
testCompile(intellijPluginDep("java"))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":plugins:lombok:lombok-compiler-plugin"))
|
||||
implementation(project(":plugins:base-compiler-plugins-ide-support"))
|
||||
|
||||
compileOnly(project(":idea"))
|
||||
compileOnly(project(":idea:idea-jvm"))
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lombok.ide
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.lombok.LombokCommandLineProcessor
|
||||
import org.jetbrains.kotlin.lombok.LombokCommandLineProcessor.Companion.CONFIG_FILE_OPTION
|
||||
import org.jetbrains.kotlin.plugin.ide.AbstractGradleImportHandler
|
||||
import org.jetbrains.kotlin.plugin.ide.CompilerPluginSetup
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import java.io.File
|
||||
|
||||
class LombokGradleProjectImportHandler : AbstractGradleImportHandler<LombokModel>() {
|
||||
|
||||
override val modelKey: Key<LombokModel> = LombokGradleProjectResolverExtension.KEY
|
||||
override val pluginJarFileFromIdea: File = PathUtil.kotlinPathsForIdeaPlugin.lombokPluginJarPath
|
||||
override val compilerPluginId: String = LombokCommandLineProcessor.PLUGIN_ID
|
||||
override val pluginName: String = "lombok"
|
||||
|
||||
override fun getOptions(model: LombokModel): List<CompilerPluginSetup.PluginOption> =
|
||||
listOfNotNull(
|
||||
model.configurationFile?.let {
|
||||
CompilerPluginSetup.PluginOption(CONFIG_FILE_OPTION.optionName, it.path)
|
||||
}
|
||||
)
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.lombok.ide
|
||||
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.gradle.tooling.model.idea.IdeaModule
|
||||
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
|
||||
|
||||
class LombokGradleProjectResolverExtension : AbstractProjectResolverExtension() {
|
||||
|
||||
private val modelClass: Class<LombokModel> = LombokModel::class.java
|
||||
private val userDataKey: Key<LombokModel> = KEY
|
||||
|
||||
override fun getExtraProjectModelClasses() = setOf(modelClass)
|
||||
|
||||
override fun getToolingExtensionsClasses() = setOf(
|
||||
modelClass,
|
||||
LombokGradleProjectResolverExtension::class.java,
|
||||
Unit::class.java
|
||||
)
|
||||
|
||||
override fun populateModuleExtraModels(gradleModule: IdeaModule, ideModule: DataNode<ModuleData>) {
|
||||
val model = resolverCtx.getExtraProject(gradleModule, modelClass)
|
||||
|
||||
if (model != null) {
|
||||
ideModule.putCopyableUserData(userDataKey, model)
|
||||
}
|
||||
|
||||
super.populateModuleExtraModels(gradleModule, ideModule)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val KEY = Key<LombokModel>("LombokModel")
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -7,7 +7,8 @@ package org.jetbrains.kotlin.lombok.ide
|
||||
|
||||
import org.jetbrains.kotlin.lombok.LombokCommandLineProcessor
|
||||
import org.jetbrains.kotlin.lombok.LombokCommandLineProcessor.Companion.CONFIG_FILE_OPTION
|
||||
import org.jetbrains.kotlin.lombok.ide.CompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.plugin.ide.AbstractMavenImportHandler
|
||||
import org.jetbrains.kotlin.plugin.ide.CompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import java.io.File
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ dependencies {
|
||||
testRuntime(project(":plugins:kapt3-idea"))
|
||||
testRuntime(project(":kotlinx-serialization-ide-plugin"))
|
||||
testRuntime(project(":plugins:parcelize:parcelize-ide"))
|
||||
testRuntime(project(":plugins:lombok:lombok-ide-plugin"))
|
||||
testRuntime(intellijDep())
|
||||
testRuntime(intellijPluginDep("junit"))
|
||||
testRuntime(intellijPluginDep("gradle"))
|
||||
|
||||
Reference in New Issue
Block a user