Skip to content
Open
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
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-core")

compileOnly(libs.develocity)

testImplementation("me.champeau.jmh:jmh-gradle-plugin:0.7.3")
}

tasks.compileKotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
Expand Down Expand Up @@ -42,6 +43,16 @@ class TestJvmConstraintsPlugin : Plugin<Project> {
configureTestJvm(testJvmSpec, taskExtension)
}

// JMH plugin is not applied on every project
project.pluginManager.withPlugin("me.champeau.jmh") {
val jmh = project.extensions.getByName("jmh")

// Avoid linking against JMH types, which are unavailable to the parent buildSrc classloader.
@Suppress("UNCHECKED_CAST")
val jvm = jmh.javaClass.getMethod("getJvm").invoke(jmh) as Property<String>
jvm.set(testJvmSpec.javaTestLauncher.map { it.executablePath.asFile.absolutePath })
}

// Jacoco plugin is not applied on every project
project.pluginManager.withPlugin("org.gradle.jacoco") {
project.tasks.withType<Test>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package datadog.gradle.plugin.testJvmConstraints

import datadog.gradle.plugin.testJvmConstraints.TestJvmConstraintsExtension.Companion.TEST_JVM_CONSTRAINTS
import me.champeau.jmh.JmhParameters
import org.assertj.core.api.Assertions.assertThat
import org.gradle.api.JavaVersion
import org.gradle.api.tasks.testing.Test as GradleTest
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
Expand All @@ -21,6 +23,31 @@ class TestJvmConstraintsPluginTest {
assertThat(testTask.extensions.findByName(TEST_JVM_CONSTRAINTS)).isInstanceOf(TestJvmConstraintsExtension::class.java)
}

@Test
fun `plugin configures jmh to use the test jvm`() {
val propertyName = "org.gradle.project.${TestJvmSpec.TEST_JVM}"
val previousValue = System.setProperty(propertyName, JavaVersion.current().majorVersion)

try {
val project = ProjectBuilder.builder().build()

project.pluginManager.apply("dd-trace-java.test-jvm-constraints")
assertThat(project.extensions.findByName("jmh")).isNull()

project.pluginManager.apply("me.champeau.jmh")

val jmh = project.extensions.getByType(JmhParameters::class.java)
val expectedExecutable = TestJvmSpec(project).javaTestLauncher.get().executablePath.asFile.absolutePath
assertThat(jmh.jvm.get()).isEqualTo(expectedExecutable)
} finally {
if (previousValue == null) {
System.clearProperty(propertyName)
} else {
System.setProperty(propertyName, previousValue)
}
}
}

@Test
fun `jacoco is disabled for additional test jvm when coverage is not checked`() {
val testTask = testTaskWithJacoco()
Expand Down
6 changes: 0 additions & 6 deletions dd-trace-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datadog.gradle.plugin.testJvmConstraints.TestJvmSpec

plugins {
id 'me.champeau.jmh'
id 'dd-trace-java.version-file'
Expand Down Expand Up @@ -135,8 +133,4 @@ jmh {
if (project.hasProperty('jmh.profilers')) {
profilers = project.property('jmh.profilers').tokenize(',')
}
if (project.hasProperty('testJvm')) {
def testJvmSpec = new TestJvmSpec(project)
jvm = testJvmSpec.javaTestLauncher.map { it.executablePath.asFile.absolutePath }
}
}
6 changes: 0 additions & 6 deletions internal-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datadog.gradle.plugin.testJvmConstraints.TestJvmSpec
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
import groovy.lang.Closure

Expand Down Expand Up @@ -291,9 +290,4 @@ jmh {
if (project.hasProperty("jmh.includes")) {
includes.add(project.property("jmh.includes") as String)
}

if (project.hasProperty("testJvm")) {
val testJvmSpec = TestJvmSpec(project)
jvm.set(testJvmSpec.javaTestLauncher.map { it.executablePath.asFile.absolutePath })
}
}
Loading