Skip to content

Commit

Permalink
Added USAGE attribute to all Kover configurations
Browse files Browse the repository at this point in the history
Fixes #678
  • Loading branch information
shanshin committed Aug 26, 2024
1 parent 9d72c74 commit 2da38dd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class LoggingTaskTests {
run(":koverLog") {
checkOutcome("koverPrintCoverage", "SUCCESS")
taskOutput("koverPrintCoverage") {
assertEquals("application line coverage: 57.1429%\n\n", this)
assertContains(this, "application line coverage: 57.1429%\n\n")
}
}
}
Expand All @@ -59,7 +59,7 @@ internal class LoggingTaskTests {
run(":koverLog") {
checkOutcome("koverPrintCoverage", "SUCCESS")
taskOutput("koverPrintCoverage") {
assertEquals("application line coverage: 50%\n\n", this)
assertContains(this, "application line coverage: 50%\n\n")
}
}
}
Expand All @@ -84,7 +84,7 @@ internal class LoggingTaskTests {
run(":koverLog") {
checkOutcome("koverPrintCoverage", "SUCCESS")
taskOutput("koverPrintCoverage") {
assertEquals("Custom header\nMy format for application is 57.1429\n\n", this)
assertContains(this, "Custom header\nMy format for application is 57.1429\n\n")
}
}
}
Expand Down Expand Up @@ -112,12 +112,12 @@ internal class LoggingTaskTests {
run(":koverLog") {
checkOutcome("koverPrintCoverage", "SUCCESS")
taskOutput("koverPrintCoverage") {
assertEquals(
assertContains(
this,
"Coverage for classes:\n" +
"Class org.jetbrains.ExampleClass covered instructions=5\n" +
"Class org.jetbrains.SecondClass covered instructions=5\n" +
"Class org.jetbrains.Unused covered instructions=0\n\n",
this
"Class org.jetbrains.Unused covered instructions=0\n\n"
)
}
}
Expand Down Expand Up @@ -146,12 +146,12 @@ internal class LoggingTaskTests {
run(":koverLog") {
checkOutcome("koverPrintCoverage", "SUCCESS")
taskOutput("koverPrintCoverage") {
assertEquals(
assertContains(
this,
"Coverage for classes:\n" +
"Class org.jetbrains.ExampleClass covered instructions=7\n" +
"Class org.jetbrains.SecondClass covered instructions=7\n" +
"Class org.jetbrains.Unused covered instructions=0\n\n",
this
"Class org.jetbrains.Unused covered instructions=0\n\n"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.commons.artifacts

import org.gradle.api.attributes.*

internal interface KoverUsageAttr: Usage {
companion object {
const val VALUE = "kover"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kotlinx.kover.gradle.aggregation.project

import kotlinx.kover.features.jvm.KoverFeatures
import kotlinx.kover.gradle.aggregation.commons.artifacts.*
import kotlinx.kover.gradle.aggregation.commons.artifacts.CompilationInfo
import kotlinx.kover.gradle.aggregation.commons.artifacts.KoverContentAttr
import kotlinx.kover.gradle.aggregation.commons.artifacts.asConsumer
Expand All @@ -25,10 +26,12 @@ import kotlinx.kover.gradle.plugin.commons.KoverCriticalException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.attributes.Usage
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import java.io.File
Expand All @@ -49,6 +52,7 @@ internal class KoverProjectGradlePlugin : Plugin<Project> {
val jarConfig = configurations.create("agentJarSource") {
asConsumer()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KoverUsageAttr.VALUE))
attribute(KoverContentAttr.ATTRIBUTE, KoverContentAttr.AGENT_JAR)
}
extendsFrom(koverJarDependency)
Expand Down Expand Up @@ -138,6 +142,7 @@ internal class KoverProjectGradlePlugin : Plugin<Project> {
configurations.register("KoverArtifactProducer") {
asProducer()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KoverUsageAttr.VALUE))
attribute(KoverContentAttr.ATTRIBUTE, KoverContentAttr.LOCAL_ARTIFACT)
}

Expand Down Expand Up @@ -165,6 +170,7 @@ internal class KoverProjectGradlePlugin : Plugin<Project> {
configurations.register("AgentJar") {
asProducer()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KoverUsageAttr.VALUE))
attribute(KoverContentAttr.ATTRIBUTE, KoverContentAttr.AGENT_JAR)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kotlinx.kover.gradle.aggregation.settings

import kotlinx.kover.gradle.aggregation.commons.artifacts.KoverContentAttr
import kotlinx.kover.gradle.aggregation.commons.artifacts.KoverUsageAttr
import kotlinx.kover.gradle.aggregation.commons.artifacts.asConsumer
import kotlinx.kover.gradle.aggregation.commons.artifacts.asDependency
import kotlinx.kover.gradle.aggregation.commons.names.KoverPaths
Expand All @@ -16,11 +17,13 @@ import kotlinx.kover.gradle.aggregation.settings.tasks.KoverHtmlReportTask
import kotlinx.kover.gradle.aggregation.settings.tasks.KoverXmlReportTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.attributes.Usage
import org.gradle.api.initialization.ProjectDescriptor
import org.gradle.api.initialization.Settings
import org.gradle.api.model.ObjectFactory
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.support.serviceOf

Expand All @@ -42,6 +45,9 @@ internal class KoverSettingsGradlePlugin: Plugin<Settings> {

val agentDependency = configurations.create(SettingsNames.DEPENDENCY_AGENT) {
asDependency()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KoverUsageAttr.VALUE))
}
}
dependencies.add(agentDependency.name, rootProject)

Expand All @@ -58,6 +64,9 @@ internal class KoverSettingsGradlePlugin: Plugin<Settings> {

val dependencyConfig = configurations.create(KOVER_DEPENDENCY_NAME) {
asDependency()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KoverUsageAttr.VALUE))
}
}
val rootDependencies = dependencies
settings.rootProject.walkSubprojects { descriptor ->
Expand All @@ -67,6 +76,7 @@ internal class KoverSettingsGradlePlugin: Plugin<Settings> {
val artifacts = configurations.create("koverArtifactsCollector") {
asConsumer()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(KoverUsageAttr.VALUE))
attribute(KoverContentAttr.ATTRIBUTE, KoverContentAttr.LOCAL_ARTIFACT)
}
extendsFrom(dependencyConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

package kotlinx.kover.gradle.plugin.appliers

import kotlinx.kover.gradle.aggregation.commons.artifacts.KoverUsageAttr
import kotlinx.kover.gradle.plugin.appliers.tasks.VariantReportsSet
import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.dsl.internal.KoverProjectExtensionImpl
import kotlinx.kover.gradle.plugin.tasks.services.KoverAgentJarTask
import kotlinx.kover.gradle.plugin.tools.CoverageToolFactory
import org.gradle.api.Project
import org.gradle.api.attributes.Usage
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
Expand All @@ -21,6 +23,9 @@ import org.gradle.kotlin.dsl.register
internal fun prepare(project: Project): KoverContext {
val koverBucketConfiguration = project.configurations.create(KOVER_DEPENDENCY_NAME) {
asBucket()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(KoverUsageAttr.VALUE))
}
}

// Project always consumes its own artifacts
Expand Down Expand Up @@ -48,6 +53,7 @@ internal fun prepare(project: Project): KoverContext {
attributes {
// common Kover artifact attributes
attribute(VariantNameAttr.ATTRIBUTE, project.objects.named("!kover##__empty__##"))
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(KoverUsageAttr.VALUE))
attribute(ProjectPathAttr.ATTRIBUTE, project.objects.named(project.path))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package kotlinx.kover.gradle.plugin.appliers.artifacts

import kotlinx.kover.gradle.aggregation.commons.artifacts.KoverUsageAttr
import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.dsl.internal.KoverVariantConfigImpl
import kotlinx.kover.gradle.plugin.appliers.origin.VariantOrigin
Expand All @@ -13,6 +14,7 @@ import kotlinx.kover.gradle.plugin.tools.CoverageTool
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.attributes.Usage
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.named
Expand Down Expand Up @@ -49,6 +51,7 @@ internal sealed class AbstractVariantArtifacts(
asProducer()
attributes {
// common Kover artifact attributes
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(KoverUsageAttr.VALUE))
attribute(VariantNameAttr.ATTRIBUTE, project.objects.named(variantName))
attribute(ProjectPathAttr.ATTRIBUTE, project.objects.named(project.path))
}
Expand All @@ -61,6 +64,9 @@ internal sealed class AbstractVariantArtifacts(

consumerConfiguration = project.configurations.register(externalArtifactConfigurationName(variantName)) {
asConsumer()
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(KoverUsageAttr.VALUE))
}
if (koverBucketConfiguration != null) {
extendsFrom(koverBucketConfiguration)
}
Expand Down

0 comments on commit 2da38dd

Please sign in to comment.