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

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

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

import org.gradle.api.flow.BuildWorkResult
import ru.tinkoff.plugins.buildmetrics.api.builds.BuildWorkResultListener
import ru.tinkoff.plugins.buildmetrics.api.factories.Factory
import ru.tinkoff.plugins.buildmetrics.api.labels.Label
import kotlin.jvm.optionals.getOrNull

/**
 * Labels:
 * - gradle_build_success;
 */
class BuildResultLabelsFactory : Factory.Labels, BuildWorkResultListener {

    @Transient
    private var failure: String? = null

    override fun reinitialize() {
        failure = null
    }

    override fun onBuildWorkResult(result: BuildWorkResult) {
        result.failure.getOrNull()?.let { buildFailure ->
            failure = buildFailure.toString()
        }
    }

    override fun create(): List> {
        return listOf(
            buildSuccessLabel(),
        )
    }

    /**
     * Build success label.
     *
     * Visible for testing.
     */
    internal fun buildSuccessLabel(): Label = Label(
        name = "gradle_build_success",
        value = failure == null,
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy