Skip to content

Commit

Permalink
Make configuration cache happy
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 11, 2024
1 parent 176c95c commit ba08bd2
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import com.gradle.develocity.agent.gradle.internal.test.PredictiveTestSelectionConfigurationInternal
import com.gradle.develocity.agent.gradle.test.PredictiveTestSelectionMode
import org.gradle.api.tasks.PathSensitivity.NONE
Expand All @@ -16,25 +17,34 @@ var openTestReportingCliClasspath = configurations.resolvable("openTestReporting
extendsFrom(openTestReportingCli.get())
}

val htmlReportFile = layout.buildDirectory.file("reports/open-test-report.html")
val eventXmlFiles =
files(tasks.withType<Test>().map { it.reports.junitXml.outputLocation.get().asFileTree.matching { include("junit-platform-events-*.xml") } })

val generateOpenTestHtmlReport by tasks.registering(JavaExec::class) {
mustRunAfter(tasks.withType<Test>())
mainClass.set("org.opentest4j.reporting.cli.ReportingCli")
args("html-report")
classpath(openTestReportingCliClasspath)
outputs.file(htmlReportFile)
inputs.files(eventXmlFiles).withPathSensitivity(NONE).skipWhenEmpty()
argumentProviders += CommandLineArgumentProvider {
listOf(
"--output",
htmlReportFile.get().asFile.absolutePath
) + eventXmlFiles.files.map { it.absolutePath }.toList()
argumentProviders += objects.newInstance(HtmlReportParameters::class).apply {
eventXmlFiles.from(tasks.withType<Test>().map {
objects.fileTree()
.from(it.reports.junitXml.outputLocation)
.include("junit-platform-events-*.xml")
})
outputLocation = layout.buildDirectory.file("reports/open-test-report.html")
}
}

abstract class HtmlReportParameters : CommandLineArgumentProvider {

@get:InputFiles
@get:PathSensitive(NONE)
abstract val eventXmlFiles: ConfigurableFileCollection

@get:OutputFile
abstract val outputLocation: RegularFileProperty

override fun asArguments() = listOf("--output", outputLocation.get().asFile.absolutePath) +
eventXmlFiles.map { it.absolutePath }.toList()
}

tasks.withType<Test>().configureEach {
useJUnitPlatform {
includeEngines("junit-jupiter")
Expand Down Expand Up @@ -106,10 +116,9 @@ tasks.withType<Test>().configureEach {
)
}

val reportFiles = objects.fileTree().from(reports.junitXml.outputLocation).matching { include("junit-platform-events-*.xml") }
doFirst {
files(reports.junitXml.outputLocation.get().asFileTree.matching {
include("junit-platform-events-*.xml")
}).files.forEach {
reportFiles.files.forEach {
Files.delete(it.toPath())
}
}
Expand Down

0 comments on commit ba08bd2

Please sign in to comment.