From 772bcb283d10cba7029753e51735379b08f0f5c9 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Thu, 22 Jun 2023 09:39:51 +0200 Subject: [PATCH] [Gradle] Replace KotlinSourceSetTree interface with simpler class ^KT-58676 Verification Pending --- .../api/kotlin-gradle-plugin-api.api | 16 ++-- .../gradle/plugin/KotlinSourceSetTree.kt | 91 +++++++------------ .../gradle/plugin/KotlinTargetHierarchy.kt | 2 +- .../KotlinSourceSetTreeClassifier.kt | 2 +- .../SourceSetTreeClassifier.kt | 4 +- .../targets/android/KotlinAndroidTarget.kt | 1 - .../android/KotlinAndroidTargetVariantDsl.kt | 3 +- 7 files changed, 46 insertions(+), 73 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api b/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api index d86a33426f3..8a16564a925 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api +++ b/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api @@ -1094,9 +1094,13 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinSourceS public abstract fun getSourceSets ()Lorg/gradle/api/NamedDomainObjectContainer; } -public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree { +public final class org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree { public static final field Companion Lorg/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree$Companion; - public abstract fun getName ()Ljava/lang/String; + public fun (Ljava/lang/String;)V + public fun equals (Ljava/lang/Object;)Z + public final fun getName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; } public final class org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree$Companion { @@ -1107,10 +1111,6 @@ public final class org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree$Compan public final fun getUnitTest ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree; } -public final class org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTreeKt { - public static final fun KotlinSourceSetTree (Ljava/lang/String;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree; -} - public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinTarget : org/gradle/api/Named, org/gradle/api/attributes/HasAttributes, org/jetbrains/kotlin/gradle/plugin/HasProject, org/jetbrains/kotlin/tooling/core/HasMutableExtras { public abstract fun attributes (Lkotlin/jvm/functions/Function1;)V public abstract fun attributes (Lorg/gradle/api/Action;)V @@ -1157,11 +1157,11 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinTargetE public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy { } -public final class org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy$SourceSetTree : org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree { +public final class org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy$SourceSetTree { public static final field Companion Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy$SourceSetTree$Companion; public fun (Ljava/lang/String;)V public fun equals (Ljava/lang/Object;)Z - public fun getName ()Ljava/lang/String; + public final fun getName ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree.kt index 387ed8a7915..b933e0bcda7 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree.kt @@ -5,12 +5,6 @@ package org.jetbrains.kotlin.gradle.plugin -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree.Companion.instrumentedTest -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree.Companion.integrationTest -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree.Companion.main -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree.Companion.test -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree.Companion.unitTest - /** * When applying any [KotlinHierarchyTemplate] (e.g. by calling `applyDefaultHierarchyTemplate()`), the descriptor will * be applied on individual compilations, creating multiple trees of shared SourceSets. @@ -60,59 +54,8 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree.Companion.unitTest * There are some exceptions, where the name of the compilations cannot be chosen by the user directly (Android) * In this case, the name of the SourceSet can be configured outside the target hierarchy DSL. */ -sealed interface KotlinSourceSetTree { - val name: String +class KotlinSourceSetTree(val name: String) { - companion object { - /** - * The 'main' SourceSetTree. Typically, with 'commonMain' as the root SourceSet - */ - val main: KotlinSourceSetTree = KotlinSourceSetTreeImpl("main") - - /** - * The 'test' SourceSetTree. Typically, with 'commonTest' as the root SourceSet - */ - val test: KotlinSourceSetTree = KotlinSourceSetTreeImpl("test") - - /** - * Special pre-defined SourceSetTree: Can be used to introduce a new tree with 'commonUnitTest' as the root SourceSet - * e.g. relevant for organising Android unitTest compilations/SourceSets - */ - val unitTest: KotlinSourceSetTree = KotlinSourceSetTreeImpl("unitTest") - - - /** - * Special pre-defined SourceSetTree: Can be used to introduce a new tree with 'commonInstrumentedTest' as the root SourceSet - * e.g. relevant for organising Android instrumented compilations/SourceSets - */ - val instrumentedTest: KotlinSourceSetTree = KotlinSourceSetTreeImpl("instrumentedTest") - - - /** - * Special pre-defined SourceSetTree: Can be used to introduce a new tree with 'commonIntegrationTest' as root SourceSEt - */ - val integrationTest: KotlinSourceSetTree = KotlinSourceSetTreeImpl("integrationTest") - - } -} - -fun KotlinSourceSetTree(name: String): KotlinSourceSetTree { - return when (name) { - main.name -> main - test.name -> test - unitTest.name -> unitTest - instrumentedTest.name -> instrumentedTest - integrationTest.name -> integrationTest - else -> KotlinSourceSetTreeImpl(name) - } -} - -/* -Implementation - */ - - -private class KotlinSourceSetTreeImpl(override val name: String) : KotlinSourceSetTree { override fun toString(): String = name override fun equals(other: Any?): Boolean { @@ -123,4 +66,36 @@ private class KotlinSourceSetTreeImpl(override val name: String) : KotlinSourceS override fun hashCode(): Int { return name.hashCode() } + + companion object { + /** + * The 'main' SourceSetTree. Typically, with 'commonMain' as the root SourceSet + */ + val main: KotlinSourceSetTree = KotlinSourceSetTree("main") + + /** + * The 'test' SourceSetTree. Typically, with 'commonTest' as the root SourceSet + */ + val test: KotlinSourceSetTree = KotlinSourceSetTree("test") + + /** + * Special pre-defined SourceSetTree: Can be used to introduce a new tree with 'commonUnitTest' as the root SourceSet + * e.g. relevant for organising Android unitTest compilations/SourceSets + */ + val unitTest: KotlinSourceSetTree = KotlinSourceSetTree("unitTest") + + + /** + * Special pre-defined SourceSetTree: Can be used to introduce a new tree with 'commonInstrumentedTest' as the root SourceSet + * e.g. relevant for organising Android instrumented compilations/SourceSets + */ + val instrumentedTest: KotlinSourceSetTree = KotlinSourceSetTree("instrumentedTest") + + + /** + * Special pre-defined SourceSetTree: Can be used to introduce a new tree with 'commonIntegrationTest' as root SourceSEt + */ + val integrationTest: KotlinSourceSetTree = KotlinSourceSetTree("integrationTest") + + } } diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy.kt index ff3ddd177b3..be992b927bf 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetHierarchy.kt @@ -9,7 +9,7 @@ package org.jetbrains.kotlin.gradle.plugin interface KotlinTargetHierarchy { @Deprecated("Use KotlinSourceSetTree instead", replaceWith = ReplaceWith("KotlinSourceSetTree")) - class SourceSetTree(override val name: String) : KotlinSourceSetTree { + class SourceSetTree(val name: String) { override fun toString(): String = name override fun equals(other: Any?): Boolean { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/hierarchy/KotlinSourceSetTreeClassifier.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/hierarchy/KotlinSourceSetTreeClassifier.kt index dcfeac6fed7..4207a868180 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/hierarchy/KotlinSourceSetTreeClassifier.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/hierarchy/KotlinSourceSetTreeClassifier.kt @@ -106,7 +106,7 @@ internal suspend fun KotlinSourceSetTreeClassifier.classify(compilation: KotlinC is KotlinSourceSetTreeClassifier.Value -> tree is KotlinSourceSetTreeClassifier.Name -> KotlinSourceSetTree(name) is KotlinSourceSetTreeClassifier.None -> null - is SourceSetTreeClassifierWrapper -> classifier.classify(compilation) + is SourceSetTreeClassifierWrapper -> classifier.classify(compilation)?.name?.let(::KotlinSourceSetTree) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/targetHierarchy/SourceSetTreeClassifier.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/targetHierarchy/SourceSetTreeClassifier.kt index 1030d007095..29b19e65501 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/targetHierarchy/SourceSetTreeClassifier.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/targetHierarchy/SourceSetTreeClassifier.kt @@ -41,13 +41,13 @@ sealed class SourceSetTreeClassifier { @ExternalKotlinTargetApi - class Property(val property: org.gradle.api.provider.Property) : SourceSetTreeClassifier() { + class Property(val property: org.gradle.api.provider.Property) : SourceSetTreeClassifier() { override fun toString(): String { return property.toString() } } - internal suspend fun classify(compilation: KotlinCompilation<*>): KotlinSourceSetTree? { + internal suspend fun classify(compilation: KotlinCompilation<*>): SourceSetTree? { return when (this) { is Default -> SourceSetTree(compilation.name) is Property -> property.awaitFinalValue() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTarget.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTarget.kt index 71bb93a1af1..b35d32111e1 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTarget.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTarget.kt @@ -13,7 +13,6 @@ import org.gradle.api.attributes.Attribute import org.gradle.api.attributes.AttributeContainer import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetHierarchy.SourceSetTree import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.copyAttributes import org.jetbrains.kotlin.gradle.utils.dashSeparatedName import org.jetbrains.kotlin.gradle.utils.forAllAndroidVariants diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTargetVariantDsl.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTargetVariantDsl.kt index 8c783c00d2a..d1b9ebc9bba 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTargetVariantDsl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/android/KotlinAndroidTargetVariantDsl.kt @@ -10,14 +10,13 @@ import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetHierarchy.SourceSetTree import org.jetbrains.kotlin.gradle.utils.property @ExperimentalKotlinGradlePluginApi interface KotlinAndroidTargetVariantDsl { /** - * Configures under which [SourceSetTree] the currently configured Android Variant shall be placed. + * Configures under which [KotlinSourceSetTree] the currently configured Android Variant shall be placed. * e.g. * * ```kotlin