Skip to content

Commit

Permalink
Fix compatibility with Gradle 7.6
Browse files Browse the repository at this point in the history
Remove dead code
Dependency versions bump

Closes #31
  • Loading branch information
koral-- committed May 4, 2023
1 parent 59ebd97 commit 3fc1d56
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 64 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.8.20'
id 'org.jetbrains.kotlin.jvm' version '1.8.21'
id 'com.gradle.plugin-publish' version '1.2.0'
id 'jacoco'
id 'java-gradle-plugin'
Expand Down Expand Up @@ -51,7 +51,7 @@ tasks.withType(Test).configureEach {
}

jacoco {
toolVersion '0.8.9'
toolVersion '0.8.10'
}

jacocoTestReport {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.droidsonroids.gradle.jacoco.testkit

import org.gradle.api.GradleException
import org.gradle.api.Project
import java.io.File

Expand All @@ -10,9 +9,5 @@ internal object Configurations {

internal fun Project.testKitDir(taskName: String = "test") = File(buildDir, "testkit/$taskName")

internal fun File.ensureParentExists() = with(parentFile) {
isDirectory || mkdirs() || throw GradleException("Could not create $path")
}

internal fun generatePropertiesTaskName(taskName: String) =
"generateJacoco${taskName.replaceFirstChar(Char::uppercase)}KitProperties"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.WriteProperties
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.util.GradleVersion

open class JacocoTestKitExtension(private val project: Project) {

Expand All @@ -22,7 +23,14 @@ open class JacocoTestKitExtension(private val project: Project) {
it.description = "Generates gradle.properties with JaCoCo java agent for TestKit"
it.comment = "Generated by pl.droidsonroids.jacoco.testkit"

it.destinationFile.set(layout.buildDirectory.file("testkit/${taskProvider.name}/testkit-gradle.properties"))
val testKitPropertiesFile =
layout.buildDirectory.file("testkit/${taskProvider.name}/testkit-gradle.properties")
if (GradleVersion.current() >= GradleVersion.version("8.1")) {
it.destinationFile.set(testKitPropertiesFile)
} else {
@Suppress("DEPRECATION")
it.outputFile = testKitPropertiesFile.get().asFile
}

it.property(
"org.gradle.jvmargs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
package pl.droidsonroids.gradle.jacoco.testkit

import org.assertj.core.api.Assertions.assertThat
import org.gradle.api.GradleException
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File

class CommonsTest {

@get:Rule
val temporaryFolder = TemporaryFolder()

@Test
fun `existing parent existence ensured`() {
val file = temporaryFolder.newFile()
assertThat(file.parentFile).isDirectory()
assertThat(file.ensureParentExists()).isTrue()
}

@Test
fun `non existent parent created`() {
val parent = temporaryFolder.newFolder()
assertThat(parent.delete()).isTrue()
val file = File(parent, "test")
assertThat(file.parentFile).doesNotExist()
assertThat(file.ensureParentExists()).isTrue()
assertThat(file.parentFile).isDirectory()
}

@Test(expected = GradleException::class)
fun `exception thrown if parent could not be created`() {
val file = temporaryFolder.newFile()
assertThat(file).isFile()
File(file, "test").ensureParentExists()
}

@Test
fun `test kit directory is located in build directory`() {
val project = ProjectBuilder.builder().build()
assertThat(project.testKitDir()).hasParent(File(project.buildDir, "testkit"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@ class JaCoCoTestKitPluginFunctionalTest {
fun `gradle properties file generated with default version`() {
temporaryFolder.newFile("build.gradle").fillFromResource("simple.gradle")
GradleRunner.create()
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()

val args = readArgsFromProperties()
assertThat(args)
.startsWith("\"-javaagent:")
.contains("=destfile=")
.contains(JacocoPlugin.DEFAULT_JACOCO_VERSION)
.endsWith("test.exec\"")
.startsWith("\"-javaagent:")
.contains("=destfile=")
.contains(JacocoPlugin.DEFAULT_JACOCO_VERSION)
.endsWith("test.exec\"")
}

@Test
fun `gradle properties file generated with explicit version`() {
temporaryFolder.newFile("build.gradle").fillFromResource("extension.gradle")
GradleRunner.create()
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()

val args = readArgsFromProperties()
assertThat(args)
.startsWith("\"-javaagent:")
.contains("=destfile=")
.contains("0.7.7.201606060606")
.endsWith(".exec\"")
.startsWith("\"-javaagent:")
.contains("=destfile=")
.contains("0.7.7.201606060606")
.endsWith(".exec\"")
}

@Test
Expand Down Expand Up @@ -87,13 +87,17 @@ class JaCoCoTestKitPluginFunctionalTest {

@Test
fun `plugin compatible with Gradle 7_6`() {
temporaryFolder.newFile("build.gradle").fillFromResource("simple.gradle")
GradleRunner.create()
temporaryFolder.newFile("build.gradle").fillFromResource("custom-task.gradle")
assertThat(
GradleRunner.create()
.withGradleVersion("7.6")
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()
.task(":$generateJacocoTestKitProperties")?.outcome
).isEqualTo(TaskOutcome.SUCCESS)
}

@Test
Expand Down Expand Up @@ -131,15 +135,15 @@ class JaCoCoTestKitPluginFunctionalTest {
fun `gradle properties file generated with custom destination file`() {
temporaryFolder.newFile("build.gradle").fillFromResource("custom-destination.gradle")
GradleRunner.create()
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()
.withProjectDir(temporaryFolder.root)
.withTestKitDir(temporaryFolder.newFolder())
.withArguments(generateJacocoTestKitProperties)
.withPluginClasspath()
.build()

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

@Test
Expand All @@ -158,7 +162,8 @@ class JaCoCoTestKitPluginFunctionalTest {
}

private fun readArgsFromProperties(taskName: String = "test"): String {
val propertiesFile = File(temporaryFolder.root, "build/testkit/$taskName/testkit-gradle.properties")
val propertiesFile =
File(temporaryFolder.root, "build/testkit/$taskName/testkit-gradle.properties")
val properties = Properties()
propertiesFile.inputStream().use { inputStream ->
properties.load(inputStream)
Expand All @@ -167,7 +172,8 @@ class JaCoCoTestKitPluginFunctionalTest {
}

private fun readLinesFromProperties(taskName: String = "test"): List<String> {
val propertiesFile = File(temporaryFolder.root, "build/testkit/$taskName/testkit-gradle.properties")
val propertiesFile =
File(temporaryFolder.root, "build/testkit/$taskName/testkit-gradle.properties")
return propertiesFile.inputStream().use { inputStream ->
inputStream.reader().readLines()
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/custom-task.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ configurations {
intTestRuntimeOnly.extendsFrom runtimeOnly
}

task integrationTest(type: Test) {
tasks.register('integrationTest', Test) {
description = 'Runs integration tests.'
group = 'verification'

Expand Down

0 comments on commit 3fc1d56

Please sign in to comment.