kotlinx.kover.gradle.plugin.dsl.internal.KoverReportExtension.kt Maven / Gradle / Ivy
/*
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.kover.gradle.plugin.dsl.internal
import kotlinx.kover.gradle.plugin.appliers.reports.androidReports
import kotlinx.kover.gradle.plugin.appliers.defaultReports
import kotlinx.kover.gradle.plugin.dsl.*
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.model.*
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.*
import java.io.*
import javax.inject.*
internal open class KoverReportExtensionImpl @Inject constructor(
private val objects: ObjectFactory,
private val layout: ProjectLayout
) : KoverReportExtension {
internal var filters: KoverReportFiltersImpl? = null
internal var verify: KoverVerificationRulesConfigImpl? = null
internal val default: KoverDefaultReportsConfigImpl = objects.defaultReports(layout)
internal val namedReports: MutableMap = mutableMapOf()
override fun filters(config: Action) {
if (filters == null) {
filters = objects.newInstance(objects)
}
filters?.also { config(it) }
}
override fun verify(config: Action) {
if (verify == null) {
verify = objects.newInstance(objects)
}
verify?.also { config(it) }
}
override fun defaults(config: Action) {
config(default)
}
override fun androidReports(variant: String, config: Action) {
val report = namedReports.getOrPut(variant) { objects.androidReports(variant, layout) }
config(report)
}
}
internal open class KoverDefaultReportsConfigImpl @Inject constructor(objects: ObjectFactory) :
KoverReportsConfigImpl(objects), KoverDefaultReportsConfig {
internal val merged: MutableSet = mutableSetOf()
init {
html.onCheck = false
xml.onCheck = false
}
override fun mergeWith(otherVariant: String) {
merged += otherVariant
}
}
internal open class KoverReportsConfigImpl @Inject constructor(private val objects: ObjectFactory) :
KoverReportsConfig {
internal val html: KoverHtmlReportConfigImpl = objects.newInstance(objects)
internal val xml: KoverXmlReportConfigImpl = objects.newInstance(objects)
internal val binary: KoverBinaryReportConfigImpl = objects.newInstance(objects)
internal var verify: KoverVerifyReportConfigImpl? = null
internal val log: KoverLogReportConfigImpl = objects.newInstance(objects)
internal var filters: KoverReportFiltersImpl? = null
override fun filters(config: Action) {
if (filters == null) {
filters = objects.newInstance(objects)
}
filters?.also { config(it) }
}
override fun html(config: Action) {
config(html)
}
override fun xml(config: Action) {
config(xml)
}
override fun binary(config: Action) {
config(binary)
}
override fun verify(config: Action) {
if (verify == null) {
verify = objects.newInstance(objects)
}
verify?.also { config(it) }
}
override fun log(config: Action) {
config(log)
}
}
internal open class KoverHtmlReportConfigImpl @Inject constructor(private val objects: ObjectFactory) :
KoverHtmlReportConfig {
override var onCheck: Boolean = false
internal var filters: KoverReportFiltersImpl? = null
override var title: String? = null
override var charset: String? = null
internal val reportDirProperty: Property = objects.property()
override fun filters(config: Action) {
if (filters == null) {
filters = objects.newInstance(objects)
}
filters?.also { config(it) }
}
override fun setReportDir(dir: File) {
reportDirProperty.set(dir)
}
override fun setReportDir(dir: Provider) {
reportDirProperty.set(dir.map { it.asFile })
}
}
internal open class KoverXmlReportConfigImpl @Inject constructor(
private val objects: ObjectFactory
) : KoverXmlReportConfig {
override val title: Property = objects.property()
override var onCheck: Boolean = false
internal var filters: KoverReportFiltersImpl? = null
override fun filters(config: Action) {
if (filters == null) {
filters = objects.newInstance(objects)
}
filters?.also { config(it) }
}
override fun setReportFile(xmlFile: File) {
reportFileProperty.set(xmlFile)
}
override fun setReportFile(xmlFile: Provider) {
reportFileProperty.set(xmlFile.map { it.asFile })
}
internal val reportFileProperty: Property = objects.property()
}
internal open class KoverBinaryReportConfigImpl @Inject constructor(
private val objects: ObjectFactory
) : KoverBinaryReportConfig {
internal var filters: KoverReportFiltersImpl? = null
override val onCheck: Property = objects.property()
override val file: RegularFileProperty = objects.fileProperty()
override fun filters(config: Action) {
if (filters == null) {
filters = objects.newInstance(objects)
}
filters?.also { config(it) }
}
}
internal open class KoverVerifyReportConfigImpl @Inject constructor(
objects: ObjectFactory,
) : KoverVerificationRulesConfigImpl(objects), KoverVerifyReportConfig {
override var onCheck: Boolean = false
internal var filters: KoverReportFiltersImpl? = null
}
internal open class KoverVerifyRuleImpl @Inject constructor(private val objects: ObjectFactory) : KoverVerifyRule {
internal var filters: KoverReportFiltersImpl? = null
override var isEnabled: Boolean = true
@Deprecated(message = "Removed")
override var name: String? = null
override var entity: GroupingEntityType = GroupingEntityType.APPLICATION
internal var internalName: String? = null
override fun filters(config: Action) {
val filtersToConfigure = filters ?: (objects.newInstance(objects).also { filters = it })
config(filtersToConfigure)
}
override fun minBound(minValue: Int, metric: MetricType, aggregation: AggregationType) {
val newBound = objects.newInstance()
newBound.minValue = minValue
newBound.metric = metric
newBound.aggregation = aggregation
bounds += newBound
}
override fun maxBound(maxValue: Int, metric: MetricType, aggregation: AggregationType) {
val newBound = objects.newInstance()
newBound.maxValue = maxValue
newBound.metric = metric
newBound.aggregation = aggregation
bounds += newBound
}
override fun minBound(minValue: Int) {
val newBound = objects.newInstance()
newBound.minValue = minValue
bounds += newBound
}
override fun maxBound(maxValue: Int) {
val newBound = objects.newInstance()
newBound.maxValue = maxValue
bounds += newBound
}
override fun bound(minValue: Int, maxValue: Int, metric: MetricType, aggregation: AggregationType) {
val newBound = objects.newInstance()
newBound.minValue = minValue
newBound.maxValue = maxValue
newBound.metric = metric
newBound.aggregation = aggregation
bounds += newBound
}
override fun bound(config: Action) {
val newBound = objects.newInstance()
config(newBound)
bounds += newBound
}
internal val bounds: MutableList = mutableListOf()
}
internal open class KoverVerifyBoundImpl : KoverVerifyBound {
override var minValue: Int? = null
override var maxValue: Int? = null
override var metric: MetricType = MetricType.LINE
override var aggregation: AggregationType = AggregationType.COVERED_PERCENTAGE
}
internal open class KoverLogReportConfigImpl @Inject constructor(private val objects: ObjectFactory): KoverLogReportConfig {
internal var filters: KoverReportFiltersImpl? = null
override var onCheck: Boolean = false
override var header: String? = null
override var format: String? = null
override var groupBy: GroupingEntityType? = null
override var coverageUnits: MetricType? = null
override var aggregationForGroup: AggregationType? = null
override fun filters(config: Action) {
val filtersToConfigure = filters ?: (objects.newInstance(objects).also { filters = it })
config(filtersToConfigure)
}
}
internal open class KoverReportFiltersImpl @Inject constructor(
objects: ObjectFactory
) : KoverReportFilters {
override fun excludes(config: Action) {
config(excludesIntern)
}
override fun includes(config: Action) {
config(includesIntern)
}
internal val excludesIntern: KoverReportFilterImpl = objects.newInstance()
internal val includesIntern: KoverReportFilterImpl = objects.newInstance()
}
internal open class KoverVerificationRulesConfigImpl @Inject constructor(
private val objects: ObjectFactory
) : KoverVerificationRulesConfig {
internal val rules: MutableList = mutableListOf()
override fun rule(config: Action) {
val newRule = objects.newInstance(objects)
config(newRule)
rules += newRule
}
override fun rule(name: String, config: Action) {
val newRule = objects.newInstance(objects)
newRule.internalName = name
config(newRule)
rules += newRule
}
}
internal open class KoverReportFilterImpl : KoverReportFilter {
internal val classes: MutableSet = mutableSetOf()
internal val annotations: MutableSet = mutableSetOf()
override fun classes(vararg names: String) {
classes += names
}
override fun classes(names: Iterable) {
classes += names
}
override fun packages(vararg names: String) {
names.forEach {
classes += "$it.*"
}
}
override fun packages(names: Iterable) {
names.forEach {
classes += "$it.*"
}
}
override fun annotatedBy(vararg annotationName: String) {
annotations += annotationName
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy