Skip to content

Commit 3ef9429

Browse files
committed
fix: profiling-controller-oracle tests could never run, introduce an includeJdk directive
1 parent dcce4f2 commit 3ef9429

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

buildSrc/src/main/kotlin/datadog.test-jvm-contraints.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import datadog.gradle.plugin.testJvmConstraints.TestJvmJavaLauncher
44
import datadog.gradle.plugin.testJvmConstraints.isJavaLauncherAllowed
55
import datadog.gradle.plugin.testJvmConstraints.isJavaVersionAllowed
66
import datadog.gradle.plugin.testJvmConstraints.isJdkExcluded
7+
import datadog.gradle.plugin.testJvmConstraints.isJdkIncluded
78
import datadog.gradle.plugin.testJvmConstraints.isJdkForced
89

910
plugins {
@@ -27,6 +28,7 @@ tasks.withType<Test>().configureEach {
2728

2829
inputs.property("${TestJvmConstraintsExtension.NAME}.allowReflectiveAccessToJdk", taskExtension.allowReflectiveAccessToJdk).optional(true)
2930
inputs.property("${TestJvmConstraintsExtension.NAME}.excludeJdk", taskExtension.excludeJdk)
31+
inputs.property("${TestJvmConstraintsExtension.NAME}.includeJdk", taskExtension.includeJdk)
3032
inputs.property("${TestJvmConstraintsExtension.NAME}.forceJdk", taskExtension.forceJdk)
3133
inputs.property("${TestJvmConstraintsExtension.NAME}.minJavaVersionForTests", taskExtension.minJavaVersionForTests).optional(true)
3234
inputs.property("${TestJvmConstraintsExtension.NAME}.maxJavaVersionForTests", taskExtension.maxJavaVersionForTests).optional(true)
@@ -63,6 +65,7 @@ fun Test.configureTestJvm(extension: TestJvmConstraintsExtension) {
6365
if (testJvmJavaLauncher.javaTestLauncher.isPresent) {
6466
javaLauncher = testJvmJavaLauncher.javaTestLauncher
6567
onlyIf("Allowed or forced JDK") {
68+
extension.isJdkIncluded(testJvmJavaLauncher.normalizedTestJvm.get()) &&
6669
!extension.isJdkExcluded(testJvmJavaLauncher.normalizedTestJvm.get()) &&
6770
(extension.isJavaLauncherAllowed(testJvmJavaLauncher.javaTestLauncher.get()) ||
6871
extension.isJdkForced(testJvmJavaLauncher.normalizedTestJvm.get()))

buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmConstraintsExtension.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,35 @@ import org.gradle.kotlin.dsl.property
1212
import javax.inject.Inject
1313

1414
interface TestJvmConstraintsExtension {
15+
/**
16+
* Sets an explicit minimum bound to allowed JDK version
17+
*/
1518
val minJavaVersionForTests: Property<JavaVersion>
19+
20+
/**
21+
* Sets an explicit maximum bound to allowed JDK version
22+
*/
1623
val maxJavaVersionForTests: Property<JavaVersion>
24+
25+
/**
26+
* List of allowed JDK names (passed through the `testJvm` property).
27+
*/
1728
val forceJdk: ListProperty<String>
29+
30+
/**
31+
* List of included JDK names (passed through the `testJvm` property).
32+
*/
33+
val includeJdk: ListProperty<String>
34+
35+
/**
36+
* List of excluded JDK names (passed through the `testJvm` property).
37+
*/
1838
val excludeJdk: ListProperty<String>
39+
40+
/**
41+
* Indicate if test jvm allows reflective access to JDK modules, in particular this toggle
42+
* openning `java.base/java.lang` and `java.base/java.util`.
43+
*/
1944
val allowReflectiveAccessToJdk: Property<Boolean>
2045

2146
companion object {

buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmConstraintsUtils.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ internal fun TestJvmConstraintsExtension.isJavaLauncherAllowed(javaLauncher: Jav
3636
}
3737

3838
internal fun TestJvmConstraintsExtension.isJdkForced(javaName: String): Boolean {
39-
return forceJdk.get().any { it.equals(javaName, ignoreCase = true) }
39+
return forceJdk.orNull?.any { it.equals(javaName, ignoreCase = true) } ?: false
4040
}
4141

4242
internal fun TestJvmConstraintsExtension.isJdkExcluded(javaName: String): Boolean {
4343
return excludeJdk.get().any { it.equals(javaName, ignoreCase = true) }
4444
}
45+
46+
internal fun TestJvmConstraintsExtension.isJdkIncluded(javaName: String): Boolean {
47+
val included = includeJdk.get()
48+
return when {
49+
included.isEmpty() -> true
50+
else -> included.any { it.equals(javaName, ignoreCase = true) }
51+
}
52+
}

dd-java-agent/agent-profiling/profiling-controller-oracle/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dependencies {
2626

2727
// Oracle JDK requires extra JVM arguments to enable JFR
2828
tasks.withType(Test).configureEach {
29-
onlyIf {
30-
it.name.contains('ORACLE8')
29+
testJvmConstraint {
30+
includeJdk = ['ORACLE8']
3131
}
3232

3333
jvmArgs += [

0 commit comments

Comments
 (0)