Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes executionData file getting overridden #21

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,36 @@ import org.gradle.api.Task
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.io.File

open class JacocoTestKitExtension(private val project: Project) {
val jacocoRuntimePathProvider: Provider<String> = project.provider { project.configurations.getByName(Configurations.jacocoRuntime).asPath }

fun applyTo(configurationRuntime: String, taskProvider: TaskProvider<Task>) {
with(project) {
val destinationFile = taskProvider.map { task ->
val extension = task.extensions.getByType(JacocoTaskExtension::class.java)
val file = checkNotNull(extension.destinationFile) { "destinationFile is missing on task $name jacoco extension" }

File(file.parentFile, "${file.nameWithoutExtension}-gradle-runner.${file.extension}")
}

val jacocoTestKitPropertiesTask = tasks.register(
generatePropertiesTaskName(taskProvider.name),
GenerateJaCoCoTestKitProperties::class.java
) {
it.outputFile = File(buildDir, "testkit/${taskProvider.name}/testkit-gradle.properties")
it.destinationFile.set(
taskProvider.map {
task -> task.extensions.getByType(JacocoTaskExtension::class.java).destinationFile!!.path
}.get()
)
it.destinationFile.set(destinationFile.get().path)
it.jacocoRuntimePath.set(jacocoRuntimePathProvider)
}

dependencies.add(configurationRuntime, files(testKitDir(taskProvider.name)))
taskProvider.configure { it.dependsOn(jacocoTestKitPropertiesTask) }

tasks.withType(JacocoReport::class.java)
.matching { it.name == "jacoco${taskProvider.name.capitalize()}Report" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If provider name starts with i and default locale at runtime is set to Turkish or Azeri then capitalization will result in capital dotted İ so no match will be probably found.
Anyway we have a similar existing capitalize https://github.com/koral--/jacoco-gradle-testkit-plugin/pull/15#discussion_r418568736 so it's fine for now to leave it also here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this was the most controversial part of the change, as I generally don't like reference tasks by name miming their internal plugin logic to name them. But I couldn't find a way to archive this without making too much refactor on the current code.

.all { it.executionData(destinationFile) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JaCoCoTestKitPluginFunctionalTest {
.startsWith("\"-javaagent:")
.contains("=destfile=")
.contains(JacocoPlugin.DEFAULT_JACOCO_VERSION)
.endsWith("test.exec\"")
.endsWith("test-gradle-runner.exec\"")
}

@Test
Expand Down Expand Up @@ -119,7 +119,7 @@ class JaCoCoTestKitPluginFunctionalTest {

val args = readArgsFromProperties()
assertThat(args)
.endsWith("integration.exec\"")
.endsWith("integration-gradle-runner.exec\"")
}

@Test
Expand All @@ -134,7 +134,7 @@ class JaCoCoTestKitPluginFunctionalTest {

val args = readArgsFromProperties("integrationTest")
assertThat(args)
.endsWith("integrationTest.exec\"")
.endsWith("integrationTest-gradle-runner.exec\"")
}

private fun readArgsFromProperties(taskName: String = "test"): String {
Expand Down