[Gradle] KotlinPluginLifecycle: Implement .toString for better diagnostics
^KT-59446 In Progress
This commit is contained in:
committed by
Space Team
parent
46ea908daf
commit
d7facce71f
+4
@@ -296,6 +296,10 @@ internal interface KotlinPluginLifecycle {
|
|||||||
|
|
||||||
val stage: Stage
|
val stage: Stage
|
||||||
|
|
||||||
|
val isStarted: Boolean
|
||||||
|
|
||||||
|
val isFinished: Boolean
|
||||||
|
|
||||||
fun launch(block: suspend KotlinPluginLifecycle.() -> Unit)
|
fun launch(block: suspend KotlinPluginLifecycle.() -> Unit)
|
||||||
|
|
||||||
suspend fun await(stage: Stage)
|
suspend fun await(stage: Stage)
|
||||||
|
|||||||
+19
-5
@@ -24,15 +24,21 @@ internal class KotlinPluginLifecycleImpl(override val project: Project) : Kotlin
|
|||||||
KotlinPluginLifecycle.Stage.values().associateWith { ArrayDeque() }
|
KotlinPluginLifecycle.Stage.values().associateWith { ArrayDeque() }
|
||||||
|
|
||||||
private val loopRunning = AtomicBoolean(false)
|
private val loopRunning = AtomicBoolean(false)
|
||||||
private val isStarted = AtomicBoolean(false)
|
private val isStartedImpl = AtomicBoolean(false)
|
||||||
private val isFinishedSuccessfully = AtomicBoolean(false)
|
private val isFinishedSuccessfully = AtomicBoolean(false)
|
||||||
private val isFinishedWithFailures = AtomicBoolean(false)
|
private val isFinishedWithFailures = AtomicBoolean(false)
|
||||||
|
|
||||||
|
|
||||||
override var stage: KotlinPluginLifecycle.Stage = KotlinPluginLifecycle.Stage.values.first()
|
override var stage: KotlinPluginLifecycle.Stage = KotlinPluginLifecycle.Stage.values.first()
|
||||||
|
|
||||||
|
override val isStarted: Boolean
|
||||||
|
get() = isStartedImpl.get()
|
||||||
|
|
||||||
|
override val isFinished: Boolean
|
||||||
|
get() = isFinishedSuccessfully.get() || isFinishedWithFailures.get()
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
check(!isStarted.getAndSet(true)) {
|
check(!isStartedImpl.getAndSet(true)) {
|
||||||
"${KotlinPluginLifecycle::class.java.name} already started"
|
"${KotlinPluginLifecycle::class.java.name} already started"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +109,13 @@ internal class KotlinPluginLifecycleImpl(override val project: Project) : Kotlin
|
|||||||
|
|
||||||
private fun finishWithFailures(failures: List<Throwable>) {
|
private fun finishWithFailures(failures: List<Throwable>) {
|
||||||
assert(failures.isNotEmpty())
|
assert(failures.isNotEmpty())
|
||||||
assert(isStarted.get())
|
assert(isStartedImpl.get())
|
||||||
assert(!isFinishedWithFailures.getAndSet(true))
|
assert(!isFinishedWithFailures.getAndSet(true))
|
||||||
configurationResult.complete(ProjectConfigurationResult.Failure(failures))
|
configurationResult.complete(ProjectConfigurationResult.Failure(failures))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun finishSuccessfully() {
|
private fun finishSuccessfully() {
|
||||||
assert(isStarted.get())
|
assert(isStartedImpl.get())
|
||||||
assert(!isFinishedSuccessfully.getAndSet(true))
|
assert(!isFinishedSuccessfully.getAndSet(true))
|
||||||
configurationResult.complete(ProjectConfigurationResult.Success)
|
configurationResult.complete(ProjectConfigurationResult.Success)
|
||||||
}
|
}
|
||||||
@@ -140,7 +146,7 @@ internal class KotlinPluginLifecycleImpl(override val project: Project) : Kotlin
|
|||||||
|
|
||||||
enqueuedActions.getValue(stage).addLast(action)
|
enqueuedActions.getValue(stage).addLast(action)
|
||||||
|
|
||||||
if (stage == KotlinPluginLifecycle.Stage.EvaluateBuildscript && isStarted.get()) {
|
if (stage == KotlinPluginLifecycle.Stage.EvaluateBuildscript && isStartedImpl.get()) {
|
||||||
loopIfNecessary()
|
loopIfNecessary()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,6 +174,14 @@ internal class KotlinPluginLifecycleImpl(override val project: Project) : Kotlin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String = buildString {
|
||||||
|
append("Kotlin Plugin Lifecycle: (${project.displayName})")
|
||||||
|
if (!isStarted) append(" *not started*")
|
||||||
|
else append(" stage '$stage'")
|
||||||
|
if (isFinishedSuccessfully.get()) append(" *finished successfully*")
|
||||||
|
if (isFinishedWithFailures.get()) append(" *finished with failures*")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KotlinPluginLifecycleCoroutineContextElement(
|
private class KotlinPluginLifecycleCoroutineContextElement(
|
||||||
|
|||||||
+5
-5
@@ -64,7 +64,7 @@ internal fun CompletableFuture<Unit>.complete() = complete(Unit)
|
|||||||
* @param name: The name of the extras key being used to store the future (see [extrasLazyProperty])
|
* @param name: The name of the extras key being used to store the future (see [extrasLazyProperty])
|
||||||
*/
|
*/
|
||||||
internal inline fun <Receiver, reified T> futureExtension(
|
internal inline fun <Receiver, reified T> futureExtension(
|
||||||
name: String? = null, noinline block: suspend Receiver.() -> T
|
name: String? = null, noinline block: suspend Receiver.() -> T,
|
||||||
): ExtrasLazyProperty<Receiver, Future<T>> where Receiver : HasMutableExtras, Receiver : HasProject {
|
): ExtrasLazyProperty<Receiver, Future<T>> where Receiver : HasMutableExtras, Receiver : HasProject {
|
||||||
return extrasLazyProperty<Receiver, Future<T>>(name) {
|
return extrasLazyProperty<Receiver, Future<T>>(name) {
|
||||||
project.future { block() }
|
project.future { block() }
|
||||||
@@ -97,7 +97,7 @@ internal fun <T> CompletableFuture(): CompletableFuture<T> {
|
|||||||
|
|
||||||
private class FutureImpl<T>(
|
private class FutureImpl<T>(
|
||||||
private val deferred: Completable<T> = Completable(),
|
private val deferred: Completable<T> = Completable(),
|
||||||
private val lifecycle: KotlinPluginLifecycle? = null
|
private val lifecycle: KotlinPluginLifecycle? = null,
|
||||||
) : CompletableFuture<T>, Serializable {
|
) : CompletableFuture<T>, Serializable {
|
||||||
fun completeWith(result: Result<T>) = deferred.completeWith(result)
|
fun completeWith(result: Result<T>) = deferred.completeWith(result)
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ private class FutureImpl<T>(
|
|||||||
|
|
||||||
override fun getOrThrow(): T {
|
override fun getOrThrow(): T {
|
||||||
return if (deferred.isCompleted) deferred.getCompleted() else throw IllegalLifecycleException(
|
return if (deferred.isCompleted) deferred.getCompleted() else throw IllegalLifecycleException(
|
||||||
"Future was not completed yet" + if (lifecycle != null) " (stage '${lifecycle.stage}') (${lifecycle.project.displayName})"
|
"Future was not completed yet" + if (lifecycle != null) " '$lifecycle'"
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ private class FutureImpl<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class LenientFutureImpl<T>(
|
private class LenientFutureImpl<T>(
|
||||||
private val future: Future<T>
|
private val future: Future<T>,
|
||||||
) : LenientFuture<T>, Serializable {
|
) : LenientFuture<T>, Serializable {
|
||||||
override suspend fun await(): T {
|
override suspend fun await(): T {
|
||||||
return future.await()
|
return future.await()
|
||||||
@@ -181,7 +181,7 @@ private class LazyFutureImpl<T>(private val future: Lazy<Future<T>>) : Future<T>
|
|||||||
* Simple, Single Threaded, replacement for kotlinx.coroutines.CompletableDeferred.
|
* Simple, Single Threaded, replacement for kotlinx.coroutines.CompletableDeferred.
|
||||||
*/
|
*/
|
||||||
private class Completable<T>(
|
private class Completable<T>(
|
||||||
private var value: Result<T>? = null
|
private var value: Result<T>? = null,
|
||||||
) {
|
) {
|
||||||
constructor(value: T) : this(Result.success(value))
|
constructor(value: T) : this(Result.success(value))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user