[Gradle] KotlinPluginLifecycle: Rename .configured to .configurationResult

^KT-58255 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-05-04 10:18:41 +02:00
committed by Space Team
parent 08055b6188
commit b437c3e0e9
3 changed files with 16 additions and 14 deletions
@@ -137,7 +137,7 @@ internal val Project.kotlinPluginLifecycle: KotlinPluginLifecycle
* will lead to: * will lead to:
* ```kotlin * ```kotlin
* project.launch { * project.launch {
* val result = project.configured.await() * val result = project.configurationResult.await()
* val result as Failure * val result as Failure
* val exception = result.failures.first() * val exception = result.failures.first()
* println(exception.message) // 'My Error' * println(exception.message) // 'My Error'
@@ -149,7 +149,7 @@ internal val Project.kotlinPluginLifecycle: KotlinPluginLifecycle
* Even in case of failure it is still okay to further launch a new coroutine * Even in case of failure it is still okay to further launch a new coroutine
* ```kotlin * ```kotlin
* project.launch { * project.launch {
* val result = project.configured.await() as Failure * val result = project.configurationResult.await() as Failure
* val anotherJob = project.launch { ... } // <- executed right away * val anotherJob = project.launch { ... } // <- executed right away
* val someFutureEvaluation = project.someFuture.getOrThrow() // <- will return value if all 'requirements' have been met. * val someFutureEvaluation = project.someFuture.getOrThrow() // <- will return value if all 'requirements' have been met.
* } * }
@@ -158,12 +158,12 @@ internal val Project.kotlinPluginLifecycle: KotlinPluginLifecycle
* Note: [Future.getOrThrow] will throw if e.g. the lifecycle fails in a very early stage, but the Future requires * Note: [Future.getOrThrow] will throw if e.g. the lifecycle fails in a very early stage, but the Future requires
* some later data to be available. In this case, the Future still will only return 'sane' data. * some later data to be available. In this case, the Future still will only return 'sane' data.
*/ */
internal val Project.configured: Future<ProjectConfigurationResult> internal val Project.configurationResult: Future<ProjectConfigurationResult>
get() = configuredImpl get() = configurationResultImpl
private val Project.configuredImpl: CompletableFuture<ProjectConfigurationResult> private val Project.configurationResultImpl: CompletableFuture<ProjectConfigurationResult>
get() = extraProperties.getOrPut("org.jetbrains.kotlin.gradle.plugin.configured") { CompletableFuture() } get() = extraProperties.getOrPut("org.jetbrains.kotlin.gradle.plugin.configurationResult") { CompletableFuture() }
/** /**
@@ -505,13 +505,13 @@ private class KotlinPluginLifecycleImpl(override val project: Project) : KotlinP
assert(failures.isNotEmpty()) assert(failures.isNotEmpty())
assert(isStarted.get()) assert(isStarted.get())
assert(!isFinishedWithFailures.getAndSet(true)) assert(!isFinishedWithFailures.getAndSet(true))
project.configuredImpl.complete(ProjectConfigurationResult.Failure(failures)) project.configurationResultImpl.complete(ProjectConfigurationResult.Failure(failures))
} }
private fun finishSuccessfully() { private fun finishSuccessfully() {
assert(isStarted.get()) assert(isStarted.get())
assert(!isFinishedSuccessfully.getAndSet(true)) assert(!isFinishedSuccessfully.getAndSet(true))
project.configuredImpl.complete(ProjectConfigurationResult.Success) project.configurationResultImpl.complete(ProjectConfigurationResult.Success)
} }
override fun enqueue(stage: Stage, action: KotlinPluginLifecycle.() -> Unit) { override fun enqueue(stage: Stage, action: KotlinPluginLifecycle.() -> Unit) {
@@ -258,7 +258,7 @@ abstract class KotlinBasePluginWrapper : DefaultKotlinBasePlugin() {
private fun Project.launchDiagnosticChecksAndReporting() { private fun Project.launchDiagnosticChecksAndReporting() {
project.launchKotlinGradleProjectCheckers() project.launchKotlinGradleProjectCheckers()
project.launch { project.launch {
project.configured.await() project.configurationResult.await()
renderReportedDiagnostics( renderReportedDiagnostics(
project.kotlinToolingDiagnosticsCollector.getDiagnosticsForProject(project), project.kotlinToolingDiagnosticsCollector.getDiagnosticsForProject(project),
project.logger, project.logger,
@@ -214,7 +214,8 @@ class KotlinPluginLifecycleTest {
fail("AfterEvaluate based stage is not expected to be launched because of exception during .evaluate()", throwable) fail("AfterEvaluate based stage is not expected to be launched because of exception during .evaluate()", throwable)
} }
val exceptions = project.configured.getOrThrow().cast<Failure>().failures.withClosure<Throwable> { listOfNotNull(it.cause) } val exceptions = project.configurationResult.getOrThrow().cast<Failure>()
.failures.withClosure<Throwable> { listOfNotNull(it.cause) }
if (thrownException !in exceptions) fail("Expected 'thrownException' in lifecycle.finished") if (thrownException !in exceptions) fail("Expected 'thrownException' in lifecycle.finished")
} }
@@ -224,7 +225,8 @@ class KotlinPluginLifecycleTest {
val executedAfterLifecycleFinished = AtomicBoolean(false) val executedAfterLifecycleFinished = AtomicBoolean(false)
project.launch { project.launch {
val exceptions = project.configured.await().cast<Failure>().failures.withClosure<Throwable> { listOfNotNull(it.cause) } val exceptions = project.configurationResult.await().cast<Failure>()
.failures.withClosure<Throwable> { listOfNotNull(it.cause) }
assertFalse(executedAfterLifecycleFinished.getAndSet(true)) assertFalse(executedAfterLifecycleFinished.getAndSet(true))
if (thrownException !in exceptions) fail("Expected 'thrownException' in lifecycle.finished") if (thrownException !in exceptions) fail("Expected 'thrownException' in lifecycle.finished")
} }
@@ -252,7 +254,7 @@ class KotlinPluginLifecycleTest {
} }
project.launch secondAction@{ project.launch secondAction@{
project.configured.await() project.configurationResult.await()
assertEquals(AfterEvaluateBuildscript, stage) assertEquals(AfterEvaluateBuildscript, stage)
assertEquals(42, future.getOrThrow()) assertEquals(42, future.getOrThrow())
assertEquals(420, project.future { AfterEvaluateBuildscript.await(); 420 }.getOrThrow()) assertEquals(420, project.future { AfterEvaluateBuildscript.await(); 420 }.getOrThrow())
@@ -280,14 +282,14 @@ class KotlinPluginLifecycleTest {
} }
project.launch { project.launch {
project.configured.await() project.configurationResult.await()
project.launchInStage(AfterEvaluateBuildscript.nextOrThrow) thirdAction@{ project.launchInStage(AfterEvaluateBuildscript.nextOrThrow) thirdAction@{
assertFalse(thirdActionExecuted.getAndSet(true)) assertFalse(thirdActionExecuted.getAndSet(true))
} }
} }
project.launch fourthAction@{ project.launch fourthAction@{
project.configured.await() project.configurationResult.await()
AfterEvaluateBuildscript.nextOrThrow.await() AfterEvaluateBuildscript.nextOrThrow.await()
assertFalse(fourthActionExecuted.getAndSet(true)) assertFalse(fourthActionExecuted.getAndSet(true))
} }