Gradle: move buildCompilationProcessor from target preset to target configurator
This commit is contained in:
+16
-3
@@ -52,7 +52,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
|||||||
cleanTask.delete(kotlinCompilation.output.allOutputs)
|
cleanTask.delete(kotlinCompilation.output.allOutputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun configureCompilations(platformTarget: KotlinTargetType) {
|
protected open fun configureCompilations(platformTarget: KotlinTargetType) {
|
||||||
val project = platformTarget.project
|
val project = platformTarget.project
|
||||||
val main = platformTarget.compilations.create(KotlinCompilation.MAIN_COMPILATION_NAME)
|
val main = platformTarget.compilations.create(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||||
|
|
||||||
@@ -301,13 +301,26 @@ internal val KotlinCompilation<*>.deprecatedCompileConfigurationName: String
|
|||||||
internal val KotlinCompilationToRunnableFiles<*>.deprecatedRuntimeConfigurationName: String
|
internal val KotlinCompilationToRunnableFiles<*>.deprecatedRuntimeConfigurationName: String
|
||||||
get() = disambiguateName("runtime")
|
get() = disambiguateName("runtime")
|
||||||
|
|
||||||
open class KotlinTargetConfigurator<KotlinCompilationType : KotlinCompilation<*>>(
|
abstract class KotlinTargetConfigurator<KotlinCompilationType : KotlinCompilation<*>>(
|
||||||
createDefaultSourceSets: Boolean,
|
createDefaultSourceSets: Boolean,
|
||||||
createTestCompilation: Boolean
|
createTestCompilation: Boolean,
|
||||||
|
val kotlinPluginVersion: String
|
||||||
) : AbstractKotlinTargetConfigurator<KotlinOnlyTarget<KotlinCompilationType>>(
|
) : AbstractKotlinTargetConfigurator<KotlinOnlyTarget<KotlinCompilationType>>(
|
||||||
createDefaultSourceSets,
|
createDefaultSourceSets,
|
||||||
createTestCompilation
|
createTestCompilation
|
||||||
) {
|
) {
|
||||||
|
internal abstract fun buildCompilationProcessor(compilation: KotlinCompilationType): KotlinSourceSetProcessor<*>
|
||||||
|
|
||||||
|
override fun configureCompilations(platformTarget: KotlinOnlyTarget<KotlinCompilationType>) {
|
||||||
|
super.configureCompilations(platformTarget)
|
||||||
|
|
||||||
|
platformTarget.compilations.all { compilation ->
|
||||||
|
buildCompilationProcessor(compilation).run()
|
||||||
|
if (compilation.name == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
||||||
|
sourcesJarTask(compilation, platformTarget.targetName, platformTarget.targetName.toLowerCase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun configureArchivesAndComponent(target: KotlinOnlyTarget<KotlinCompilationType>) {
|
override fun configureArchivesAndComponent(target: KotlinOnlyTarget<KotlinCompilationType>) {
|
||||||
val project = target.project
|
val project = target.project
|
||||||
|
|||||||
+1
-10
@@ -13,8 +13,7 @@ abstract class KotlinOnlyTargetPreset<T : KotlinCompilation<*>>(
|
|||||||
protected val kotlinPluginVersion: String
|
protected val kotlinPluginVersion: String
|
||||||
) : KotlinTargetPreset<KotlinOnlyTarget<T>> {
|
) : KotlinTargetPreset<KotlinOnlyTarget<T>> {
|
||||||
|
|
||||||
protected open fun createKotlinTargetConfigurator(): KotlinTargetConfigurator<T> =
|
protected abstract fun createKotlinTargetConfigurator(): KotlinTargetConfigurator<T>
|
||||||
KotlinTargetConfigurator(createDefaultSourceSets = true, createTestCompilation = true)
|
|
||||||
|
|
||||||
protected open fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<T>): String? =
|
protected open fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget<T>): String? =
|
||||||
target.targetName
|
target.targetName
|
||||||
@@ -31,17 +30,9 @@ abstract class KotlinOnlyTargetPreset<T : KotlinCompilation<*>>(
|
|||||||
|
|
||||||
createKotlinTargetConfigurator().configureTarget(result)
|
createKotlinTargetConfigurator().configureTarget(result)
|
||||||
|
|
||||||
result.compilations.all { compilation ->
|
|
||||||
buildCompilationProcessor(compilation).run()
|
|
||||||
if (compilation.name == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
|
||||||
sourcesJarTask(compilation, result.targetName, result.targetName.toLowerCase())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun createCompilationFactory(forTarget: KotlinOnlyTarget<T>): KotlinCompilationFactory<T>
|
protected abstract fun createCompilationFactory(forTarget: KotlinOnlyTarget<T>): KotlinCompilationFactory<T>
|
||||||
protected abstract val platformType: KotlinPlatformType
|
protected abstract val platformType: KotlinPlatformType
|
||||||
internal abstract fun buildCompilationProcessor(compilation: T): KotlinSourceSetProcessor<*>
|
|
||||||
}
|
}
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.js
|
||||||
|
|
||||||
|
import org.gradle.api.plugins.JavaBasePlugin
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetConfigurator
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.tasks.KotlinJsNodeModulesTask
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.tasks.KotlinNodeJsTestRuntimeToNodeModulesTask
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.tasks.KotlinNodeJsTestTask
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
|
|
||||||
|
class KotlinJsTargetConfigurator(kotlinPluginVersion: String) :
|
||||||
|
KotlinTargetConfigurator<KotlinJsCompilation>(true, true, kotlinPluginVersion) {
|
||||||
|
|
||||||
|
override fun buildCompilationProcessor(compilation: KotlinJsCompilation): KotlinSourceSetProcessor<*> {
|
||||||
|
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
|
||||||
|
return Kotlin2JsSourceSetProcessor(compilation.target.project, tasksProvider, compilation, kotlinPluginVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun configureTest(target: KotlinOnlyTarget<KotlinJsCompilation>) {
|
||||||
|
target.compilations.all {
|
||||||
|
configureTest(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun configureTest(compilation: KotlinCompilationToRunnableFiles<*>) {
|
||||||
|
val target = compilation.target
|
||||||
|
val project = target.project
|
||||||
|
val name = compilation.name
|
||||||
|
val compileTestKotlin2Js = compilation.compileKotlinTask as Kotlin2JsCompile
|
||||||
|
val isDefaultTarget = compilation.name.isBlank()
|
||||||
|
|
||||||
|
fun camelCaseName(prefix: String): String {
|
||||||
|
return if (isDefaultTarget) prefix
|
||||||
|
else name + prefix.capitalize()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun underscoredName(prefix: String): String {
|
||||||
|
return if (isDefaultTarget) prefix
|
||||||
|
else "${name}_$prefix"
|
||||||
|
}
|
||||||
|
|
||||||
|
val nodeModulesDir = project.buildDir.resolve(underscoredName("node_modules"))
|
||||||
|
val nodeModulesTask = project.tasks.create(
|
||||||
|
camelCaseName("kotlinJsNodeModules"),
|
||||||
|
KotlinJsNodeModulesTask::class.java
|
||||||
|
) {
|
||||||
|
it.dependsOn(compileTestKotlin2Js)
|
||||||
|
|
||||||
|
it.nodeModulesDir = nodeModulesDir
|
||||||
|
it.compile = compileTestKotlin2Js
|
||||||
|
}
|
||||||
|
|
||||||
|
val nodeModulesTestRuntimeTask = project.tasks.create(
|
||||||
|
camelCaseName("kotlinJsNodeModulesTestRuntime"),
|
||||||
|
KotlinNodeJsTestRuntimeToNodeModulesTask::class.java
|
||||||
|
) {
|
||||||
|
it.nodeModulesDir = nodeModulesDir
|
||||||
|
}
|
||||||
|
|
||||||
|
val testJs: KotlinNodeJsTestTask =
|
||||||
|
if (isDefaultTarget) project.tasks.create("testJs", KotlinNodeJsTestTask::class.java)
|
||||||
|
else project.tasks.replace(camelCaseName("test"), KotlinNodeJsTestTask::class.java)
|
||||||
|
|
||||||
|
testJs.also {
|
||||||
|
it.group = "verification"
|
||||||
|
it.dependsOn(nodeModulesTask, nodeModulesTestRuntimeTask)
|
||||||
|
|
||||||
|
it.nodeModulesDir = nodeModulesDir
|
||||||
|
it.nodeModulesToLoad = setOf(compileTestKotlin2Js.outputFile.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
project.tasks.findByName(JavaBasePlugin.CHECK_TASK_NAME)?.dependsOn(testJs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-5
@@ -10,6 +10,8 @@ import org.gradle.api.Project
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsSourceSetProcessor
|
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsSourceSetProcessor
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetConfigurator
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
|
|
||||||
open class KotlinJsTargetPreset(
|
open class KotlinJsTargetPreset(
|
||||||
@@ -19,6 +21,8 @@ open class KotlinJsTargetPreset(
|
|||||||
project,
|
project,
|
||||||
kotlinPluginVersion
|
kotlinPluginVersion
|
||||||
) {
|
) {
|
||||||
|
override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator(kotlinPluginVersion)
|
||||||
|
|
||||||
override fun getName(): String = PRESET_NAME
|
override fun getName(): String = PRESET_NAME
|
||||||
|
|
||||||
override fun createCompilationFactory(forTarget: KotlinOnlyTarget<KotlinJsCompilation>) =
|
override fun createCompilationFactory(forTarget: KotlinOnlyTarget<KotlinJsCompilation>) =
|
||||||
@@ -27,11 +31,6 @@ open class KotlinJsTargetPreset(
|
|||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.js
|
get() = KotlinPlatformType.js
|
||||||
|
|
||||||
override fun buildCompilationProcessor(compilation: KotlinJsCompilation): KotlinSourceSetProcessor<*> {
|
|
||||||
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
|
|
||||||
return Kotlin2JsSourceSetProcessor(project, tasksProvider, compilation, kotlinPluginVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PRESET_NAME = "js"
|
const val PRESET_NAME = "js"
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.jvm
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JsSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetConfigurator
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
|
|
||||||
|
class KotlinJvmTargetConfigurator(kotlinPluginVersion: String) :
|
||||||
|
KotlinTargetConfigurator<KotlinJvmCompilation>(true, true, kotlinPluginVersion) {
|
||||||
|
|
||||||
|
override fun buildCompilationProcessor(compilation: KotlinJvmCompilation): KotlinSourceSetProcessor<*> {
|
||||||
|
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
|
||||||
|
return Kotlin2JvmSourceSetProcessor(compilation.target.project, tasksProvider, compilation, kotlinPluginVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-5
@@ -10,6 +10,8 @@ import org.gradle.api.Project
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor
|
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetConfigurator
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTargetConfigurator
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
|
|
||||||
class KotlinJvmTargetPreset(
|
class KotlinJvmTargetPreset(
|
||||||
@@ -24,14 +26,11 @@ class KotlinJvmTargetPreset(
|
|||||||
override fun createCompilationFactory(forTarget: KotlinOnlyTarget<KotlinJvmCompilation>): KotlinCompilationFactory<KotlinJvmCompilation> =
|
override fun createCompilationFactory(forTarget: KotlinOnlyTarget<KotlinJvmCompilation>): KotlinCompilationFactory<KotlinJvmCompilation> =
|
||||||
KotlinJvmCompilationFactory(forTarget)
|
KotlinJvmCompilationFactory(forTarget)
|
||||||
|
|
||||||
|
override fun createKotlinTargetConfigurator() = KotlinJvmTargetConfigurator(kotlinPluginVersion)
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.jvm
|
get() = KotlinPlatformType.jvm
|
||||||
|
|
||||||
override fun buildCompilationProcessor(compilation: KotlinJvmCompilation): KotlinSourceSetProcessor<*> {
|
|
||||||
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
|
|
||||||
return Kotlin2JvmSourceSetProcessor(project, tasksProvider, compilation, kotlinPluginVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PRESET_NAME = "jvm"
|
const val PRESET_NAME = "jvm"
|
||||||
}
|
}
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.metadata
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCommonSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetProcessor
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetConfigurator
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
|
|
||||||
|
class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||||
|
KotlinTargetConfigurator<KotlinCommonCompilation>(
|
||||||
|
createDefaultSourceSets = false,
|
||||||
|
createTestCompilation = false,
|
||||||
|
kotlinPluginVersion = kotlinPluginVersion
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun buildCompilationProcessor(compilation: KotlinCommonCompilation): KotlinSourceSetProcessor<*> {
|
||||||
|
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
|
||||||
|
return KotlinCommonSourceSetProcessor(compilation.target.project, compilation, tasksProvider, kotlinPluginVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-6
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.applyLanguageSettingsToKotlinTask
|
import org.jetbrains.kotlin.gradle.plugin.sources.applyLanguageSettingsToKotlinTask
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.metadata.KotlinMetadataTargetConfigurator
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||||
|
|
||||||
class KotlinMetadataTargetPreset(
|
class KotlinMetadataTargetPreset(
|
||||||
@@ -30,17 +31,12 @@ class KotlinMetadataTargetPreset(
|
|||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.common
|
get() = KotlinPlatformType.common
|
||||||
|
|
||||||
override fun buildCompilationProcessor(compilation: KotlinCommonCompilation): KotlinSourceSetProcessor<*> {
|
|
||||||
val tasksProvider = KotlinTasksProvider(compilation.target.targetName)
|
|
||||||
return KotlinCommonSourceSetProcessor(project, compilation, tasksProvider, kotlinPluginVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PRESET_NAME = "metadata"
|
const val PRESET_NAME = "metadata"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createKotlinTargetConfigurator(): KotlinTargetConfigurator<KotlinCommonCompilation> =
|
override fun createKotlinTargetConfigurator(): KotlinTargetConfigurator<KotlinCommonCompilation> =
|
||||||
KotlinTargetConfigurator(createDefaultSourceSets = false, createTestCompilation = false)
|
KotlinMetadataTargetConfigurator(kotlinPluginVersion)
|
||||||
|
|
||||||
override fun createTarget(name: String): KotlinOnlyTarget<KotlinCommonCompilation> =
|
override fun createTarget(name: String): KotlinOnlyTarget<KotlinCommonCompilation> =
|
||||||
super.createTarget(name).apply {
|
super.createTarget(name).apply {
|
||||||
|
|||||||
Reference in New Issue
Block a user