Add build uuid into build scan
This commit is contained in:
+2
-21
@@ -47,7 +47,7 @@ internal abstract class KotlinGradleBuildServices : BuildService<KotlinGradleBui
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun registerIfAbsent(project: Project, kotlinVersion: String): Provider<KotlinGradleBuildServices> =
|
fun registerIfAbsent(project: Project): Provider<KotlinGradleBuildServices> =
|
||||||
project.gradle.sharedServices.registerIfAbsent(
|
project.gradle.sharedServices.registerIfAbsent(
|
||||||
"kotlin-build-service-${KotlinGradleBuildServices::class.java.canonicalName}_${KotlinGradleBuildServices::class.java.classLoader.hashCode()}",
|
"kotlin-build-service-${KotlinGradleBuildServices::class.java.canonicalName}_${KotlinGradleBuildServices::class.java.classLoader.hashCode()}",
|
||||||
KotlinGradleBuildServices::class.java
|
KotlinGradleBuildServices::class.java
|
||||||
@@ -55,28 +55,9 @@ internal abstract class KotlinGradleBuildServices : BuildService<KotlinGradleBui
|
|||||||
service.parameters.rootDir = project.rootProject.rootDir
|
service.parameters.rootDir = project.rootProject.rootDir
|
||||||
service.parameters.buildDir = project.rootProject.buildDir
|
service.parameters.buildDir = project.rootProject.buildDir
|
||||||
|
|
||||||
val reportingSettings = reportingSettings(project.rootProject)
|
|
||||||
addListeners(project, reportingSettings, kotlinVersion)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addListeners(project: Project, reportingSettings: ReportingSettings, kotlinVersion: String) {
|
|
||||||
project.rootProject.extensions.findByName("buildScan")
|
|
||||||
?.also {
|
|
||||||
if (reportingSettings.buildReportOutputs.contains(BuildReportType.BUILD_SCAN)) {
|
|
||||||
val listenerRegistryHolder = BuildEventsListenerRegistryHolder.getInstance(project)
|
|
||||||
listenerRegistryHolder.listenerRegistry.onTaskCompletion(
|
|
||||||
project.provider {
|
|
||||||
BuildScanStatisticsListener(
|
|
||||||
it as BuildScanExtension,
|
|
||||||
project.rootProject.name,
|
|
||||||
reportingSettings.buildReportLabel,
|
|
||||||
kotlinVersion
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val multipleProjectsHolder = KotlinPluginInMultipleProjectsHolder(
|
private val multipleProjectsHolder = KotlinPluginInMultipleProjectsHolder(
|
||||||
trackPluginVersionsSeparately = true
|
trackPluginVersionsSeparately = true
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ abstract class DefaultKotlinBasePlugin : KotlinBasePlugin {
|
|||||||
addGradlePluginMetadataAttributes(project)
|
addGradlePluginMetadataAttributes(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinGradleBuildServices.registerIfAbsent(project, kotlinPluginVersion).get()
|
KotlinGradleBuildServices.registerIfAbsent(project).get()
|
||||||
KotlinGradleBuildServices.detectKotlinPluginLoadedInMultipleProjects(project, kotlinPluginVersion)
|
KotlinGradleBuildServices.detectKotlinPluginLoadedInMultipleProjects(project, kotlinPluginVersion)
|
||||||
|
|
||||||
BuildMetricsReporterService.registerIfAbsent(project)?.also {
|
BuildMetricsReporterService.registerIfAbsent(project)?.also {
|
||||||
|
|||||||
+5
-1
@@ -23,6 +23,7 @@ class BuildScanStatisticsListener(
|
|||||||
val projectName: String,
|
val projectName: String,
|
||||||
val label: String?,
|
val label: String?,
|
||||||
val kotlinVersion: String,
|
val kotlinVersion: String,
|
||||||
|
val buildUuid: String
|
||||||
) : OperationCompletionListener, AutoCloseable {
|
) : OperationCompletionListener, AutoCloseable {
|
||||||
companion object {
|
companion object {
|
||||||
const val lengthLimit = 100_000
|
const val lengthLimit = 100_000
|
||||||
@@ -30,7 +31,6 @@ class BuildScanStatisticsListener(
|
|||||||
|
|
||||||
private val tags = LinkedHashSet<String>()
|
private val tags = LinkedHashSet<String>()
|
||||||
private val log = Logging.getLogger(this.javaClass)
|
private val log = Logging.getLogger(this.javaClass)
|
||||||
private val buildUuid: String = UUID.randomUUID().toString()
|
|
||||||
|
|
||||||
override fun onFinish(event: FinishEvent?) {
|
override fun onFinish(event: FinishEvent?) {
|
||||||
if (event is TaskFinishEvent) {
|
if (event is TaskFinishEvent) {
|
||||||
@@ -53,6 +53,10 @@ class BuildScanStatisticsListener(
|
|||||||
|
|
||||||
readableString(data).forEach { buildScan.value(data.taskName, it) }
|
readableString(data).forEach { buildScan.value(data.taskName, it) }
|
||||||
|
|
||||||
|
if (!tags.contains(buildUuid)) {
|
||||||
|
tags.add(buildUuid)
|
||||||
|
}
|
||||||
|
|
||||||
data.label?.takeIf { !tags.contains(it) }?.also {
|
data.label?.takeIf { !tags.contains(it) }?.also {
|
||||||
buildScan.tag(it)
|
buildScan.tag(it)
|
||||||
tags.add(it)
|
tags.add(it)
|
||||||
|
|||||||
+30
-4
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.report
|
package org.jetbrains.kotlin.gradle.report
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.gradle.scan.plugin.BuildScanExtension
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.logging.Logging
|
import org.gradle.api.logging.Logging
|
||||||
import org.gradle.api.provider.Provider
|
import org.gradle.api.provider.Provider
|
||||||
@@ -15,9 +16,11 @@ import org.gradle.tooling.events.FinishEvent
|
|||||||
import org.gradle.tooling.events.OperationCompletionListener
|
import org.gradle.tooling.events.OperationCompletionListener
|
||||||
import org.gradle.tooling.events.task.TaskFinishEvent
|
import org.gradle.tooling.events.task.TaskFinishEvent
|
||||||
import org.jetbrains.kotlin.gradle.plugin.stat.BuildFinishData
|
import org.jetbrains.kotlin.gradle.plugin.stat.BuildFinishData
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.BuildEventsListenerRegistryHolder
|
||||||
import org.jetbrains.kotlin.gradle.plugin.stat.CompileStatisticsData
|
import org.jetbrains.kotlin.gradle.plugin.stat.CompileStatisticsData
|
||||||
import org.jetbrains.kotlin.gradle.plugin.stat.GradleBuildStartParameters
|
import org.jetbrains.kotlin.gradle.plugin.stat.GradleBuildStartParameters
|
||||||
import org.jetbrains.kotlin.gradle.plugin.stat.StatTag
|
import org.jetbrains.kotlin.gradle.plugin.stat.StatTag
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.statistics.BuildScanStatisticsListener
|
||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatListener.Companion.prepareData
|
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatListener.Companion.prepareData
|
||||||
import org.jetbrains.kotlin.gradle.report.BuildMetricsReporterService.Companion.getStartParameters
|
import org.jetbrains.kotlin.gradle.report.BuildMetricsReporterService.Companion.getStartParameters
|
||||||
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
|
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
|
||||||
@@ -33,7 +36,6 @@ abstract class HttpReportService : BuildService<HttpReportService.Parameters>,
|
|||||||
OperationCompletionListener, AutoCloseable {
|
OperationCompletionListener, AutoCloseable {
|
||||||
|
|
||||||
var executorService: ExecutorService = Executors.newSingleThreadExecutor()
|
var executorService: ExecutorService = Executors.newSingleThreadExecutor()
|
||||||
val uuid = UUID.randomUUID().toString()
|
|
||||||
|
|
||||||
val startTime = System.nanoTime()
|
val startTime = System.nanoTime()
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ abstract class HttpReportService : BuildService<HttpReportService.Parameters>,
|
|||||||
val log = Logging.getLogger(this.javaClass)
|
val log = Logging.getLogger(this.javaClass)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
log.info("Http report service is registered. Unique build id: $uuid")
|
log.info("Http report service is registered. Unique build id: $buildUuid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Volatile for one thread executor it does not need
|
// @Volatile for one thread executor it does not need
|
||||||
@@ -59,7 +61,7 @@ abstract class HttpReportService : BuildService<HttpReportService.Parameters>,
|
|||||||
override fun onFinish(event: FinishEvent?) {
|
override fun onFinish(event: FinishEvent?) {
|
||||||
if (event is TaskFinishEvent) {
|
if (event is TaskFinishEvent) {
|
||||||
val data =
|
val data =
|
||||||
prepareData(event, parameters.projectName, uuid, parameters.label, parameters.kotlinVersion, parameters.additionalTags)
|
prepareData(event, parameters.projectName, buildUuid, parameters.label, parameters.kotlinVersion, parameters.additionalTags)
|
||||||
data?.also { executorService.submit { report(data) } }
|
data?.also { executorService.submit { report(data) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,11 +73,15 @@ abstract class HttpReportService : BuildService<HttpReportService.Parameters>,
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
val buildUuid = UUID.randomUUID().toString()
|
||||||
|
|
||||||
fun registerIfAbsent(project: Project, kotlinVersion: String): Provider<HttpReportService>? {
|
fun registerIfAbsent(project: Project, kotlinVersion: String): Provider<HttpReportService>? {
|
||||||
val gradle = project.gradle
|
val gradle = project.gradle
|
||||||
val rootProject = gradle.rootProject
|
val rootProject = gradle.rootProject
|
||||||
val reportingSettings = reportingSettings(rootProject)
|
val reportingSettings = reportingSettings(rootProject)
|
||||||
|
|
||||||
|
addListeners(project, reportingSettings, kotlinVersion)
|
||||||
|
|
||||||
return reportingSettings.httpReportSettings?.let { httpSettings ->
|
return reportingSettings.httpReportSettings?.let { httpSettings ->
|
||||||
gradle.sharedServices.registerIfAbsent(
|
gradle.sharedServices.registerIfAbsent(
|
||||||
"build_http_metric_service_${HttpReportService::class.java.classLoader.hashCode()}",
|
"build_http_metric_service_${HttpReportService::class.java.classLoader.hashCode()}",
|
||||||
@@ -101,6 +107,26 @@ abstract class HttpReportService : BuildService<HttpReportService.Parameters>,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addListeners(project: Project, reportingSettings: ReportingSettings, kotlinVersion: String) {
|
||||||
|
if (reportingSettings.buildReportOutputs.contains(BuildReportType.BUILD_SCAN)) {
|
||||||
|
project.rootProject.extensions.findByName("buildScan")
|
||||||
|
?.also {
|
||||||
|
val listenerRegistryHolder = BuildEventsListenerRegistryHolder.getInstance(project)
|
||||||
|
listenerRegistryHolder.listenerRegistry.onTaskCompletion(
|
||||||
|
project.provider {
|
||||||
|
BuildScanStatisticsListener(
|
||||||
|
it as BuildScanExtension,
|
||||||
|
project.rootProject.name,
|
||||||
|
reportingSettings.buildReportLabel,
|
||||||
|
kotlinVersion,
|
||||||
|
buildUuid
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun report(data: Any) {
|
fun report(data: Any) {
|
||||||
@@ -144,7 +170,7 @@ abstract class HttpReportService : BuildService<HttpReportService.Parameters>,
|
|||||||
private fun reportBuildFinish() {
|
private fun reportBuildFinish() {
|
||||||
val buildFinishData = BuildFinishData(
|
val buildFinishData = BuildFinishData(
|
||||||
startParameters = parameters.startParameters,
|
startParameters = parameters.startParameters,
|
||||||
buildUuid = parameters.uuid,
|
buildUuid = buildUuid,
|
||||||
label = parameters.label,
|
label = parameters.label,
|
||||||
totalTime = (System.nanoTime() - startTime) / 1_000_000
|
totalTime = (System.nanoTime() - startTime) / 1_000_000
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user