diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index e9797cc4b48..393db417113 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -918,14 +918,11 @@ compileTestKotlin { buildscript { repositories { mavenCentral() - maven { - url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' - } } dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0") - classpath("org.jetbrains.kotlin:kotlin-allopen:1.1.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.10") + classpath("org.jetbrains.kotlin:kotlin-allopen:1.2.10") } } @@ -949,6 +946,46 @@ compileTestKotlin { } } + @Test + fun testNoArgInvokeInitializers() { + createProjectSubFile("build.gradle", """ + group 'Again' + version '1.0-SNAPSHOT' + + buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.10") + classpath("org.jetbrains.kotlin:kotlin-noarg:1.2.10") + } + } + + apply plugin: 'kotlin' + apply plugin: "kotlin-noarg" + + noArg { + invokeInitializers = true + annotation("NoArg") + } + """) + importProject() + + with (facetSettings) { + Assert.assertEquals( + "-version", + compilerSettings!!.additionalArguments + ) + Assert.assertEquals( + listOf("plugin:org.jetbrains.kotlin.noarg:annotation=NoArg", + "plugin:org.jetbrains.kotlin.noarg:invokeInitializers=true"), + compilerArguments!!.pluginOptions!!.toList() + ) + } + } + @Test fun testAndroidGradleJsDetection() { createProjectSubFile("android-module/build.gradle", """ diff --git a/idea/src/META-INF/gradle.xml b/idea/src/META-INF/gradle.xml index 15ab6e337d4..865b4788b96 100644 --- a/idea/src/META-INF/gradle.xml +++ b/idea/src/META-INF/gradle.xml @@ -10,6 +10,9 @@ + + + diff --git a/plugins/allopen/allopen-ide/src/AllOpenGradleProjectImportHandler.kt b/plugins/allopen/allopen-ide/src/AllOpenGradleProjectImportHandler.kt index 9d26c684cd9..e9f87acc921 100644 --- a/plugins/allopen/allopen-ide/src/AllOpenGradleProjectImportHandler.kt +++ b/plugins/allopen/allopen-ide/src/AllOpenGradleProjectImportHandler.kt @@ -20,12 +20,12 @@ import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler import org.jetbrains.kotlin.utils.PathUtil -class AllOpenGradleProjectImportHandler : AbstractGradleImportHandler() { +class AllOpenGradleProjectImportHandler : AbstractGradleImportHandler() { override val compilerPluginId = AllOpenCommandLineProcessor.PLUGIN_ID override val pluginName = "allopen" override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name - override val dataStorageTaskName = "allOpenDataStorageTask" override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.allOpenPluginJarPath + override val modelKey = AllOpenProjectResolverExtension.KEY override fun getAnnotationsForPreset(presetName: String): List { for ((name, annotations) in AllOpenCommandLineProcessor.SUPPORTED_PRESETS.entries) { diff --git a/plugins/allopen/allopen-ide/src/AllOpenModelBuilderService.kt b/plugins/allopen/allopen-ide/src/AllOpenModelBuilderService.kt new file mode 100644 index 00000000000..8c40f2c7023 --- /dev/null +++ b/plugins/allopen/allopen-ide/src/AllOpenModelBuilderService.kt @@ -0,0 +1,48 @@ +/* + * 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.allopen.ide + +import com.intellij.openapi.util.Key +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginProjectResolverExtension + +interface AllOpenModel : AnnotationBasedPluginModel + +class AllOpenModelImpl( + override val annotations: List, + override val presets: List +) : AllOpenModel + +class AllOpenModelBuilderService : AnnotationBasedPluginModelBuilderService() { + 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, presets: List, extension: Any?): AllOpenModelImpl { + return AllOpenModelImpl(annotations, presets) + } +} + +class AllOpenProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension() { + companion object { + val KEY = Key("AllOpenModel") + } + + override val modelClass get() = AllOpenModel::class.java + override val userDataKey get() = KEY +} \ No newline at end of file diff --git a/plugins/allopen/allopen-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/allopen/allopen-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 00000000000..1da9e7c5776 --- /dev/null +++ b/plugins/allopen/allopen-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1 @@ +org.jetbrains.kotlin.allopen.ide.AllOpenModelBuilderService \ No newline at end of file diff --git a/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt b/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt index 6d196fbe9e2..9fc95fda3a2 100644 --- a/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt +++ b/plugins/annotation-based-compiler-plugins-ide-support/src/AbstractGradleImportHandler.kt @@ -19,25 +19,22 @@ package org.jetbrains.kotlin.annotation.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.model.task.TaskData import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil +import com.intellij.openapi.util.Key import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup.PluginOption 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 : GradleProjectImportHandler { - private companion object { - private val TASK_DESCRIPTION_REGEX = "Supported annotations: ([^; ]*); (?:Presets: (.*?); )?Compiler plugin classpath: (.*?)".toRegex() - } - +abstract class AbstractGradleImportHandler : GradleProjectImportHandler { abstract val compilerPluginId: String abstract val pluginName: String abstract val annotationOptionName: String - abstract val dataStorageTaskName: String abstract val pluginJarFileFromIdea: File + abstract val modelKey: Key + override fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode) { modifyCompilerArgumentsForPlugin(facet, getPluginSetupBySourceSet(sourceSetNode), compilerPluginId = compilerPluginId, @@ -52,20 +49,17 @@ abstract class AbstractGradleImportHandler : GradleProjectImportHandler { protected open fun getAnnotationsForPreset(presetName: String): List = emptyList() + protected open fun getAdditionalOptions(model: T): List = emptyList() + private fun getPluginSetupByModule( moduleNode: DataNode ): AnnotationBasedCompilerPluginSetup? { - val dataStorageTaskData = moduleNode.children.firstOrNull { - val data = it.data as? TaskData ?: return@firstOrNull false - data.name == dataStorageTaskName - }?.data as? TaskData ?: return null + val pluginModel = moduleNode.getUserData(modelKey)?.takeIf { it.isEnabled } ?: return null + val annotations = pluginModel.annotations + val presets = pluginModel.presets - val dataStorageTaskDescription = dataStorageTaskData.description ?: return null - val matchResult = TASK_DESCRIPTION_REGEX.matchEntire(dataStorageTaskDescription)?.groupValues?.drop(1) ?: return null - val (annotationFqNamesList, presets) = matchResult - - val annotationFqNames = annotationFqNamesList.split(',') + presets.split(',').flatMap { getAnnotationsForPreset(it) } - val options = annotationFqNames.map { PluginOption(annotationOptionName, it) } + val allAnnotations = annotations + presets.flatMap { getAnnotationsForPreset(it) } + val options = allAnnotations.map { PluginOption(annotationOptionName, it) } + getAdditionalOptions(pluginModel) // 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. diff --git a/plugins/annotation-based-compiler-plugins-ide-support/src/AnnotationBasedPluginProjectResolverExtension.kt b/plugins/annotation-based-compiler-plugins-ide-support/src/AnnotationBasedPluginProjectResolverExtension.kt new file mode 100644 index 00000000000..481f98b0df1 --- /dev/null +++ b/plugins/annotation-based-compiler-plugins-ide-support/src/AnnotationBasedPluginProjectResolverExtension.kt @@ -0,0 +1,121 @@ +/* + * 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.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.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 AnnotationBasedPluginModel : Serializable { + val annotations: List + val presets: List + + val isEnabled get() = annotations.isNotEmpty() || presets.isNotEmpty() +} + +@Suppress("unused") +abstract class AnnotationBasedPluginProjectResolverExtension : AbstractProjectResolverExtension() { + private companion object { + private val LOG = Logger.getInstance(AnnotationBasedPluginProjectResolverExtension::class.java) + } + + abstract val modelClass: Class + abstract val userDataKey: Key + + override fun getExtraProjectModelClasses() = setOf(modelClass) + + override fun getToolingExtensionsClasses() = setOf( + modelClass, + AnnotationBasedPluginProjectResolverExtension::class.java, + Unit::class.java) + + override fun populateModuleExtraModels(gradleModule: IdeaModule, ideModule: DataNode) { + val model = resolverCtx.getExtraProject(gradleModule, modelClass) + + if (model != null) { + ideModule.putUserData(userDataKey, model) + } + + super.populateModuleExtraModels(gradleModule, ideModule) + } +} + +abstract class AnnotationBasedPluginModelBuilderService : AbstractKotlinGradleModelBuilder() { + abstract val gradlePluginNames: List + abstract val extensionName: String + + abstract val modelClass: Class + abstract fun createModel(annotations: List, presets: List, 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() + val presets = mutableListOf() + + 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): Plugin<*>? { + for (name in names) { + plugins.findPlugin(name)?.let { return it } + } + + return null + } + + private fun Any.getList(fieldName: String): List { + @Suppress("UNCHECKED_CAST") + return getFieldValue(fieldName) as? List ?: 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 + } + } +} \ No newline at end of file diff --git a/plugins/noarg/noarg-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/noarg/noarg-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 00000000000..ae51c6db34e --- /dev/null +++ b/plugins/noarg/noarg-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1 @@ +org.jetbrains.kotlin.noarg.ide.NoArgModelBuilderService \ No newline at end of file diff --git a/plugins/noarg/noarg-ide/src/NoArgGradleProjectImportHandler.kt b/plugins/noarg/noarg-ide/src/NoArgGradleProjectImportHandler.kt index 6d06e39396f..7045986c03a 100644 --- a/plugins/noarg/noarg-ide/src/NoArgGradleProjectImportHandler.kt +++ b/plugins/noarg/noarg-ide/src/NoArgGradleProjectImportHandler.kt @@ -17,15 +17,23 @@ package org.jetbrains.kotlin.noarg.ide import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup.PluginOption import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor import org.jetbrains.kotlin.utils.PathUtil -class NoArgGradleProjectImportHandler : AbstractGradleImportHandler() { +class NoArgGradleProjectImportHandler : AbstractGradleImportHandler() { override val compilerPluginId = NoArgCommandLineProcessor.PLUGIN_ID override val pluginName = "noarg" override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name - override val dataStorageTaskName = "noArgDataStorageTask" override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.noArgPluginJarPath + override val modelKey = NoArgProjectResolverExtension.KEY + + override fun getAdditionalOptions(model: NoArgModel): List { + return listOf(PluginOption( + NoArgCommandLineProcessor.INVOKE_INITIALIZERS_OPTION.name, + model.invokeInitializers.toString())) + } override fun getAnnotationsForPreset(presetName: String): List { for ((name, annotations) in NoArgCommandLineProcessor.SUPPORTED_PRESETS.entries) { diff --git a/plugins/noarg/noarg-ide/src/NoArgModelBuilderService.kt b/plugins/noarg/noarg-ide/src/NoArgModelBuilderService.kt new file mode 100644 index 00000000000..3f1023fdd9f --- /dev/null +++ b/plugins/noarg/noarg-ide/src/NoArgModelBuilderService.kt @@ -0,0 +1,52 @@ +/* + * 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.AnnotationBasedPluginModel +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginProjectResolverExtension + +interface NoArgModel : AnnotationBasedPluginModel { + val invokeInitializers: Boolean +} + +class NoArgModelImpl( + override val annotations: List, + override val presets: List, + override val invokeInitializers: Boolean +) : NoArgModel + +class NoArgModelBuilderService : AnnotationBasedPluginModelBuilderService() { + 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, presets: List, extension: Any?): NoArgModel { + val invokeInitializers = extension?.getFieldValue("invokeInitializers") as? Boolean ?: false + return NoArgModelImpl(annotations, presets, invokeInitializers) + } +} + +class NoArgProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension() { + companion object { + val KEY = Key("NoArgModel") + } + + override val modelClass get() = NoArgModel::class.java + override val userDataKey get() = KEY +} \ No newline at end of file diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverGradleProjectImportHandler.kt b/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverGradleProjectImportHandler.kt deleted file mode 100644 index 5967d493853..00000000000 --- a/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverGradleProjectImportHandler.kt +++ /dev/null @@ -1,39 +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.samWithReceiver.ide - -import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor -import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler -import org.jetbrains.kotlin.utils.PathUtil - -class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler() { - override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID - override val pluginName = "sam-with-receiver" - override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name - override val dataStorageTaskName = "samWithReceiverDataStorageTask" - override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.samWithReceiverJarPath - - override fun getAnnotationsForPreset(presetName: String): List { - for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) { - if (presetName == name) { - return annotations - } - } - - return super.getAnnotationsForPreset(presetName) - } -} diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverMavenProjectImportHandler.kt b/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverMavenProjectImportHandler.kt deleted file mode 100644 index 915712085d2..00000000000 --- a/plugins/sam-with-receiver/sam-with-receiver-cli/src/SamWithReceiverMavenProjectImportHandler.kt +++ /dev/null @@ -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.samWithReceiver.ide - -import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor -import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler -import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup.PluginOption -import org.jetbrains.kotlin.utils.PathUtil - -class SamWithReceiverMavenProjectImportHandler : AbstractMavenImportHandler() { - private companion object { - val ANNOTATION_PARAMETER_PREFIX = "sam-with-receiver:${SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name}=" - } - - override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID - override val pluginName = "sam-with-receiver" - override val mavenPluginArtifactName = "kotlin-maven-sam-with-receiver" - override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.samWithReceiverJarPath - - override fun getOptions(enabledCompilerPlugins: List, compilerPluginOptions: List): List? { - if ("sam-with-receiver" !in enabledCompilerPlugins) { - return null - } - - val annotations = mutableListOf() - - for ((presetName, presetAnnotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS) { - if (presetName in enabledCompilerPlugins) { - annotations.addAll(presetAnnotations) - } - } - - annotations.addAll(compilerPluginOptions.mapNotNull { text -> - if (!text.startsWith(ANNOTATION_PARAMETER_PREFIX)) return@mapNotNull null - text.substring(ANNOTATION_PARAMETER_PREFIX.length) - }) - - return annotations.map { PluginOption(SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name, it) } - } -} diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/sam-with-receiver/sam-with-receiver-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 00000000000..4317479395c --- /dev/null +++ b/plugins/sam-with-receiver/sam-with-receiver-ide/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1 @@ +org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverModelBuilderService \ No newline at end of file diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt index 7fbcf9628c0..ff8328eb977 100644 --- a/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt +++ b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverGradleProjectImportHandler.kt @@ -17,15 +17,16 @@ package org.jetbrains.kotlin.samWithReceiver.ide import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor import org.jetbrains.kotlin.utils.PathUtil -class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler() { +class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler() { override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID override val pluginName = "sam-with-receiver" override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name - override val dataStorageTaskName = "samWithReceiverDataStorageTask" override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.samWithReceiverJarPath + override val modelKey = SamWithReceiverProjectResolverExtension.KEY override fun getAnnotationsForPreset(presetName: String): List { for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) { diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverModelBuilderService.kt b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverModelBuilderService.kt new file mode 100644 index 00000000000..7bba8aeb850 --- /dev/null +++ b/plugins/sam-with-receiver/sam-with-receiver-ide/src/SamWithReceiverModelBuilderService.kt @@ -0,0 +1,48 @@ +/* + * 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.samWithReceiver.ide + +import com.intellij.openapi.util.Key +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService +import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginProjectResolverExtension + +interface SamWithReceiverModel : AnnotationBasedPluginModel + +class SamWithReceiverModelImpl( + override val annotations: List, + override val presets: List +) : SamWithReceiverModel + +class SamWithReceiverModelBuilderService : AnnotationBasedPluginModelBuilderService() { + 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, presets: List, extension: Any?): SamWithReceiverModelImpl { + return SamWithReceiverModelImpl(annotations, presets) + } +} + +class SamWithReceiverProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension() { + companion object { + val KEY = Key("SamWithReceiverModel") + } + + override val modelClass get() = SamWithReceiverModel::class.java + override val userDataKey get() = KEY +} \ No newline at end of file