diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt index c599bef1d6b..5e8694b18c0 100644 --- a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt +++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt @@ -29,20 +29,23 @@ import com.intellij.mock.MockProject public object ExampleConfigurationKeys { public val EXAMPLE_KEY: CompilerConfigurationKey = CompilerConfigurationKey.create("example argument") + public val EXAMPLE_LEGACY_KEY: CompilerConfigurationKey = CompilerConfigurationKey.create("example legacy argument") } public class ExampleCommandLineProcessor : CommandLineProcessor { companion object { public val EXAMPLE_PLUGIN_ID: String = "example.plugin" public val EXAMPLE_OPTION: CliOption = CliOption("exampleKey", "", "") + public val EXAMPLE_LEGACY_OPTION: CliOption = CliOption("exampleLegacyKey", "", "") } override val pluginId: String = EXAMPLE_PLUGIN_ID - override val pluginOptions: Collection = listOf(EXAMPLE_OPTION) + override val pluginOptions: Collection = listOf(EXAMPLE_OPTION, EXAMPLE_LEGACY_OPTION) override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) { when (option) { EXAMPLE_OPTION -> configuration.put(ExampleConfigurationKeys.EXAMPLE_KEY, value) + EXAMPLE_LEGACY_OPTION -> configuration.put(ExampleConfigurationKeys.EXAMPLE_LEGACY_KEY, value) else -> throw CliOptionProcessingException("Unknown option: ${option.name}") } } @@ -51,7 +54,9 @@ public class ExampleCommandLineProcessor : CommandLineProcessor { public class ExampleComponentRegistrar : ComponentRegistrar { public override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) { val exampleValue = configuration.get(ExampleConfigurationKeys.EXAMPLE_KEY) + val exampleLegacyValue = configuration.get(ExampleConfigurationKeys.EXAMPLE_LEGACY_KEY) val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) messageCollector.report(CompilerMessageSeverity.INFO, "Project component registration: $exampleValue") + messageCollector.report(CompilerMessageSeverity.INFO, "Project component registration: $exampleLegacyValue") } } diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleLegacySubplugin.kt b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleLegacySubplugin.kt new file mode 100644 index 00000000000..568d7e19475 --- /dev/null +++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleLegacySubplugin.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2015 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 example + +import org.gradle.api.Project +import org.gradle.api.tasks.compile.AbstractCompile +import org.jetbrains.kotlin.gradle.plugin.* + +class ExampleLegacySubplugin : KotlinGradleSubplugin { + + override fun isApplicable(project: Project, task: AbstractCompile): Boolean { + return true + } + + override fun apply( + project: Project, + kotlinCompile: AbstractCompile, + javaCompile: AbstractCompile?, + variantData: Any?, + androidProjectHandler: Any?, + kotlinCompilation: KotlinCompilation<*>? + ): List { + println("ExampleLegacySubplugin loaded") + return listOf( + SubpluginOption("exampleLegacyKey", "exampleLegacyValue") + ) + } + + override fun getCompilerPluginId(): String { + return "example.plugin" + } + + override fun getPluginArtifact(): SubpluginArtifact = + JetBrainsSubpluginArtifact("kotlin-gradle-subplugin-example") +} \ No newline at end of file diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt index f166c651fe3..15868caf6c7 100644 --- a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt +++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt @@ -16,26 +16,20 @@ package example -import org.gradle.api.Project -import org.gradle.api.tasks.compile.AbstractCompile +import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.plugin.* -class ExampleSubplugin : KotlinGradleSubplugin { +class ExampleSubplugin : KotlinCompilerPluginSupportPlugin { - override fun isApplicable(project: Project, task: AbstractCompile): Boolean { - return true - } + override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true - override fun apply( - project: Project, - kotlinCompile: AbstractCompile, - javaCompile: AbstractCompile?, - variantData: Any?, - androidProjectHandler: Any?, - kotlinCompilation: KotlinCompilation<*>? - ): List { + override fun applyToCompilation( + kotlinCompilation: KotlinCompilation<*> + ): Provider> { println("ExampleSubplugin loaded") - return listOf(SubpluginOption("exampleKey", "exampleValue")) + return kotlinCompilation.target.project.provider { + listOf(SubpluginOption("exampleKey", "exampleValue")) + } } override fun getCompilerPluginId(): String { diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/gradle-plugins/kotlin-example-subplugin.properties b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/gradle-plugins/kotlin-example-subplugin.properties new file mode 100644 index 00000000000..d04deab6d25 --- /dev/null +++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/gradle-plugins/kotlin-example-subplugin.properties @@ -0,0 +1 @@ +implementation-class=example.ExampleSubplugin \ No newline at end of file diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin index 68d0867ca30..db576b3adac 100644 --- a/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin +++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin @@ -1 +1,6 @@ -example.ExampleSubplugin \ No newline at end of file +# +# 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. +# + +example.ExampleLegacySubplugin \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SubpluginsIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SubpluginsIT.kt index bd625183ef6..c8e3b32dbc5 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SubpluginsIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SubpluginsIT.kt @@ -21,14 +21,18 @@ class SubpluginsIT : BaseGradleIT() { project.build("compileKotlin", "build") { assertSuccessful() assertContains("ExampleSubplugin loaded") + assertContains("ExampleLegacySubplugin loaded") assertContains("Project component registration: exampleValue") + assertContains("Project component registration: exampleLegacyValue") assertTasksExecuted(":compileKotlin") } project.build("compileKotlin", "build") { assertSuccessful() assertContains("ExampleSubplugin loaded") + assertContains("ExampleLegacySubplugin loaded") assertNotContains("Project component registration: exampleValue") + assertNotContains("Project component registration: exampleLegacyValue") assertTasksUpToDate(":compileKotlin") } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle index e37390d66ed..6fee132288e 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle @@ -10,6 +10,7 @@ buildscript { } apply plugin: "kotlin" +apply plugin: "kotlin-example-subplugin" repositories { mavenLocal()