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

ru.tinkoff.plugins.buildmetrics.gradle.internal.utils.TasksData.kt Maven / Gradle / Ivy

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

import org.gradle.api.internal.tasks.TaskExecutionOutcome
import org.gradle.api.internal.tasks.execution.ExecuteTaskBuildOperationType
import ru.tinkoff.plugins.buildmetrics.api.builds.internal.BuildOperationData

/**
 * Tasks data.
 */
internal class TasksData(
    val runTasksCount: Int,
    val executedTasksCount: Int,
    val fromCacheTasksCount: Int,
    val upToDateTasksCount: Int,
    val skippedTasksCount: Int,
    val noSourceTasksCount: Int,
    val lifecycleTasksCount: Int,
    val requestedFromCacheTasksCount: Int,
) {

    internal class Builder {

        private var runTasksCount: Int = 0

        private var executedTasksCount: Int = 0

        private var fromCacheTasksCount: Int = 0

        private var upToDateTasksCount: Int = 0

        private var skippedTasksCount: Int = 0

        private var noSourceTasksCount: Int = 0

        private var lifecycleTasksCount: Int = 0

        /**
         * Tasks whose outputs were requested from cache.
         *
         * Task can request a cache if it meets the conditions:
         * - task is actionable (contains `doFirst`, `doLast` or `org.gradle.api.tasks.TaskAction`);
         * - task cache is not disabled (`cachingDisabledReasonCategory` is `null`)
         * - task executed
         *   (`skipMessage` equals `org.gradle.api.internal.tasks.TaskExecutionOutcome.EXECUTED.message`)
         *   **OR**
         *   task execution was skipped because the result was taken from the cache
         *   (`skipMessage` equals `org.gradle.api.internal.tasks.TaskExecutionOutcome.FROM_CACHE.message`)
         */
        private var requestedFromCacheTasksCount: Int = 0

        fun onBuildOperationData(data: BuildOperationData) {
            val result = data.result
            if (result is ExecuteTaskBuildOperationType.Result) {
                ++runTasksCount
                if (result.isActionable) {
                    when (result.skipMessage) {
                        TaskExecutionOutcome.EXECUTED.message -> ++executedTasksCount
                        TaskExecutionOutcome.FROM_CACHE.message -> ++fromCacheTasksCount
                        TaskExecutionOutcome.UP_TO_DATE.message -> ++upToDateTasksCount
                        TaskExecutionOutcome.SKIPPED.message -> ++skippedTasksCount
                        TaskExecutionOutcome.NO_SOURCE.message -> ++noSourceTasksCount
                    }
                    if (result.cachingDisabledReasonCategory == null &&
                        (TaskExecutionOutcome.EXECUTED.message == result.skipMessage ||
                                TaskExecutionOutcome.FROM_CACHE.message == result.skipMessage)
                    ) {
                        ++requestedFromCacheTasksCount
                    }
                } else {
                    ++lifecycleTasksCount
                }
            }
        }

        fun build(): TasksData = TasksData(
            runTasksCount = runTasksCount,
            executedTasksCount = executedTasksCount,
            fromCacheTasksCount = fromCacheTasksCount,
            upToDateTasksCount = upToDateTasksCount,
            skippedTasksCount = skippedTasksCount,
            noSourceTasksCount = noSourceTasksCount,
            lifecycleTasksCount = lifecycleTasksCount,
            requestedFromCacheTasksCount = requestedFromCacheTasksCount,
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy