diff --git a/kover-gradle-plugin/api/kover-gradle-plugin.api b/kover-gradle-plugin/api/kover-gradle-plugin.api index f36cbdf8..c20d7ddf 100644 --- a/kover-gradle-plugin/api/kover-gradle-plugin.api +++ b/kover-gradle-plugin/api/kover-gradle-plugin.api @@ -304,6 +304,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverBinar } public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverHtmlReport : kotlinx/kover/gradle/plugin/dsl/tasks/KoverReport { + public abstract fun getReportDir ()Lorg/gradle/api/provider/Provider; } public abstract interface class kotlinx/kover/gradle/plugin/dsl/tasks/KoverLogReport : kotlinx/kover/gradle/plugin/dsl/tasks/KoverReport { diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/TaskInterfacesTests.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/TaskInterfacesTests.kt new file mode 100644 index 00000000..d3eb8c1d --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/TaskInterfacesTests.kt @@ -0,0 +1,82 @@ +/* + * 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.test.functional.cases + +import kotlinx.kover.gradle.plugin.test.functional.framework.runner.generateBuild +import kotlinx.kover.gradle.plugin.test.functional.framework.runner.runWithParams +import org.junit.jupiter.api.Test +import kotlin.test.assertTrue + +internal class TaskInterfacesTests { + + @Test + fun testDefaultHtmlDir() { + val build = generateBuild { dir -> + dir.resolve("settings.gradle.kts").createNewFile() + + dir.resolve("build.gradle.kts").writeText( + """ + import kotlinx.kover.gradle.plugin.dsl.tasks.KoverHtmlReport + + plugins { + kotlin("jvm") version "1.9.22" + id("org.jetbrains.kotlinx.kover") + } + + tasks.register("checkDir") { + doFirst { + val task = tasks.withType().matching { it.name == "koverHtmlReport" }.first() + if (task.reportDir.get().asFile != layout.buildDirectory.dir("reports/kover/html").get().asFile) { + throw Exception("Default directory differ, expect ${'$'}{layout.buildDirectory.dir("reports/kover/html").get().asFile} actual ${'$'}{task.reportDir.get().asFile}") + } + } + } + """.trimIndent() + ) + }.generate() + + val result = build.runWithParams("checkDir") + assertTrue(result.isSuccessful) + } + + @Test + fun testCustomHtmlDir() { + val build = generateBuild { dir -> + dir.resolve("settings.gradle.kts").createNewFile() + + dir.resolve("build.gradle.kts").writeText( + """ + import kotlinx.kover.gradle.plugin.dsl.tasks.KoverHtmlReport + + plugins { + kotlin("jvm") version "1.9.22" + id("org.jetbrains.kotlinx.kover") + } + + kover { + reports { + total { + html { + htmlDir.set(layout.buildDirectory.dir("customHtmlReport")) + } + } + } + } + + tasks.register("checkDir") { + doFirst { + val task = tasks.withType().matching { it.name == "koverHtmlReport" }.first() + if (task.reportDir.get().asFile != layout.buildDirectory.dir("customHtmlReport").get().asFile) { + throw Exception("Custom directory differ, expect ${'$'}{layout.buildDirectory.dir("customHtmlReport").get().asFile} actual ${'$'}{task.reportDir.get().asFile}") + } + } + } + """.trimIndent() + ) + }.generate() + + val result = build.runWithParams("checkDir") + assertTrue(result.isSuccessful) + } +} diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/tasks/KoverTasks.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/tasks/KoverTasks.kt index fc0e8e24..a3b8e27f 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/tasks/KoverTasks.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/tasks/KoverTasks.kt @@ -5,6 +5,9 @@ package kotlinx.kover.gradle.plugin.dsl.tasks import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.OutputDirectory /** * Common interface for all Kover report tasks. @@ -19,7 +22,13 @@ interface KoverXmlReport: KoverReport /** * Interface for Kover HTML report generation tasks. */ -interface KoverHtmlReport: KoverReport +interface KoverHtmlReport: KoverReport { + /** + * The directory where the HTML report will be saved. + */ + @get:OutputDirectory + val reportDir: Provider +} /** * Interface for Kover tasks that print coverage to the build log. diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tasks/reports/KoverHtmlTask.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tasks/reports/KoverHtmlTask.kt index e34174f8..b34f2e9d 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tasks/reports/KoverHtmlTask.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/tasks/reports/KoverHtmlTask.kt @@ -14,7 +14,7 @@ import java.net.URI @CacheableTask internal abstract class KoverHtmlTask : AbstractKoverReportTask(), KoverHtmlReport { @get:OutputDirectory - abstract val reportDir: DirectoryProperty + abstract override val reportDir: DirectoryProperty @get:Input abstract val title: Property