[Gradle] KotlinPluginLifecycle: Ensure no enqueued actions will be missed

^KT-34662 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-03-10 14:12:53 +01:00
committed by Space Team
parent 4ba2107ec5
commit 4c653a4297
2 changed files with 26 additions and 5 deletions
@@ -385,22 +385,27 @@ private class KotlinPluginLifecycleImpl(override val project: Project) : KotlinP
project.whenEvaluated {
assert(enqueuedActions.getValue(stage).isEmpty()) { "Expected empty queue from '$stage'" }
executeStage(project, stage.nextOrThrow)
stage = stage.nextOrThrow
executeCurrentStageAndScheduleNext()
}
}
private fun executeStage(project: Project, stage: Stage) {
this.stage = stage
private fun executeCurrentStageAndScheduleNext() {
stage.previousOrNull?.let { previousStage ->
assert(enqueuedActions.getValue(previousStage).isEmpty()) {
"Actions from previous stage '$previousStage' have not been executed (stage: '$stage')"
}
}
loopIfNecessary()
val nextStage = stage.nextOrNull ?: run {
stage = stage.nextOrNull ?: run {
isFinished.set(true)
return
}
project.afterEvaluate {
executeStage(project, nextStage)
executeCurrentStageAndScheduleNext()
}
}
@@ -350,6 +350,22 @@ class KotlinPluginLifecycleTest {
}
}
@Test
fun `test - launching in AfterEvaluate`() = project.runLifecycleAwareTest {
val actionInvocations = AtomicInteger(0)
afterEvaluate {
launch {
assertEquals(AfterEvaluate.nextOrThrow, currentKotlinPluginLifecycle().stage)
assertEquals(1, actionInvocations.incrementAndGet())
}
}
await(AfterEvaluate.nextOrThrow.nextOrThrow)
assertEquals(1, actionInvocations.get())
await(Stage.values.last())
}
@Test
fun `test - Stage - previous next utils`() {
assertNull(Stage.values.first().previousOrNull)