|
1 | 1 | package me.shika
|
2 | 2 |
|
3 |
| -import org.gradle.api.Plugin |
4 | 3 | import org.gradle.api.Project
|
| 4 | +import org.gradle.api.internal.provider.DefaultListProperty |
| 5 | +import org.gradle.api.provider.Provider |
| 6 | +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation |
| 7 | +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin |
| 8 | +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
| 9 | +import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact |
| 10 | +import org.jetbrains.kotlin.gradle.plugin.SubpluginOption |
5 | 11 |
|
6 |
| -class ObjectSerializationPlugin : Plugin<Project> { |
7 |
| - override fun apply(project: Project) { |
8 |
| - project.extensions.create( |
| 12 | +class ObjectSerializationPlugin : KotlinCompilerPluginSupportPlugin { |
| 13 | + override fun apply(target: Project) { |
| 14 | + target.extensions.create( |
9 | 15 | "objectSerialization",
|
10 | 16 | ObjectSerializationExtension::class.java
|
11 | 17 | )
|
12 | 18 | }
|
| 19 | + |
| 20 | + override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> { |
| 21 | + val project = kotlinCompilation.target.project |
| 22 | + val extension = project.extensions.findByType(ObjectSerializationExtension::class.java) ?: ObjectSerializationExtension() |
| 23 | + |
| 24 | + return DefaultListProperty(SubpluginOption::class.java).apply { |
| 25 | + add( |
| 26 | + SubpluginOption( |
| 27 | + key = "enabled", |
| 28 | + value = extension.enabled.toString() |
| 29 | + ) |
| 30 | + ) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + override fun getCompilerPluginId(): String = "object-serialization-fix" |
| 35 | + |
| 36 | + override fun getPluginArtifact(): SubpluginArtifact = |
| 37 | + SubpluginArtifact( |
| 38 | + groupId = "me.shika", |
| 39 | + artifactId = "kotlin-object-java-serialization", |
| 40 | + version = "1.2.0" |
| 41 | + ) |
| 42 | + |
| 43 | + override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = |
| 44 | + kotlinCompilation.platformType in setOf( |
| 45 | + KotlinPlatformType.jvm, |
| 46 | + KotlinPlatformType.androidJvm, |
| 47 | + KotlinPlatformType.common |
| 48 | + ) |
13 | 49 | }
|
14 | 50 |
|
15 | 51 | open class ObjectSerializationExtension {
|
|
0 commit comments