Rework SamWithReceiverSubplugin for the new subplugins API
This commit is contained in:
+20
-29
@@ -16,26 +16,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.samWithReceiver.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.noarg.gradle.model.builder.SamWithReceiverModelBuilder
|
||||
import javax.inject.Inject
|
||||
|
||||
class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin<Project> {
|
||||
companion object {
|
||||
fun isEnabled(project: Project) = project.plugins.findPlugin(SamWithReceiverGradleSubplugin::class.java) != null
|
||||
}
|
||||
|
||||
class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : KotlinCompilerPluginSupportPlugin {
|
||||
override fun apply(project: Project) {
|
||||
project.extensions.create("samWithReceiver", SamWithReceiverExtension::class.java)
|
||||
registry.register(SamWithReceiverModelBuilder())
|
||||
}
|
||||
}
|
||||
|
||||
class SamWithReceiverKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
|
||||
companion object {
|
||||
const val SAM_WITH_RECEIVER_ARTIFACT_NAME = "kotlin-sam-with-receiver"
|
||||
|
||||
@@ -43,31 +36,29 @@ class SamWithReceiverKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompi
|
||||
private val PRESET_ARG_NAME = "preset"
|
||||
}
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile) = SamWithReceiverGradleSubplugin.isEnabled(project)
|
||||
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true
|
||||
|
||||
override fun apply(
|
||||
project: Project,
|
||||
kotlinCompile: AbstractCompile,
|
||||
javaCompile: AbstractCompile?,
|
||||
variantData: Any?,
|
||||
androidProjectHandler: Any?,
|
||||
kotlinCompilation: KotlinCompilation<*>?
|
||||
): List<SubpluginOption> {
|
||||
if (!SamWithReceiverGradleSubplugin.isEnabled(project)) return emptyList()
|
||||
override fun applyToCompilation(
|
||||
kotlinCompilation: KotlinCompilation<*>
|
||||
): Provider<List<SubpluginOption>> {
|
||||
val project = kotlinCompilation.target.project
|
||||
|
||||
val samWithReceiverExtension = project.extensions.findByType(SamWithReceiverExtension::class.java) ?: return emptyList()
|
||||
val samWithReceiverExtension =
|
||||
project.extensions.findByType(SamWithReceiverExtension::class.java) ?: return project.provider { emptyList<SubpluginOption>() }
|
||||
|
||||
val options = mutableListOf<SubpluginOption>()
|
||||
return project.provider<List<SubpluginOption>> {
|
||||
val options = mutableListOf<SubpluginOption>()
|
||||
|
||||
for (anno in samWithReceiverExtension.myAnnotations) {
|
||||
options += SubpluginOption(ANNOTATION_ARG_NAME, anno)
|
||||
for (anno in samWithReceiverExtension.myAnnotations) {
|
||||
options += SubpluginOption(ANNOTATION_ARG_NAME, anno)
|
||||
}
|
||||
|
||||
for (preset in samWithReceiverExtension.myPresets) {
|
||||
options += SubpluginOption(PRESET_ARG_NAME, preset)
|
||||
}
|
||||
|
||||
options
|
||||
}
|
||||
|
||||
for (preset in samWithReceiverExtension.myPresets) {
|
||||
options += SubpluginOption(PRESET_ARG_NAME, preset)
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlin.samWithReceiver"
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverKotlinGradleSubplugin
|
||||
Reference in New Issue
Block a user