From 2a4f9b19f0e0738505076521c57a33020f39c5aa Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Wed, 21 Jun 2023 14:34:05 +0200 Subject: [PATCH] [Gradle] KotlinSourceSetConvention: KotlinSourceSet registration logic Separate the retrieval and registration of KotlinSourceSets in the getValue function of KotlinSourceSetConvention. Add a custom Trace class to be stored in the isRegisteredByKotlinSourceSetConventionAt property for better readability and debugging purposes. --- .../kotlin/gradle/dsl/KotlinSourceSetConvention.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt index e3b8a65ccd1..04b2b58c21a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt @@ -39,12 +39,17 @@ import kotlin.reflect.KProperty @ExperimentalKotlinGradlePluginApi object KotlinSourceSetConvention : ReadOnlyProperty, NamedDomainObjectProvider> { + + internal class Trace : Throwable() + override fun getValue( thisRef: NamedDomainObjectContainer, property: KProperty<*>, ): NamedDomainObjectProvider { val name = property.name - return if (name in thisRef.names) thisRef.named(name) else thisRef.register(name) { sourceSet -> - sourceSet.isRegisteredByKotlinSourceSetConventionAt = Throwable() + if (name in thisRef.names) return thisRef.named(name) + val trace = Trace() + return thisRef.register(name) { sourceSet -> + sourceSet.isRegisteredByKotlinSourceSetConventionAt = trace } } @@ -53,7 +58,7 @@ object KotlinSourceSetConvention : * This will be null if SourceSet already existed and was referenced using the convention, or of no convention was used at all. */ @Suppress("UnusedReceiverParameter") // Diagnostic is wrong - internal var KotlinSourceSet.isRegisteredByKotlinSourceSetConventionAt: Throwable? + internal var KotlinSourceSet.isRegisteredByKotlinSourceSetConventionAt: Trace? by extrasReadWriteProperty("isRegisteredByKotlinSourceSetConvention") private set }