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

ru.tinkoff.plugins.buildmetrics.gradle.labels.internal.BuildOperationsLabelsFactory.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC2
Show newest version
package ru.tinkoff.plugins.buildmetrics.gradle.labels.internal

import org.gradle.internal.configurationcache.ConfigurationCacheLoadBuildOperationType
import org.gradle.internal.configurationcache.ConfigurationCacheStoreBuildOperationType
import org.gradle.tooling.provider.model.internal.QueryToolingModelBuildOperationType
import ru.tinkoff.plugins.buildmetrics.api.builds.internal.BuildOperationData
import ru.tinkoff.plugins.buildmetrics.api.builds.internal.BuildOperationDataListener
import ru.tinkoff.plugins.buildmetrics.api.factories.Factory
import ru.tinkoff.plugins.buildmetrics.api.labels.Label

/**
 * Labels:
 * - gradle_tooling_used;
 * - gradle_configuration_cache_reused;
 */
class BuildOperationsLabelsFactory : Factory.Labels, BuildOperationDataListener {

    private class FactoryData {

        var gradleToolingUsed: Boolean = false
            private set

        var configurationCacheLoaded: Boolean = false
            private set

        var configurationCacheStored: Boolean = false
            private set

        val configurationCacheReused: Boolean
            get() = configurationCacheLoaded && configurationCacheStored.not()

        fun onBuildOperationData(data: BuildOperationData) {
            when(data.details) {
                is QueryToolingModelBuildOperationType.Details -> gradleToolingUsed = true
                is ConfigurationCacheLoadBuildOperationType.Details -> configurationCacheLoaded = true
                is ConfigurationCacheStoreBuildOperationType.Details -> configurationCacheStored = true
            }
        }
    }

    @Transient
    private var factoryData: FactoryData = FactoryData()

    override fun reinitialize() {
        factoryData = FactoryData()
    }

    override fun onBuildOperationData(data: BuildOperationData) {
        factoryData.onBuildOperationData(data = data)
    }

    override fun create(): List> = listOf(
        Label(name = "gradle_tooling_used", value = factoryData.gradleToolingUsed),
        Label(name = "gradle_configuration_cache_reused", value = factoryData.configurationCacheReused),
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy