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