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

kotlinx.kover.gradle.aggregation.settings.KoverParametersProcessor.kt Maven / Gradle / Ivy

There is a newer version: 0.9.0-RC
Show newest version
/*
 * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package kotlinx.kover.gradle.aggregation.settings

import kotlinx.kover.gradle.aggregation.settings.dsl.VerificationRuleSettings
import kotlinx.kover.gradle.aggregation.settings.dsl.intern.KoverSettingsExtensionImpl
import org.gradle.api.provider.HasMultipleValues
import org.gradle.api.provider.ProviderFactory


internal object KoverParametersProcessor {
    fun process(settingsExtension: KoverSettingsExtensionImpl, providers: ProviderFactory) {
        val koverProperty = providers.gradleProperty("kover")
        if (koverProperty.isPresent) {
            val disabled = koverProperty.get().equals("false", ignoreCase = true)
            settingsExtension.coverageIsEnabled.set(!disabled)
        }
        val verifyWarn = providers.gradleProperty("kover.verify.warn")
        if (verifyWarn.isPresent) {
            verifyWarn.get().lowercase().toBooleanStrictOrNull()?.also { warn ->
                settingsExtension.reports.verify.warningInsteadOfFailure.set(warn)
            }
        }
        val ruleSettings: MutableList Unit> = mutableListOf()
        val minVerify = providers.gradleProperty("kover.verify.min")
        if (minVerify.isPresent) {
            minVerify.get().toIntOrNull()?.also { min ->
                ruleSettings += { bound { minValue.set(min) } }
            }
        }
        val maxVerify = providers.gradleProperty("kover.verify.max")
        if (maxVerify.isPresent) {
            maxVerify.get().toIntOrNull()?.also { max ->
                ruleSettings += { bound { maxValue.set(max) } }
            }
        }
        if (ruleSettings.isNotEmpty()) {
            settingsExtension.reports.verify.rule("CLI parameters") {
                ruleSettings.forEach { setting -> setting() }
            }
        }




        settingsExtension.reports.includedProjects.readAppendableArgument(providers, "kover.projects.includes")
        settingsExtension.reports.excludedProjects.readAppendableArgument(providers, "kover.projects.excludes")
        settingsExtension.reports.excludedClasses.readAppendableArgument(providers, "kover.classes.excludes")
        settingsExtension.reports.includedClasses.readAppendableArgument(providers, "kover.classes.includes")
        settingsExtension.reports.excludesAnnotatedBy.readAppendableArgument(providers, "kover.classes.excludesAnnotated")
        settingsExtension.reports.includesAnnotatedBy.readAppendableArgument(providers, "kover.classes.includesAnnotated")
    }

    private fun HasMultipleValues.readAppendableArgument(providers: ProviderFactory, propertyName: String) {
        val propertyProvider = providers.gradleProperty(propertyName)
        if (propertyProvider.isPresent) {
            val arg = propertyProvider.get().parseCollection()
            if (!arg.append) {
                empty()
            }
            addAll(arg.values)
        }
    }

    private fun String.parseCollection(): ArgCollection {
        val append = startsWith('+')
        val str = if (append) substring(1) else this
        val values = str.split(',')
        return ArgCollection(append, values)
    }

    private data class ArgCollection(val append: Boolean, val values: List)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy