Remove deprecated ConfigureUtil usages in Kotlin target containers
^KT-46019 In Progress
This commit is contained in:
+11
-9
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.dsl
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.gradle.api.Action
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension.Companion.reportJsCompilerMode
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.calculateJsCompilerType
|
||||
@@ -48,30 +47,33 @@ interface KotlinTargetContainerWithJsPresetFunctions :
|
||||
|
||||
fun js() = jsInternal(name = "js") { }
|
||||
fun js(name: String) = jsInternal(name = name) { }
|
||||
fun js(name: String, configure: Closure<*>) = jsInternal(name = name) { ConfigureUtil.configure(configure, this) }
|
||||
fun js(compiler: KotlinJsCompilerType, configure: Closure<*>) = js(compiler = compiler) { ConfigureUtil.configure(configure, this) }
|
||||
fun js(configure: Closure<*>) = jsInternal { ConfigureUtil.configure(configure, this) }
|
||||
fun js(name: String, configure: Action<KotlinJsTargetDsl>) = jsInternal(name = name) { configure.execute(this) }
|
||||
fun js(compiler: KotlinJsCompilerType, configure: Action<KotlinJsTargetDsl>) = js(compiler = compiler) {
|
||||
configure.execute(this)
|
||||
}
|
||||
|
||||
fun js(configure: Action<KotlinJsTargetDsl>) = jsInternal { configure.execute(this) }
|
||||
|
||||
fun js(
|
||||
name: String,
|
||||
compiler: KotlinJsCompilerType,
|
||||
configure: Closure<*>
|
||||
configure: Action<KotlinJsTargetDsl>
|
||||
) = js(
|
||||
name = name,
|
||||
compiler = compiler
|
||||
) {
|
||||
ConfigureUtil.configure(configure, this)
|
||||
configure.execute(this)
|
||||
}
|
||||
|
||||
fun js(
|
||||
name: String,
|
||||
compiler: String,
|
||||
configure: Closure<*>
|
||||
configure: Action<KotlinJsTargetDsl>
|
||||
) = js(
|
||||
name = name,
|
||||
compiler = compiler
|
||||
) {
|
||||
ConfigureUtil.configure(configure, this)
|
||||
configure.execute(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-8
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.dsl
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.gradle.api.Action
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
@@ -68,8 +67,8 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
|
||||
fun ios() = ios("ios") { }
|
||||
fun ios(namePrefix: String) = ios(namePrefix) { }
|
||||
fun ios(namePrefix: String, configure: Closure<*>) = ios(namePrefix) { ConfigureUtil.configure(configure, this) }
|
||||
fun ios(configure: Closure<*>) = ios { ConfigureUtil.configure(configure, this) }
|
||||
fun ios(namePrefix: String, configure: Action<KotlinNativeTarget>) = ios(namePrefix) { configure.execute(this) }
|
||||
fun ios(configure: Action<KotlinNativeTarget>) = ios { configure.execute(this) }
|
||||
|
||||
fun tvos(
|
||||
namePrefix: String = "tvos",
|
||||
@@ -85,8 +84,8 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
|
||||
fun tvos() = tvos("tvos") { }
|
||||
fun tvos(namePrefix: String) = tvos(namePrefix) { }
|
||||
fun tvos(namePrefix: String, configure: Closure<*>) = tvos(namePrefix) { ConfigureUtil.configure(configure, this) }
|
||||
fun tvos(configure: Closure<*>) = tvos { ConfigureUtil.configure(configure, this) }
|
||||
fun tvos(namePrefix: String, configure: Action<KotlinNativeTarget>) = tvos(namePrefix) { configure.execute(this) }
|
||||
fun tvos(configure: Action<KotlinNativeTarget>) = tvos { configure.execute(this) }
|
||||
|
||||
fun watchos(
|
||||
namePrefix: String = "watchos",
|
||||
@@ -113,6 +112,6 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
|
||||
fun watchos() = watchos("watchos") { }
|
||||
fun watchos(namePrefix: String) = watchos(namePrefix) { }
|
||||
fun watchos(namePrefix: String, configure: Closure<*>) = watchos(namePrefix) { ConfigureUtil.configure(configure, this) }
|
||||
fun watchos(configure: Closure<*>) = watchos { ConfigureUtil.configure(configure, this) }
|
||||
fun watchos(namePrefix: String, configure: Action<KotlinNativeTarget>) = watchos(namePrefix) { configure.execute(this) }
|
||||
fun watchos(configure: Action<KotlinNativeTarget>) = watchos { configure.execute(this) }
|
||||
}
|
||||
|
||||
+3
-4
@@ -5,8 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.dsl
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.gradle.api.Action
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
|
||||
@@ -31,8 +30,8 @@ interface KotlinTargetContainerWithWasmPresetFunctions : KotlinTargetContainerWi
|
||||
fun wasm(name: String) = wasm(name) { }
|
||||
|
||||
@ExperimentalWasmDsl
|
||||
fun wasm(name: String, configure: Closure<*>) = wasm(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun wasm(name: String, configure: Action<KotlinWasmTargetDsl>) = wasm(name) { configure.execute(this) }
|
||||
|
||||
@ExperimentalWasmDsl
|
||||
fun wasm(configure: Closure<*>) = wasm { ConfigureUtil.configure(configure, this) }
|
||||
fun wasm(configure: Action<KotlinWasmTargetDsl>) = wasm { configure.execute(this) }
|
||||
}
|
||||
+26
-11
@@ -604,13 +604,15 @@ internal open class KotlinPlugin(
|
||||
Kotlin2JvmSourceSetProcessor(tasksProvider, compilation)
|
||||
|
||||
override fun apply(project: Project) {
|
||||
val target =
|
||||
KotlinWithJavaTarget<KotlinJvmOptions>(
|
||||
project,
|
||||
KotlinPlatformType.jvm,
|
||||
targetName,
|
||||
{ KotlinJvmOptionsImpl() }
|
||||
).apply {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val target = (project.objects.newInstance(
|
||||
KotlinWithJavaTarget::class.java,
|
||||
project,
|
||||
KotlinPlatformType.jvm,
|
||||
targetName,
|
||||
{ KotlinJvmOptionsImpl() }
|
||||
) as KotlinWithJavaTarget<KotlinJvmOptions>)
|
||||
.apply {
|
||||
disambiguationClassifier = null // don't add anything to the task names
|
||||
}
|
||||
|
||||
@@ -644,12 +646,14 @@ internal open class KotlinCommonPlugin(
|
||||
KotlinCommonSourceSetProcessor(compilation, tasksProvider)
|
||||
|
||||
override fun apply(project: Project) {
|
||||
val target = KotlinWithJavaTarget<KotlinMultiplatformCommonOptions>(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val target = project.objects.newInstance(
|
||||
KotlinWithJavaTarget::class.java,
|
||||
project,
|
||||
KotlinPlatformType.common,
|
||||
targetName,
|
||||
{ KotlinMultiplatformCommonOptionsImpl() }
|
||||
)
|
||||
) as KotlinWithJavaTarget<KotlinMultiplatformCommonOptions>
|
||||
(project.kotlinExtension as KotlinCommonProjectExtension).target = target
|
||||
|
||||
super.apply(project)
|
||||
@@ -675,7 +679,14 @@ internal open class Kotlin2JsPlugin(
|
||||
Kotlin2JsSourceSetProcessor(tasksProvider, compilation)
|
||||
|
||||
override fun apply(project: Project) {
|
||||
val target = KotlinWithJavaTarget<KotlinJsOptions>(project, KotlinPlatformType.js, targetName, { KotlinJsOptionsImpl() })
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val target = project.objects.newInstance(
|
||||
KotlinWithJavaTarget::class.java,
|
||||
project,
|
||||
KotlinPlatformType.js,
|
||||
targetName,
|
||||
{ KotlinJsOptionsImpl() }
|
||||
) as KotlinWithJavaTarget<KotlinJsOptions>
|
||||
|
||||
(project.kotlinExtension as Kotlin2JsProjectExtension).setTarget(target)
|
||||
super.apply(project)
|
||||
@@ -691,7 +702,11 @@ internal open class KotlinAndroidPlugin(
|
||||
|
||||
project.dynamicallyApplyWhenAndroidPluginIsApplied(
|
||||
{
|
||||
KotlinAndroidTarget("", project).also {
|
||||
project.objects.newInstance(
|
||||
KotlinAndroidTarget::class.java,
|
||||
"",
|
||||
project
|
||||
).also {
|
||||
(project.kotlinExtension as KotlinAndroidProjectExtension).target = it
|
||||
}
|
||||
}
|
||||
|
||||
+3
-6
@@ -6,17 +6,14 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ConfigurablePublishArtifact
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.KotlinMetadataTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.isCompatibilityMetadataVariantEnabled
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinMetadataTarget @Inject constructor(project: Project) :
|
||||
KotlinOnlyTarget<AbstractKotlinCompilation<*>>(project, KotlinPlatformType.common) {
|
||||
abstract class KotlinMetadataTarget @Inject constructor(
|
||||
project: Project
|
||||
) : KotlinOnlyTarget<AbstractKotlinCompilation<*>>(project, KotlinPlatformType.common) {
|
||||
|
||||
override val artifactsTaskName: String
|
||||
// The IDE import looks at this task name to determine the artifact and register the path to the artifact;
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
|
||||
}
|
||||
)
|
||||
add(KotlinWasmTargetPreset(project))
|
||||
add(KotlinAndroidTargetPreset(project))
|
||||
add(project.objects.newInstance(KotlinAndroidTargetPreset::class.java, project))
|
||||
add(KotlinJvmWithJavaTargetPreset(project))
|
||||
|
||||
// Note: modifying these sets should also be reflected in the DSL code generator, see 'presetEntries.kt'
|
||||
|
||||
+2
-1
@@ -17,8 +17,9 @@ import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.utils.dashSeparatedName
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.gradle.utils.setProperty
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinAndroidTarget(
|
||||
abstract class KotlinAndroidTarget @Inject constructor(
|
||||
override val targetName: String,
|
||||
project: Project
|
||||
) : AbstractKotlinTarget(project) {
|
||||
|
||||
+7
-2
@@ -12,15 +12,20 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.PublicationRegistrationMode
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.hasKpmModel
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.mapTargetCompilationsToKpmVariants
|
||||
import javax.inject.Inject
|
||||
|
||||
class KotlinAndroidTargetPreset(
|
||||
abstract class KotlinAndroidTargetPreset @Inject constructor(
|
||||
private val project: Project
|
||||
) : KotlinTargetPreset<KotlinAndroidTarget> {
|
||||
|
||||
override fun getName(): String = PRESET_NAME
|
||||
|
||||
override fun createTarget(name: String): KotlinAndroidTarget {
|
||||
val result = KotlinAndroidTarget(name, project).apply {
|
||||
val result = project.objects.newInstance(
|
||||
KotlinAndroidTarget::class.java,
|
||||
name,
|
||||
project
|
||||
).apply {
|
||||
disambiguationClassifier = name
|
||||
preset = this@KotlinAndroidTargetPreset
|
||||
targetUnderConstruction = this
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import java.util.concurrent.Callable
|
||||
import javax.inject.Inject
|
||||
import kotlin.reflect.full.functions
|
||||
|
||||
open class KotlinJvmTarget @Inject constructor(
|
||||
abstract class KotlinJvmTarget @Inject constructor(
|
||||
project: Project
|
||||
) : KotlinOnlyTarget<KotlinJvmCompilation>(project, KotlinPlatformType.jvm),
|
||||
KotlinTargetWithTests<JvmClasspathTestRunSource, KotlinJvmTestRun> {
|
||||
|
||||
+12
-4
@@ -29,10 +29,18 @@ class KotlinJvmWithJavaTargetPreset(
|
||||
|
||||
project.plugins.apply(JavaPlugin::class.java)
|
||||
|
||||
val target = KotlinWithJavaTarget<KotlinJvmOptions>(project, KotlinPlatformType.jvm, name, { KotlinJvmOptionsImpl() }).apply {
|
||||
disambiguationClassifier = name
|
||||
preset = this@KotlinJvmWithJavaTargetPreset
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val target = (project.objects.newInstance(
|
||||
KotlinWithJavaTarget::class.java,
|
||||
project,
|
||||
KotlinPlatformType.jvm,
|
||||
name,
|
||||
{ KotlinJvmOptionsImpl() }
|
||||
) as KotlinWithJavaTarget<KotlinJvmOptions>)
|
||||
.apply {
|
||||
disambiguationClassifier = name
|
||||
preset = this@KotlinJvmWithJavaTargetPreset
|
||||
}
|
||||
|
||||
AbstractKotlinPlugin.configureTarget(target) { compilation ->
|
||||
Kotlin2JvmSourceSetProcessor(KotlinTasksProvider(), compilation)
|
||||
|
||||
+2
-1
@@ -17,8 +17,9 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_BUILD_DIR_NAME
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinWithJavaTarget<KotlinOptionsType : KotlinCommonOptions>(
|
||||
abstract class KotlinWithJavaTarget<KotlinOptionsType : KotlinCommonOptions> @Inject constructor(
|
||||
project: Project,
|
||||
override val platformType: KotlinPlatformType,
|
||||
override val targetName: String,
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinNativeTarget @Inject constructor(
|
||||
abstract class KotlinNativeTarget @Inject constructor(
|
||||
project: Project,
|
||||
val konanTarget: KonanTarget
|
||||
) : KotlinTargetWithBinaries<KotlinNativeCompilation, KotlinNativeBinaryContainer>(
|
||||
@@ -202,8 +202,8 @@ abstract class KotlinNativeTargetWithTests<T : KotlinNativeBinaryTestRun>(
|
||||
internal set
|
||||
}
|
||||
|
||||
open class KotlinNativeTargetWithHostTests @Inject constructor(project: Project, konanTarget: KonanTarget) :
|
||||
abstract class KotlinNativeTargetWithHostTests @Inject constructor(project: Project, konanTarget: KonanTarget) :
|
||||
KotlinNativeTargetWithTests<KotlinNativeHostTestRun>(project, konanTarget)
|
||||
|
||||
open class KotlinNativeTargetWithSimulatorTests @Inject constructor(project: Project, konanTarget: KonanTarget) :
|
||||
abstract class KotlinNativeTargetWithSimulatorTests @Inject constructor(project: Project, konanTarget: KonanTarget) :
|
||||
KotlinNativeTargetWithTests<KotlinNativeSimulatorTestRun>(project, konanTarget)
|
||||
|
||||
+6
-6
@@ -57,13 +57,13 @@ class BuildKotlinToolingMetadataTest : AbstractKpmExtensionTest() {
|
||||
assertEquals(3, metadata.projectTargets.size, "Expected 3 targets in KPM")
|
||||
|
||||
val jvmTarget = metadata.projectTargets.single { it.platformType == jvm.name }
|
||||
assertEquals(GradleKpmJvmVariant::class.java.canonicalName, jvmTarget.target)
|
||||
assertEquals(GradleKpmJvmVariant::class.decoratedClassCanonicalName, jvmTarget.target)
|
||||
|
||||
val nativeTargets = metadata.projectTargets.filter { it.platformType == native.name }.map { it.target }.toSet()
|
||||
assertEquals(
|
||||
setOf(
|
||||
GradleKpmLinuxArm64Variant::class.java.canonicalName,
|
||||
GradleKpmLinuxX64Variant::class.java.canonicalName
|
||||
GradleKpmLinuxArm64Variant::class.decoratedClassCanonicalName,
|
||||
GradleKpmLinuxX64Variant::class.decoratedClassCanonicalName,
|
||||
),
|
||||
nativeTargets
|
||||
)
|
||||
@@ -134,7 +134,7 @@ class KotlinToolingMetadataWithModelMappingTest {
|
||||
|
||||
expectedTargets.forEach { (platformType, targetClass) ->
|
||||
assertEquals(
|
||||
targetClass.java.canonicalName,
|
||||
targetClass.decoratedClassCanonicalName,
|
||||
metadata.projectTargets.single { it.platformType == platformType.name }.target,
|
||||
"Platform '$platformType' has different target class"
|
||||
)
|
||||
@@ -212,11 +212,11 @@ class KotlinToolingMetadataWithModelMappingTest {
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
GradleKpmLinuxArm64Variant::class.java.canonicalName,
|
||||
GradleKpmLinuxArm64Variant::class.decoratedClassCanonicalName,
|
||||
linuxArm64.target
|
||||
)
|
||||
assertEquals(
|
||||
GradleKpmLinuxX64Variant::class.java.canonicalName,
|
||||
GradleKpmLinuxX64Variant::class.decoratedClassCanonicalName,
|
||||
linuxX64.target
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class KotlinNativeVariantFactoryTest(
|
||||
|
||||
@Test
|
||||
fun `test variantClass`() {
|
||||
assertEquals(variantConstructor.variantClass, variant.javaClass)
|
||||
assertEquals(variantConstructor.variantClass.decoratedClassCanonicalName, variant.javaClass.canonicalName)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.kpm
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.GradleKpmFragment
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
internal val <T : GradleKpmFragment> KClass<T>.decoratedClassCanonicalName: String get() = java.decoratedClassCanonicalName
|
||||
|
||||
internal val <T : GradleKpmFragment> Class<T>.decoratedClassCanonicalName: String get() = "${canonicalName}_Decorated"
|
||||
Reference in New Issue
Block a user