[Import] Downgrade jvmTarget & move Models and ModelBuilderServices

Fixed KT-35921
Fixed KT-36673
This commit is contained in:
Yaroslav Chernyshev
2020-04-13 19:20:30 +03:00
committed by Yaroslav Chernyshev
parent 385ddba2d9
commit 0b8c497d2e
22 changed files with 373 additions and 315 deletions
@@ -2,6 +2,7 @@ plugins {
kotlin("jvm")
id("jps-compatible")
}
jvmTarget = "1.6"
// BUNCH 193: this module is no longer needed since IDEA 2020.1
Platform[193].orLower {
+2 -1
View File
@@ -1,4 +1,3 @@
description = "Kotlin Gradle Tooling support"
plugins {
@@ -6,6 +5,8 @@ plugins {
id("jps-compatible")
}
jvmTarget = "1.6"
dependencies {
compile(kotlinStdlib())
@@ -1,3 +1,7 @@
org.jetbrains.kotlin.gradle.KotlinGradleModelBuilder
org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder
org.jetbrains.kotlin.gradle.KotlinCocoaPodsModelBuilder
org.jetbrains.kotlin.allopen.ide.AllOpenModelBuilderService
org.jetbrains.kotlin.kapt.idea.KaptModelBuilderService
org.jetbrains.kotlin.noarg.ide.NoArgModelBuilderService
org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverModelBuilderService
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2020 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.allopen.ide
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService
import org.jetbrains.kotlin.annotation.plugin.ide.DumpedPluginModel
import org.jetbrains.kotlin.annotation.plugin.ide.DumpedPluginModelImpl
interface AllOpenModel : AnnotationBasedPluginModel {
override fun dump(): DumpedPluginModel {
return DumpedPluginModelImpl(AllOpenModelImpl::class.java, annotations.toList(), presets.toList())
}
}
class AllOpenModelImpl(
override val annotations: List<String>,
override val presets: List<String>
) : AllOpenModel
class AllOpenModelBuilderService : AnnotationBasedPluginModelBuilderService<AllOpenModel>() {
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.allopen", "kotlin-allopen")
override val extensionName get() = "allOpen"
override val modelClass get() = AllOpenModel::class.java
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): AllOpenModelImpl {
return AllOpenModelImpl(annotations, presets)
}
}
@@ -0,0 +1,100 @@
/*
* Copyright 2010-2020 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
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import java.io.Serializable
import java.lang.Exception
interface DumpedPluginModel {
val className: String
// May contain primitives, Strings and collections of primitives/Strings
val args: Array<*>
operator fun component1() = className
operator fun component2() = args
}
class DumpedPluginModelImpl(
override val className: String,
override val args: Array<*>
) : DumpedPluginModel, Serializable {
constructor(clazz: Class<*>, vararg args: Any?) : this(clazz.canonicalName, args)
}
interface AnnotationBasedPluginModel : Serializable {
val annotations: List<String>
val presets: List<String>
/*
Objects returned from Gradle importer are implicitly wrapped in a proxy that can potentially leak internal Gradle structures.
So we need a way to safely serialize the arbitrary annotation plugin model.
*/
fun dump(): DumpedPluginModel
val isEnabled get() = annotations.isNotEmpty() || presets.isNotEmpty()
}
abstract class AnnotationBasedPluginModelBuilderService<T : AnnotationBasedPluginModel> : AbstractKotlinGradleModelBuilder() {
abstract val gradlePluginNames: List<String>
abstract val extensionName: String
abstract val modelClass: Class<T>
abstract fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): T
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
return ErrorMessageBuilder.create(project, e, "Gradle import errors")
.withDescription("Unable to build $gradlePluginNames plugin configuration")
}
override fun canBuild(modelName: String?): Boolean = modelName == modelClass.name
override fun buildAll(modelName: String?, project: Project): Any {
val plugin: Plugin<*>? = project.findPlugin(gradlePluginNames)
val extension: Any? = project.extensions.findByName(extensionName)
val annotations = mutableListOf<String>()
val presets = mutableListOf<String>()
if (plugin != null && extension != null) {
annotations += extension.getList("myAnnotations")
presets += extension.getList("myPresets")
return createModel(annotations, presets, extension)
}
return createModel(emptyList(), emptyList(), null)
}
private fun Project.findPlugin(names: List<String>): Plugin<*>? {
for (name in names) {
plugins.findPlugin(name)?.let { return it }
}
return null
}
private fun Any.getList(fieldName: String): List<String> {
@Suppress("UNCHECKED_CAST")
return getFieldValue(fieldName) as? List<String> ?: emptyList()
}
protected fun Any.getFieldValue(fieldName: String, clazz: Class<*> = this.javaClass): Any? {
val field = clazz.declaredFields.firstOrNull { it.name == fieldName }
?: return getFieldValue(fieldName, clazz.superclass ?: return null)
val oldIsAccessible = field.isAccessible
try {
field.isAccessible = true
return field.get(this)
} finally {
field.isAccessible = oldIsAccessible
}
}
}
@@ -0,0 +1,127 @@
/*
* Copyright 2010-2020 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.kapt.idea
import org.gradle.api.Named
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder.Companion.getTargets
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import java.io.File
import java.io.Serializable
import java.lang.Exception
import java.lang.reflect.Modifier
interface KaptSourceSetModel : Serializable {
val sourceSetName: String
val isTest: Boolean
val generatedSourcesDir: String
val generatedClassesDir: String
val generatedKotlinSourcesDir: String
val generatedSourcesDirFile get() = generatedSourcesDir.takeIf { it.isNotEmpty() }?.let(::File)
val generatedClassesDirFile get() = generatedClassesDir.takeIf { it.isNotEmpty() }?.let(::File)
val generatedKotlinSourcesDirFile get() = generatedKotlinSourcesDir.takeIf { it.isNotEmpty() }?.let(::File)
}
class KaptSourceSetModelImpl(
override val sourceSetName: String,
override val isTest: Boolean,
override val generatedSourcesDir: String,
override val generatedClassesDir: String,
override val generatedKotlinSourcesDir: String
) : KaptSourceSetModel
interface KaptGradleModel : Serializable {
val isEnabled: Boolean
val buildDirectory: File
val sourceSets: List<KaptSourceSetModel>
}
class KaptGradleModelImpl(
override val isEnabled: Boolean,
override val buildDirectory: File,
override val sourceSets: List<KaptSourceSetModel>
) : KaptGradleModel
class KaptModelBuilderService : AbstractKotlinGradleModelBuilder() {
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
return ErrorMessageBuilder.create(project, e, "Gradle import errors")
.withDescription("Unable to build kotlin-kapt plugin configuration")
}
override fun canBuild(modelName: String?): Boolean = modelName == KaptGradleModel::class.java.name
override fun buildAll(modelName: String?, project: Project): Any {
val kaptPlugin: Plugin<*>? = project.plugins.findPlugin("kotlin-kapt")
val kaptIsEnabled = kaptPlugin != null
val sourceSets = mutableListOf<KaptSourceSetModel>()
if (kaptIsEnabled) {
val targets = project.getTargets()
fun handleCompileTask(moduleName: String, compileTask: Task) {
if (compileTask.javaClass.name !in kotlinCompileJvmTaskClasses) {
return
}
val sourceSetName = compileTask.getSourceSetName()
val isTest = sourceSetName.toLowerCase().endsWith("test")
val kaptGeneratedSourcesDir = getKaptDirectory("getKaptGeneratedSourcesDir", project, sourceSetName)
val kaptGeneratedClassesDir = getKaptDirectory("getKaptGeneratedClassesDir", project, sourceSetName)
val kaptGeneratedKotlinSourcesDir = getKaptDirectory("getKaptGeneratedKotlinSourcesDir", project, sourceSetName)
sourceSets += KaptSourceSetModelImpl(
moduleName, isTest, kaptGeneratedSourcesDir, kaptGeneratedClassesDir, kaptGeneratedKotlinSourcesDir
)
}
if (targets != null && targets.isNotEmpty()) {
for (target in targets) {
if (!isWithJavaEnabled(target)) {
continue
}
val compilations = KotlinMPPGradleModelBuilder.getCompilations(target) ?: continue
for (compilation in compilations) {
val compileTask = KotlinMPPGradleModelBuilder.getCompileKotlinTaskName(project, compilation) ?: continue
val moduleName = target.name + compilation.name.capitalize()
handleCompileTask(moduleName, compileTask)
}
}
} else {
project.getAllTasks(false)[project]?.forEach { compileTask ->
val sourceSetName = compileTask.getSourceSetName()
handleCompileTask(sourceSetName, compileTask)
}
}
}
return KaptGradleModelImpl(kaptIsEnabled, project.buildDir, sourceSets)
}
private fun isWithJavaEnabled(target: Named): Boolean {
val getWithJavaEnabledMethod = target.javaClass.methods
.firstOrNull { it.name == "getWithJavaEnabled" && it.parameterCount == 0 } ?: return false
return getWithJavaEnabledMethod.invoke(target) == true
}
private fun getKaptDirectory(funName: String, project: Project, sourceSetName: String): String {
val kotlinKaptPlugin = project.plugins.findPlugin("kotlin-kapt") ?: return ""
val targetMethod = kotlinKaptPlugin::class.java.methods.firstOrNull {
Modifier.isStatic(it.modifiers) && it.name == funName && it.parameterCount == 2
} ?: return ""
return (targetMethod(null, project, sourceSetName) as? File)?.absolutePath ?: ""
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2020 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.noarg.ide
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService
import org.jetbrains.kotlin.annotation.plugin.ide.DumpedPluginModel
import org.jetbrains.kotlin.annotation.plugin.ide.DumpedPluginModelImpl
interface NoArgModel : AnnotationBasedPluginModel {
val invokeInitializers: Boolean
override fun dump(): DumpedPluginModel {
return DumpedPluginModelImpl(NoArgModelImpl::class.java, annotations.toList(), presets.toList(), invokeInitializers)
}
}
class NoArgModelImpl(
override val annotations: List<String>,
override val presets: List<String>,
override val invokeInitializers: Boolean
) : NoArgModel
class NoArgModelBuilderService : AnnotationBasedPluginModelBuilderService<NoArgModel>() {
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.noarg", "kotlin-noarg")
override val extensionName get() = "noArg"
override val modelClass get() = NoArgModel::class.java
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): NoArgModel {
val invokeInitializers = extension?.getFieldValue("invokeInitializers") as? Boolean ?: false
return NoArgModelImpl(annotations, presets, invokeInitializers)
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2020 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.samWithReceiver.ide
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService
import org.jetbrains.kotlin.annotation.plugin.ide.DumpedPluginModel
import org.jetbrains.kotlin.annotation.plugin.ide.DumpedPluginModelImpl
interface SamWithReceiverModel : AnnotationBasedPluginModel {
override fun dump(): DumpedPluginModel {
return DumpedPluginModelImpl(SamWithReceiverModelImpl::class.java, annotations.toList(), presets.toList())
}
}
class SamWithReceiverModelImpl(
override val annotations: List<String>,
override val presets: List<String>
) : SamWithReceiverModel
class SamWithReceiverModelBuilderService : AnnotationBasedPluginModelBuilderService<SamWithReceiverModel>() {
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.sam.with.receiver", "kotlin-sam-with-receiver")
override val extensionName get() = "samWithReceiver"
override val modelClass get() = SamWithReceiverModel::class.java
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): SamWithReceiverModelImpl {
return SamWithReceiverModelImpl(annotations, presets)
}
}
@@ -19,6 +19,7 @@ dependencies {
compileOnly(intellijDep())
excludeInAndroidStudio(rootProject) { compileOnly(intellijPluginDep("maven")) }
compileOnly(intellijPluginDep("gradle"))
compileOnly(project(":idea:kotlin-gradle-tooling"))
testRuntime(project(":kotlin-reflect"))
@@ -1 +0,0 @@
org.jetbrains.kotlin.allopen.ide.AllOpenModelBuilderService
@@ -19,27 +19,6 @@ package org.jetbrains.kotlin.allopen.ide
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.annotation.plugin.ide.*
interface AllOpenModel : AnnotationBasedPluginModel {
override fun dump(): DumpedPluginModel {
return DumpedPluginModelImpl(AllOpenModelImpl::class.java, annotations.toList(), presets.toList())
}
}
class AllOpenModelImpl(
override val annotations: List<String>,
override val presets: List<String>
) : AllOpenModel
class AllOpenModelBuilderService : AnnotationBasedPluginModelBuilderService<AllOpenModel>() {
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.allopen", "kotlin-allopen")
override val extensionName get() = "allOpen"
override val modelClass get() = AllOpenModel::class.java
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): AllOpenModelImpl {
return AllOpenModelImpl(annotations, presets)
}
}
class AllOpenProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<AllOpenModel>() {
companion object {
val KEY = Key<AllOpenModel>("AllOpenModel")
@@ -16,7 +16,8 @@ dependencies {
excludeInAndroidStudio(rootProject) { compileOnly(intellijPluginDep("maven")) }
compileOnly(intellijPluginDep("gradle"))
compileOnly(intellijDep())
}
compileOnly(project(":idea:kotlin-gradle-tooling"))
}
sourceSets {
"main" { projectDefault() }
@@ -18,46 +18,10 @@ package org.jetbrains.kotlin.annotation.plugin.ide
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.project.*
import com.intellij.openapi.externalSystem.model.project.ModuleData
import com.intellij.openapi.util.Key
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.tooling.model.idea.IdeaModule
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import java.io.Serializable
import java.lang.Exception
interface DumpedPluginModel {
val className: String
// May contain primitives, Strings and collections of primitives/Strings
val args: Array<*>
operator fun component1() = className
operator fun component2() = args
}
class DumpedPluginModelImpl(
override val className: String,
override val args: Array<*>
) : DumpedPluginModel, Serializable {
constructor(clazz: Class<*>, vararg args: Any?) : this(clazz.canonicalName, args)
}
interface AnnotationBasedPluginModel : Serializable {
val annotations: List<String>
val presets: List<String>
/*
Objects returned from Gradle importer are implicitly wrapped in a proxy that can potentially leak internal Gradle structures.
So we need a way to safely serialize the arbitrary annotation plugin model.
*/
fun dump(): DumpedPluginModel
val isEnabled get() = annotations.isNotEmpty() || presets.isNotEmpty()
}
@Suppress("unused")
abstract class AnnotationBasedPluginProjectResolverExtension<T : AnnotationBasedPluginModel> : AbstractProjectResolverExtension() {
@@ -90,60 +54,3 @@ abstract class AnnotationBasedPluginProjectResolverExtension<T : AnnotationBased
super.populateModuleExtraModels(gradleModule, ideModule)
}
}
abstract class AnnotationBasedPluginModelBuilderService<T : AnnotationBasedPluginModel> : AbstractKotlinGradleModelBuilder() {
abstract val gradlePluginNames: List<String>
abstract val extensionName: String
abstract val modelClass: Class<T>
abstract fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): T
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
return ErrorMessageBuilder.create(project, e, "Gradle import errors")
.withDescription("Unable to build $gradlePluginNames plugin configuration")
}
override fun canBuild(modelName: String?): Boolean = modelName == modelClass.name
override fun buildAll(modelName: String?, project: Project): Any {
val plugin: Plugin<*>? = project.findPlugin(gradlePluginNames)
val extension: Any? = project.extensions.findByName(extensionName)
val annotations = mutableListOf<String>()
val presets = mutableListOf<String>()
if (plugin != null && extension != null) {
annotations += extension.getList("myAnnotations")
presets += extension.getList("myPresets")
return createModel(annotations, presets, extension)
}
return createModel(emptyList(), emptyList(), null)
}
private fun Project.findPlugin(names: List<String>): Plugin<*>? {
for (name in names) {
plugins.findPlugin(name)?.let { return it }
}
return null
}
private fun Any.getList(fieldName: String): List<String> {
@Suppress("UNCHECKED_CAST")
return getFieldValue(fieldName) as? List<String> ?: emptyList()
}
protected fun Any.getFieldValue(fieldName: String, clazz: Class<*> = this.javaClass): Any? {
val field = clazz.declaredFields.firstOrNull { it.name == fieldName }
?: return getFieldValue(fieldName, clazz.superclass ?: return null)
val oldIsAccessible = field.isAccessible
try {
field.isAccessible = true
return field.get(this)
} finally {
field.isAccessible = oldIsAccessible
}
}
}
@@ -1 +0,0 @@
org.jetbrains.kotlin.kapt.idea.KaptModelBuilderService
@@ -20,55 +20,10 @@ import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.ProjectKeys
import com.intellij.openapi.externalSystem.model.project.*
import org.gradle.api.Named
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.tooling.model.idea.IdeaModule
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder.Companion.getCompilations
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder.Companion.getCompileKotlinTaskName
import org.jetbrains.kotlin.gradle.KotlinMPPGradleModelBuilder.Companion.getTargets
import org.jetbrains.kotlin.idea.framework.GRADLE_SYSTEM_ID
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import java.io.File
import java.io.Serializable
import java.lang.Exception
import java.lang.reflect.Modifier
interface KaptSourceSetModel : Serializable {
val sourceSetName: String
val isTest: Boolean
val generatedSourcesDir: String
val generatedClassesDir: String
val generatedKotlinSourcesDir: String
val generatedSourcesDirFile get() = generatedSourcesDir.takeIf { it.isNotEmpty() }?.let(::File)
val generatedClassesDirFile get() = generatedClassesDir.takeIf { it.isNotEmpty() }?.let(::File)
val generatedKotlinSourcesDirFile get() = generatedKotlinSourcesDir.takeIf { it.isNotEmpty() }?.let(::File)
}
class KaptSourceSetModelImpl(
override val sourceSetName: String,
override val isTest: Boolean,
override val generatedSourcesDir: String,
override val generatedClassesDir: String,
override val generatedKotlinSourcesDir: String
) : KaptSourceSetModel
interface KaptGradleModel : Serializable {
val isEnabled: Boolean
val buildDirectory: File
val sourceSets: List<KaptSourceSetModel>
}
class KaptGradleModelImpl(
override val isEnabled: Boolean,
override val buildDirectory: File,
override val sourceSets: List<KaptSourceSetModel>
) : KaptGradleModel
@Suppress("unused")
class KaptProjectResolverExtension : AbstractProjectResolverExtension() {
@@ -130,77 +85,3 @@ class KaptProjectResolverExtension : AbstractProjectResolverExtension() {
}
}
class KaptModelBuilderService : AbstractKotlinGradleModelBuilder() {
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
return ErrorMessageBuilder.create(project, e, "Gradle import errors")
.withDescription("Unable to build kotlin-kapt plugin configuration")
}
override fun canBuild(modelName: String?): Boolean = modelName == KaptGradleModel::class.java.name
override fun buildAll(modelName: String?, project: Project): Any {
val kaptPlugin: Plugin<*>? = project.plugins.findPlugin("kotlin-kapt")
val kaptIsEnabled = kaptPlugin != null
val sourceSets = mutableListOf<KaptSourceSetModel>()
if (kaptIsEnabled) {
val targets = project.getTargets()
fun handleCompileTask(moduleName: String, compileTask: Task) {
if (compileTask.javaClass.name !in kotlinCompileJvmTaskClasses) {
return
}
val sourceSetName = compileTask.getSourceSetName()
val isTest = sourceSetName.toLowerCase().endsWith("test")
val kaptGeneratedSourcesDir = getKaptDirectory("getKaptGeneratedSourcesDir", project, sourceSetName)
val kaptGeneratedClassesDir = getKaptDirectory("getKaptGeneratedClassesDir", project, sourceSetName)
val kaptGeneratedKotlinSourcesDir = getKaptDirectory("getKaptGeneratedKotlinSourcesDir", project, sourceSetName)
sourceSets += KaptSourceSetModelImpl(
moduleName, isTest, kaptGeneratedSourcesDir, kaptGeneratedClassesDir, kaptGeneratedKotlinSourcesDir
)
}
if (targets != null && targets.isNotEmpty()) {
for (target in targets) {
if (!isWithJavaEnabled(target)) {
continue
}
val compilations = getCompilations(target) ?: continue
for (compilation in compilations) {
val compileTask = getCompileKotlinTaskName(project, compilation) ?: continue
val moduleName = target.name + compilation.name.capitalize()
handleCompileTask(moduleName, compileTask)
}
}
} else {
project.getAllTasks(false)[project]?.forEach { compileTask ->
val sourceSetName = compileTask.getSourceSetName()
handleCompileTask(sourceSetName, compileTask)
}
}
}
return KaptGradleModelImpl(kaptIsEnabled, project.buildDir, sourceSets)
}
private fun isWithJavaEnabled(target: Named): Boolean {
val getWithJavaEnabledMethod = target.javaClass.methods
.firstOrNull { it.name == "getWithJavaEnabled" && it.parameterCount == 0 } ?: return false
return getWithJavaEnabledMethod.invoke(target) == true
}
private fun getKaptDirectory(funName: String, project: Project, sourceSetName: String): String {
val kotlinKaptPlugin = project.plugins.findPlugin("kotlin-kapt") ?: return ""
val targetMethod = kotlinKaptPlugin::class.java.methods.firstOrNull {
Modifier.isStatic(it.modifiers) && it.name == funName && it.parameterCount == 2
} ?: return ""
return (targetMethod(null, project, sourceSetName) as? File)?.absolutePath ?: ""
}
}
+1
View File
@@ -20,6 +20,7 @@ dependencies {
compileOnly(intellijDep())
excludeInAndroidStudio(rootProject) { compileOnly(intellijPluginDep("maven")) }
compileOnly(intellijPluginDep("gradle"))
compileOnly(project(":idea:kotlin-gradle-tooling"))
testRuntime(project(":kotlin-reflect"))
@@ -1 +0,0 @@
org.jetbrains.kotlin.noarg.ide.NoArgModelBuilderService
@@ -1,54 +0,0 @@
/*
* Copyright 2010-2017 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.
*/
package org.jetbrains.kotlin.noarg.ide
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.annotation.plugin.ide.*
interface NoArgModel : AnnotationBasedPluginModel {
val invokeInitializers: Boolean
override fun dump(): DumpedPluginModel {
return DumpedPluginModelImpl(NoArgModelImpl::class.java, annotations.toList(), presets.toList(), invokeInitializers)
}
}
class NoArgModelImpl(
override val annotations: List<String>,
override val presets: List<String>,
override val invokeInitializers: Boolean
) : NoArgModel
class NoArgModelBuilderService : AnnotationBasedPluginModelBuilderService<NoArgModel>() {
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.noarg", "kotlin-noarg")
override val extensionName get() = "noArg"
override val modelClass get() = NoArgModel::class.java
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): NoArgModel {
val invokeInitializers = extension?.getFieldValue("invokeInitializers") as? Boolean ?: false
return NoArgModelImpl(annotations, presets, invokeInitializers)
}
}
class NoArgProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<NoArgModel>() {
companion object {
val KEY = Key<NoArgModel>("NoArgModel")
}
override val modelClass get() = NoArgModel::class.java
override val userDataKey get() = KEY
}
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2017 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.
*/
package org.jetbrains.kotlin.noarg.ide
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.annotation.plugin.ide.*
class NoArgProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<NoArgModel>() {
companion object {
val KEY = Key<NoArgModel>("NoArgModel")
}
override val modelClass get() = NoArgModel::class.java
override val userDataKey get() = KEY
}
@@ -23,6 +23,7 @@ dependencies {
}
compileOnly(intellijDep()) { includeJars("platform-api", "extensions", "util") }
compileOnly(intellijDep("gradle"))
compileOnly(project(":idea:kotlin-gradle-tooling"))
}
sourceSets {
@@ -1 +0,0 @@
org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverModelBuilderService
@@ -19,27 +19,6 @@ package org.jetbrains.kotlin.samWithReceiver.ide
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.annotation.plugin.ide.*
interface SamWithReceiverModel : AnnotationBasedPluginModel {
override fun dump(): DumpedPluginModel {
return DumpedPluginModelImpl(SamWithReceiverModelImpl::class.java, annotations.toList(), presets.toList())
}
}
class SamWithReceiverModelImpl(
override val annotations: List<String>,
override val presets: List<String>
) : SamWithReceiverModel
class SamWithReceiverModelBuilderService : AnnotationBasedPluginModelBuilderService<SamWithReceiverModel>() {
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.sam.with.receiver", "kotlin-sam-with-receiver")
override val extensionName get() = "samWithReceiver"
override val modelClass get() = SamWithReceiverModel::class.java
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): SamWithReceiverModelImpl {
return SamWithReceiverModelImpl(annotations, presets)
}
}
class SamWithReceiverProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<SamWithReceiverModel>() {
companion object {
val KEY = Key<SamWithReceiverModel>("SamWithReceiverModel")