Skip to content

Commit

Permalink
Attempt to simplify jacoco logic
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <jmazane@amazon.com>
  • Loading branch information
jmazanec15 committed Nov 4, 2023
1 parent cc2b847 commit 3107c29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
32 changes: 8 additions & 24 deletions build-tools/knnplugin-coverage.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,35 @@
* break if there are multiple nodes in the integTestCluster. But for now... it sorta works.
*/

import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'jacoco'

jacoco {
toolVersion = "0.8.10"
}

// Get gradle to generate the required jvm agent arg for us using a dummy tasks of type Test. Unfortunately Elastic's
// testing tasks don't derive from Test so the jacoco plugin can't do this automatically.
def jacocoDir = "${buildDir}/jacoco"
task dummyTest(type: Test) {
enabled = false
workingDir = file("/") // Force absolute path to jacoco agent jar
def jacocoDir = "${project.layout.buildDirectory.get().asFile}/jacoco"
test {
jacoco {
destinationFile = file("${jacocoDir}/test.exec")
destinationFile.parentFile.mkdirs()
jmx = true
}
}

task dummyIntegTest(type: Test) {
enabled = false
workingDir = file("/") // Force absolute path to jacoco agent jar
integTest {
jacoco {
destinationFile = file("${jacocoDir}/integTest.exec")
destinationFile.parentFile.mkdirs()
jmx = true
}
}

integTest {
systemProperty 'jacoco.dir', "${jacocoDir}"
systemProperty 'jmx.serviceUrl', "service:jmx:rmi:///jndi/rmi://127.0.0.1:7777/jmxrmi"
}

jacocoTestReport {
dependsOn integTest, test
executionData.from = [dummyTest.jacoco.destinationFile, dummyIntegTest.jacoco.destinationFile]
sourceDirectories.from = sourceSets.main.java.sourceDirectories
classDirectories.from = files(sourceSets.main.java.classesDirectory)

reports {
html.getRequired().set(true) // human readable
csv.getRequired().set(true)
Expand All @@ -62,16 +54,8 @@ jacocoTestReport {
}

afterEvaluate {
jacocoTestReport.dependsOn integTest

// jacocoTestReport.dependsOn integTest
testClusters.integTest {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// Replacing build with absolute path to fix the error "error opening zip file or JAR manifest missing : /build/tmp/expandedArchives/..../jacocoagent.jar"
jvmArgs " ${dummyIntegTest.jacoco.getAsJvmArg()}".replace('build',"${buildDir}")
} else {
jvmArgs " ${dummyIntegTest.jacoco.getAsJvmArg()}".replace('javaagent:','javaagent:/')
}

systemProperty 'com.sun.management.jmxremote', "true"
systemProperty 'com.sun.management.jmxremote.authenticate', "false"
systemProperty 'com.sun.management.jmxremote.port', "7777"
Expand Down
5 changes: 0 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ plugins {
id 'java-library'
id 'java-test-fixtures'
id 'idea'
id 'jacoco'
id "com.diffplug.spotless" version "6.3.0" apply false
id 'io.freefair.lombok' version '8.4'
}
Expand Down Expand Up @@ -135,10 +134,6 @@ if (!usingRemoteCluster) {
}
}

jacoco {
toolVersion = "0.8.7"
}

check.dependsOn spotlessCheck
check.dependsOn jacocoTestReport

Expand Down

0 comments on commit 3107c29

Please sign in to comment.