From d0984cc6a32f5477a72b73fa60966eaefec24ec2 Mon Sep 17 00:00:00 2001 From: "Nataliya.Valtman" Date: Mon, 24 Jun 2024 20:06:02 +0000 Subject: [PATCH] Calculate projects configurationMetrics after project evaluation This configuration metrics calculation allows - to avoid metrics calculation on build close and CME - to get clear stack trace and error message in case of exception Delete unnecessary ProjectConfigurationFusService services. #KTI-1611 Fixed Merge-request: KT-MR-16382 Merged-by: Nataliya Valtman (cherry picked from commit 363cbacb6ed422ab02e050efdd465541ac5fb03b) --- .../plugin/statistics/BuildFusService.kt | 2 - .../FinalizeConfigurationFusMetricAction.kt | 10 +---- .../ProjectConfigurationFusService.kt | 38 ------------------- 3 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/ProjectConfigurationFusService.kt diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/BuildFusService.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/BuildFusService.kt index c6defd3489802..c3c60aa9601ef 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/BuildFusService.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/BuildFusService.kt @@ -95,8 +95,6 @@ abstract class BuildFusService : BuildService, AutoC val isConfigurationCacheRequested = project.isConfigurationCacheRequested val isProjectIsolationRequested = project.isProjectIsolationRequested - ProjectConfigurationFusService.registerIfAbsent(project) - project.gradle.sharedServices.registrations.findByName(serviceName)?.let { @Suppress("UNCHECKED_CAST") return (it.service as Provider) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FinalizeConfigurationFusMetricAction.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FinalizeConfigurationFusMetricAction.kt index 239d866cfbb96..a6b6f146be80e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FinalizeConfigurationFusMetricAction.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FinalizeConfigurationFusMetricAction.kt @@ -13,17 +13,9 @@ import org.jetbrains.kotlin.gradle.plugin.await internal val FinalizeConfigurationFusMetricAction = KotlinProjectSetupCoroutine { KotlinPluginLifecycle.Stage.ReadyForExecution.await() - val projectConfigurationService = - project.gradle.sharedServices.registrations.findByName(ProjectConfigurationFusService.getServiceName(project))?.also { - val parameters = it.parameters as ProjectConfigurationFusService.Parameters - parameters.configurationMetrics.finalizeValue() - } - project.gradle.sharedServices.registrations.findByName(BuildFusService.serviceName)?.also { val parameters = it.parameters as BuildFusService.Parameters parameters.generalConfigurationMetrics.finalizeValue() - projectConfigurationService?.service?.orNull?.also { - parameters.configurationMetrics.add((it.parameters as ProjectConfigurationFusService.Parameters).configurationMetrics) - } + parameters.configurationMetrics.add(KotlinProjectConfigurationMetrics.collectMetrics(project)) } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/ProjectConfigurationFusService.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/ProjectConfigurationFusService.kt deleted file mode 100644 index 8517fcd55479f..0000000000000 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/ProjectConfigurationFusService.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.gradle.plugin.statistics - -import org.gradle.api.Project -import org.gradle.api.provider.Property -import org.gradle.api.provider.Provider -import org.gradle.api.services.BuildService -import org.gradle.api.services.BuildServiceParameters - -abstract class ProjectConfigurationFusService : BuildService, AutoCloseable { - interface Parameters : BuildServiceParameters { - val configurationMetrics: Property - } - - companion object { - fun getServiceName(project: Project): String = - "${project.path}_${ProjectConfigurationFusService::class.simpleName}_${ProjectConfigurationFusService::class.java.classLoader.hashCode()}" - - //register a new service for every project to collect configuration metrics - fun registerIfAbsent(project: Project): Provider { - return project.gradle.sharedServices.registerIfAbsent( - getServiceName(project), - ProjectConfigurationFusService::class.java - ) { spec -> - spec.parameters.configurationMetrics.set(project.provider { - KotlinProjectConfigurationMetrics.collectMetrics(project) - }) - } - } - } - - override fun close() { - } -} \ No newline at end of file