Refactor KotlinMultiplatformPlugin to allow Native extend it
This commit is contained in:
+28
-17
@@ -27,7 +27,14 @@ import org.gradle.api.tasks.SourceSetContainer
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||||
|
|
||||||
abstract class KotlinPlatformPluginBase(protected val platformName: String) : Plugin<Project>
|
abstract class KotlinPlatformPluginBase(protected val platformName: String) : Plugin<Project> {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
protected inline fun <reified T : Plugin<*>> Project.applyPlugin() {
|
||||||
|
pluginManager.apply(T::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
@@ -97,14 +104,31 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
|||||||
|
|
||||||
commonProject.sourceSets.all { commonSourceSet ->
|
commonProject.sourceSets.all { commonSourceSet ->
|
||||||
// todo: warn if not found
|
// todo: warn if not found
|
||||||
val platformTask = platformKotlinTasksBySourceSetName[commonSourceSet.name]
|
addCommonSourceSetToPlatformSourceSet(commonSourceSet)
|
||||||
commonSourceSet.kotlin!!.srcDirs.forEach { platformTask?.source(it) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val SourceSet.kotlin: SourceDirectorySet?
|
protected fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: SourceSet) {
|
||||||
|
val platformTask = platformKotlinTasksBySourceSetName[commonSourceSet.name]
|
||||||
|
commonSourceSet.kotlin!!.srcDirs.forEach { platformTask?.source(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected val SourceSet.kotlin: SourceDirectorySet?
|
||||||
get() = ((getConvention("kotlin") ?: getConvention("kotlin2js")) as? KotlinSourceSet)?.kotlin
|
get() = ((getConvention("kotlin") ?: getConvention("kotlin2js")) as? KotlinSourceSet)?.kotlin
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
protected fun <T> Project.whenEvaluated(fn: Project.() -> T) {
|
||||||
|
if (state.executed) {
|
||||||
|
fn()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
afterEvaluate { it.fn() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KotlinPlatformJvmPlugin : KotlinPlatformImplementationPluginBase("jvm") {
|
open class KotlinPlatformJvmPlugin : KotlinPlatformImplementationPluginBase("jvm") {
|
||||||
@@ -123,16 +147,3 @@ open class KotlinPlatformJsPlugin : KotlinPlatformImplementationPluginBase("js")
|
|||||||
|
|
||||||
private val Project.sourceSets: SourceSetContainer
|
private val Project.sourceSets: SourceSetContainer
|
||||||
get() = convention.getPlugin(JavaPluginConvention::class.java).sourceSets
|
get() = convention.getPlugin(JavaPluginConvention::class.java).sourceSets
|
||||||
|
|
||||||
private fun <T> Project.whenEvaluated(fn: Project.()->T) {
|
|
||||||
if (state.executed) {
|
|
||||||
fn()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
afterEvaluate { it.fn() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun <reified T : Plugin<*>> Project.applyPlugin() {
|
|
||||||
pluginManager.apply(T::class.java)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user