Skip to content

Commit ec84816

Browse files
authored
Added the ability to specify a header for an XML report
Resolves #527 PR #539
1 parent 1d6f64a commit ec84816

File tree

13 files changed

+101
-10
lines changed

13 files changed

+101
-10
lines changed

docs/gradle-plugin/configuring.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ koverReport {
9494
// generate an XML report when running the `check` task
9595
onCheck = false
9696

97+
// XML report title (the location depends on the library)
98+
title.set("Custom XML report title")
99+
97100
// XML report file
98101
setReportFile(layout.buildDirectory.file("my-project-report/result.xml"))
99102

@@ -283,6 +286,9 @@ koverReport {
283286
// generate an XML report when running the `check` task
284287
onCheck = false
285288

289+
// XML report title (the location depends on the library)
290+
title.set("Custom XML report title")
291+
286292
// XML report file
287293
setReportFile(layout.buildDirectory.file("my-project-report/result.xml"))
288294

kover-gradle-plugin/api/kover-gradle-plugin.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverXmlReportCo
342342
public abstract fun filters (Lorg/gradle/api/Action;)V
343343
public abstract fun getOnCheck ()Z
344344
public fun getReportFile ()Ljava/lang/Void;
345+
public abstract fun getTitle ()Lorg/gradle/api/provider/Property;
345346
public fun overrideFilters (Lkotlin/jvm/functions/Function0;)V
346347
public abstract fun setOnCheck (Z)V
347348
public abstract fun setReportFile (Ljava/io/File;)V
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
package kotlinx.kover.gradle.plugin.test.functional.cases
5+
6+
import kotlinx.kover.gradle.plugin.test.functional.framework.checker.defaultReportsDir
7+
import kotlinx.kover.gradle.plugin.test.functional.framework.configurator.*
8+
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.*
9+
import kotlin.test.assertContains
10+
11+
internal class XmlReportTests {
12+
13+
@SlicedGeneratedTest(allTools = true)
14+
fun BuildConfigurator.testDefaultXmlTitle() {
15+
addProjectWithKover {
16+
17+
}
18+
19+
addProjectWithKover(":nested") {
20+
sourcesFrom("simple")
21+
}
22+
23+
run("koverXmlReport") {
24+
subproject(":nested") {
25+
file("$defaultReportsDir/report.xml") {
26+
assertContains(readText(), "Kover Gradle Plugin XML report for :nested")
27+
}
28+
}
29+
}
30+
}
31+
32+
@SlicedGeneratedTest(allTools = true)
33+
fun BuildConfigurator.testCustomXmlTitle() {
34+
val title = "My Custom XML title"
35+
36+
addProjectWithKover {
37+
38+
}
39+
40+
addProjectWithKover(":nested") {
41+
sourcesFrom("simple")
42+
43+
koverReport {
44+
defaults {
45+
xml {
46+
this.title.set("My Custom XML title")
47+
}
48+
}
49+
}
50+
}
51+
52+
run("koverXmlReport") {
53+
subproject(":nested") {
54+
file("$defaultReportsDir/report.xml") {
55+
assertContains(readText(), title)
56+
}
57+
}
58+
}
59+
}
60+
61+
}

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/framework/writer/KoverReportWriter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ internal class KoverXmlReportConfigWriter(private val writer: FormattedWriter) :
135135
field = value
136136
}
137137

138+
override val title: Property<String> = PropertyWriter("title", writer)
139+
138140
override fun setReportFile(xmlFile: File) {
139141
writer.assign("reportFile", xmlFile.forScript())
140142
}

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/reports/ReportsVariantApplier.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ internal abstract class ReportsVariantApplier(
129129
) {
130130
reportConfig.binary.onCheck.convention(false)
131131
reportConfig.binary.file.convention(project.layout.buildDirectory.file(binaryReportPath(variantName)))
132+
reportConfig.xml.title.convention("Kover Gradle Plugin XML report for ${project.path}")
132133

133134
val runOnCheck = mutableListOf<Any>()
134135

@@ -146,6 +147,7 @@ internal abstract class ReportsVariantApplier(
146147

147148
xmlTask.configure {
148149
reportFile.convention(project.layout.file(reportConfig.xml.reportFileProperty))
150+
title.convention(reportConfig.xml.title)
149151
filters.set((reportConfig.xml.filters ?: reportConfig.filters ?: commonFilters).convert())
150152
}
151153
if (reportConfig.xml.onCheck) {

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverReportExtension.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public interface KoverReportsConfig {
221221
* }
222222
*
223223
* onCheck = false
224+
* title.set("Custom XML report title")
224225
* setReportFile(layout.buildDirectory.file("my-project-report/result.xml"))
225226
* }
226227
* ```
@@ -621,6 +622,9 @@ public interface KoverHtmlReportConfig {
621622
* // Generate an XML report when running the `check` task
622623
* onCheck = false
623624
*
625+
* // XML report title (the location depends on the library)
626+
* title.set("Custom XML report title")
627+
*
624628
* // Specify file to generate XML report
625629
* setReportFile(layout.buildDirectory.file("my-xml-report.xml"))
626630
* }
@@ -633,6 +637,13 @@ public interface KoverXmlReportConfig {
633637
*/
634638
public fun filters(config: Action<KoverReportFilters>)
635639

640+
/**
641+
* Specify title in XML report.
642+
*
643+
* `"Kover Gradle Plugin XML report for $projectPath"` by default.
644+
*/
645+
public val title: Property<String>
646+
636647
/**
637648
* Generate an XML report when running the `check` task.
638649
*/

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/internal/KoverReportExtension.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ internal open class KoverHtmlReportConfigImpl @Inject constructor(private val ob
139139
internal open class KoverXmlReportConfigImpl @Inject constructor(
140140
private val objects: ObjectFactory
141141
) : KoverXmlReportConfig {
142+
override val title: Property<String> = objects.property()
143+
142144
override var onCheck: Boolean = false
143145

144146
internal var filters: KoverReportFiltersImpl? = null

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tasks/reports/KoverXmlTask.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
package kotlinx.kover.gradle.plugin.tasks.reports
66

77
import org.gradle.api.file.*
8+
import org.gradle.api.provider.Property
89
import org.gradle.api.tasks.*
910

1011
@CacheableTask
1112
internal abstract class KoverXmlTask : AbstractKoverReportTask() {
1213
@get:OutputFile
1314
internal abstract val reportFile: RegularFileProperty
1415

16+
@get:Input
17+
abstract val title: Property<String>
18+
1519
@TaskAction
1620
fun generate() {
1721
val xmlFile = reportFile.get().asFile
1822
xmlFile.parentFile.mkdirs()
19-
tool.get().xmlReport(xmlFile, context())
23+
tool.get().xmlReport(xmlFile, title.get(), context())
2024
}
2125
}

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/CoverageTool.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ internal interface CoverageTool {
9898
/**
9999
* Generate XML report.
100100
*/
101-
fun xmlReport(xmlFile: File, context: ReportContext)
101+
fun xmlReport(xmlFile: File, title: String, context: ReportContext)
102102

103103
/**
104104
* Generate binary report in IntelliJ format (Kover-only).

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/jacoco/JacocoHtmlOrXmlReport.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ internal fun ReportContext.jacocoHtmlReport(htmlDir: File, title: String, charse
2121
}
2222
}
2323

24-
internal fun ReportContext.jacocoXmlReport(xmlFile: File) {
25-
callAntReport(projectPath) {
24+
internal fun ReportContext.jacocoXmlReport(xmlFile: File, title: String) {
25+
callAntReport(title) {
2626
xmlFile.parentFile.mkdirs()
2727
invokeMethod("xml", mapOf("destfile" to xmlFile))
2828
}

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/jacoco/JacocoTool.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ internal class JacocoTool(override val variant: CoverageToolVariant) : CoverageT
3535
return buildJvmAgentArgs(jarFile, binReportFile, excludedClasses)
3636
}
3737

38-
override fun xmlReport(xmlFile: File, context: ReportContext) {
39-
context.jacocoXmlReport(xmlFile)
38+
override fun xmlReport(xmlFile: File, title: String, context: ReportContext) {
39+
context.jacocoXmlReport(xmlFile, title)
4040
}
4141

4242
override fun htmlReport(htmlDir: File, title: String, charset: String?, context: ReportContext) {

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/kover/KoverHtmlOrXmlReport.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ internal fun ReportContext.koverHtmlReport(htmlReportDir: File, htmlTitle: Strin
2525
}
2626
}
2727

28-
internal fun ReportContext.koverXmlReport(xmlReportFile: File) {
28+
internal fun ReportContext.koverXmlReport(xmlReportFile: File, xmlTitle: String) {
2929
submitAction<XmlReportAction, XmlReportParameters> {
3030
xmlFile.set(xmlReportFile)
31+
title.convention(xmlTitle)
3132
filters.convention(this@koverXmlReport.filters)
3233

3334
files.convention(this@koverXmlReport.files)
@@ -39,6 +40,7 @@ internal fun ReportContext.koverXmlReport(xmlReportFile: File) {
3940

4041
internal interface XmlReportParameters : ReportParameters {
4142
val xmlFile: RegularFileProperty
43+
val title: Property<String>
4244
}
4345

4446
internal interface HtmlReportParameters : ReportParameters {
@@ -53,7 +55,7 @@ internal abstract class XmlReportAction : AbstractReportAction<XmlReportParamete
5355

5456
ReportApi.xmlReport(
5557
parameters.xmlFile.get().asFile,
56-
parameters.projectPath.get(),
58+
parameters.title.get(),
5759
files.reports.toList(),
5860
files.outputs.toList(),
5961
files.sources.toList(),

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tools/kover/KoverTool.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ internal class KoverTool(override val variant: CoverageToolVariant) : CoverageTo
3838
return buildJvmAgentArgs(jarFile, tempDir, binReportFile, excludedClasses)
3939
}
4040

41-
override fun xmlReport(xmlFile: File, context: ReportContext) {
42-
context.koverXmlReport(xmlFile)
41+
override fun xmlReport(xmlFile: File, title: String, context: ReportContext) {
42+
context.koverXmlReport(xmlFile, title)
4343
}
4444

4545
override fun htmlReport(htmlDir: File, title: String, charset: String?, context: ReportContext) {

0 commit comments

Comments
 (0)