Skip to content

Commit 1d6f64a

Browse files
authored
Fixed Stream closed error when generating Kover HTML report
When generating an HTML report, errors sometimes occur when reading the freemarker template from resources. The exact cause of the error has not yet been determined (relates to the Gradle isolated class loaders), but it disappears when you try to read again. In some cases, it is necessary to increase the number of repetitions, so this setting was made in Kover Gradle plugin. Fixes #510 PR #540
1 parent f0d57ca commit 1d6f64a

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22

3-
intellij-coverage = "1.0.741"
3+
intellij-coverage = "1.0.748"
44
junit = "5.9.0"
55
kotlinx-bcv = "0.13.2"
66
kotlinx-dokka = "1.8.10"

kover-cli/src/main/kotlin/kotlinx/kover/cli/commands/ReportCommand.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ internal class ReportCommand : Command {
4747
@Option(name = "--html", usage = "generate a HTML report in the specified path", metaVar = "<html-dir>")
4848
private var htmlDir: File? = null
4949

50-
@Option(name = "--title", usage = "title in the HTML report", metaVar = "<html-title>")
51-
private var htmlTitle: String? = null
50+
@Option(name = "--title", usage = "title in the HTML or XML report", metaVar = "<title>")
51+
private var title: String? = null
5252

5353
@Option(
5454
name = "--include",
@@ -85,15 +85,15 @@ internal class ReportCommand : Command {
8585
var fail = false
8686
if (xmlFile != null) {
8787
try {
88-
ReportApi.xmlReport(xmlFile, binaryReports, outputRoots, sourceRoots, filters)
88+
ReportApi.xmlReport(xmlFile, title ?: "Kover XML Report", binaryReports, outputRoots, sourceRoots, filters)
8989
} catch (e: IOException) {
9090
fail = true
9191
errorWriter.println("XML generation failed: " + e.message)
9292
}
9393
}
9494
if (htmlDir != null) {
9595
try {
96-
ReportApi.htmlReport(htmlDir, htmlTitle, null, binaryReports, outputRoots, sourceRoots, filters)
96+
ReportApi.htmlReport(htmlDir, title, null, binaryReports, outputRoots, sourceRoots, filters)
9797
} catch (e: IOException) {
9898
fail = true
9999
errorWriter.println("HTML generation failed: " + e.message)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public object KoverVersions {
1515
/**
1616
* Kover coverage tool version.
1717
*/
18-
public const val KOVER_TOOL_VERSION = "1.0.741"
18+
public const val KOVER_TOOL_VERSION = "1.0.748"
1919

2020
/**
2121
* JaCoCo coverage tool version used by default.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ internal abstract class XmlReportAction : AbstractReportAction<XmlReportParamete
5353

5454
ReportApi.xmlReport(
5555
parameters.xmlFile.get().asFile,
56+
parameters.projectPath.get(),
5657
files.reports.toList(),
5758
files.outputs.toList(),
5859
files.sources.toList(),
@@ -69,6 +70,10 @@ internal abstract class HtmlReportAction : AbstractReportAction<HtmlReportParame
6970
val files = parameters.files.get()
7071
val filters = parameters.filters.get()
7172

73+
// repeat reading freemarker temple from resources if error occurred, see https://github.com/Kotlin/kotlinx-kover/issues/510
74+
// the values are selected empirically so that the maximum report generation time is not much more than a second
75+
ReportApi.setFreemarkerRetry(7, 150)
76+
7277
ReportApi.htmlReport(
7378
parameters.htmlDir.get().asFile,
7479
parameters.title.get(),

0 commit comments

Comments
 (0)