Skip to content

Commit 54b11e3

Browse files
sellmairSpace Team
authored and
Space Team
committed
[Gradle] KotlinPluginLifecycle: Implement .toString for better diagnostics
^KT-59446 In Progress (cherry picked from commit d7facce)
1 parent 3a65c0c commit 54b11e3

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPluginLifecycle.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ internal interface KotlinPluginLifecycle {
329329

330330
fun enqueue(stage: Stage, action: KotlinPluginLifecycle.() -> Unit)
331331

332+
val isStarted: Boolean
333+
332334
fun launch(block: suspend KotlinPluginLifecycle.() -> Unit)
333335

334336
suspend fun await(stage: Stage)
@@ -370,13 +372,16 @@ private class KotlinPluginLifecycleImpl(override val project: Project) : KotlinP
370372
Stage.values().associateWith { ArrayDeque() }
371373

372374
private val loopRunning = AtomicBoolean(false)
373-
private val isStarted = AtomicBoolean(false)
375+
private val isStartedImpl = AtomicBoolean(false)
374376
private val isFinished = AtomicBoolean(false)
375377

378+
override val isStarted: Boolean
379+
get() = isStartedImpl.get()
380+
376381
private val properties = WeakHashMap<Property<*>, WeakReference<LifecycleAwareProperty<*>>>()
377382

378383
fun start() {
379-
check(!isStarted.getAndSet(true)) {
384+
check(!isStartedImpl.getAndSet(true)) {
380385
"${KotlinPluginLifecycle::class.java.name} already started"
381386
}
382387

@@ -444,7 +449,7 @@ private class KotlinPluginLifecycleImpl(override val project: Project) : KotlinP
444449

445450
enqueuedActions.getValue(stage).addLast(action)
446451

447-
if (stage == Stage.EvaluateBuildscript && isStarted.get()) {
452+
if (stage == Stage.EvaluateBuildscript && isStartedImpl.get()) {
448453
loopIfNecessary()
449454
}
450455
}
@@ -498,6 +503,13 @@ private class KotlinPluginLifecycleImpl(override val project: Project) : KotlinP
498503
return property.orNull
499504
}
500505
}
506+
507+
override fun toString(): String = buildString {
508+
append("Kotlin Plugin Lifecycle: (${project.displayName})")
509+
if (!isStarted) append(" *not started*")
510+
else append(" stage '$stage'")
511+
if (isFinished.get()) append(" *finished*")
512+
}
501513
}
502514

503515
private class KotlinPluginLifecycleCoroutineContextElement(

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/utils/Future.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal fun CompletableFuture<Unit>.complete() = complete(Unit)
6464
* @param name: The name of the extras key being used to store the future (see [extrasLazyProperty])
6565
*/
6666
internal inline fun <Receiver, reified T> futureExtension(
67-
name: String? = null, noinline block: suspend Receiver.() -> T
67+
name: String? = null, noinline block: suspend Receiver.() -> T,
6868
): ExtrasLazyProperty<Receiver, Future<T>> where Receiver : HasMutableExtras, Receiver : HasProject {
6969
return extrasLazyProperty<Receiver, Future<T>>(name) {
7070
project.future { block() }
@@ -97,7 +97,7 @@ internal fun <T> CompletableFuture(): CompletableFuture<T> {
9797

9898
private class FutureImpl<T>(
9999
private val deferred: Completable<T> = Completable(),
100-
private val lifecycle: KotlinPluginLifecycle? = null
100+
private val lifecycle: KotlinPluginLifecycle? = null,
101101
) : CompletableFuture<T>, Serializable {
102102
fun completeWith(result: Result<T>) = deferred.completeWith(result)
103103

@@ -111,7 +111,7 @@ private class FutureImpl<T>(
111111

112112
override fun getOrThrow(): T {
113113
return if (deferred.isCompleted) deferred.getCompleted() else throw IllegalLifecycleException(
114-
"Future was not completed yet" + if (lifecycle != null) " (stage '${lifecycle.stage}') (${lifecycle.project.displayName})"
114+
"Future was not completed yet" + if (lifecycle != null) " '$lifecycle'"
115115
else ""
116116
)
117117
}
@@ -128,7 +128,7 @@ private class FutureImpl<T>(
128128
}
129129

130130
private class LenientFutureImpl<T>(
131-
private val future: Future<T>
131+
private val future: Future<T>,
132132
) : LenientFuture<T>, Serializable {
133133
override suspend fun await(): T {
134134
return future.await()
@@ -181,7 +181,7 @@ private class LazyFutureImpl<T>(private val future: Lazy<Future<T>>) : Future<T>
181181
* Simple, Single Threaded, replacement for kotlinx.coroutines.CompletableDeferred.
182182
*/
183183
private class Completable<T>(
184-
private var value: Result<T>? = null
184+
private var value: Result<T>? = null,
185185
) {
186186
constructor(value: T) : this(Result.success(value))
187187

0 commit comments

Comments
 (0)