All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.gradle.plugin.StatisticsBuildFlowManager.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2023 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

import org.gradle.api.Project
import org.gradle.api.flow.*
import org.gradle.api.provider.Property
import org.gradle.api.services.ServiceReference
import org.gradle.api.tasks.Input
import org.jetbrains.kotlin.gradle.plugin.statistics.BuildFusService
import org.jetbrains.kotlin.gradle.report.BuildMetricsService
import org.jetbrains.kotlin.gradle.report.BuildScanExtensionHolder
import javax.inject.Inject

internal abstract class StatisticsBuildFlowManager @Inject constructor(
    private val flowScope: FlowScope,
    private val flowProviders: FlowProviders,
) {
    companion object {
        fun getInstance(project: Project) =
            project.objects.newInstance(StatisticsBuildFlowManager::class.java)
    }

    fun subscribeForBuildResult() {
        flowScope.always(
            BuildFinishFlowAction::class.java
        ) { spec ->
            spec.parameters.buildFailed.set(flowProviders.buildWorkResult.map { it.failure.isPresent })
        }
    }

    fun subscribeForBuildScan(buildScanHolder: BuildScanExtensionHolder) {
        flowScope.always(
            BuildScanFlowAction::class.java
        ) { spec ->
            spec.parameters.buildScanExtensionHolder.set(buildScanHolder)
        }
    }
}

internal class BuildScanFlowAction : FlowAction {
    interface Parameters : FlowParameters {
        @get:ServiceReference
        val buildMetricService: Property

        @get: Input
        val buildScanExtensionHolder: Property
    }

    override fun execute(parameters: Parameters) {
        parameters.buildMetricService.orNull?.addBuildScanReport(parameters.buildScanExtensionHolder.orNull)
    }
}

internal class BuildFinishFlowAction : FlowAction {
    interface Parameters : FlowParameters {
        @get:ServiceReference
        val buildFusServiceProperty: Property

        @get:Input
        val buildFailed: Property

    }

    override fun execute(parameters: Parameters) {
        parameters.buildFusServiceProperty.orNull?.recordBuildFinished(parameters.buildFailed.get())
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy