Skip to content

Commit b38a776

Browse files
Refactor System.getenv to providers.environmentVariable. (#9538)
1 parent 44e5822 commit b38a776

File tree

23 files changed

+42
-41
lines changed

23 files changed

+42
-41
lines changed

buildSrc/src/main/kotlin/datadog.gradle-debug.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ val ddGradleDebugEnabled = project.hasProperty("ddGradleDebug")
66
val logPath = rootProject.layout.buildDirectory.file("datadog.gradle-debug.log")
77

88
fun inferJdkFromJavaHome(javaHome: String?): String {
9-
val effectiveJavaHome = javaHome ?: System.getenv("JAVA_HOME")
10-
if (effectiveJavaHome == null) {
11-
throw IllegalStateException("JAVA_HOME is not set")
12-
}
9+
val effectiveJavaHome = javaHome ?: providers.environmentVariable("JAVA_HOME").orNull ?: error("JAVA_HOME is not set")
1310
val javaExecutable = File(effectiveJavaHome, "bin/java").absolutePath
1411
return try {
1512
val process = ProcessBuilder(javaExecutable, "-version")

dd-smoke-tests/armeria-grpc/application/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818
}
1919
}
2020

21-
def isCI = System.getenv("CI") != null
21+
def isCI = providers.environmentVariable("CI").isPresent()
2222

2323
// Don't pollute the dependency cache with the build cache
2424
if (isCI) {

dd-smoke-tests/debugger-integration-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tasks.withType(Test).configureEach {
3434

3535
// TODO latest-jdk-app fails too often with a jgit failure, so disable until fixed
3636
// def isLatestJdk = project.findProperty("testJvm") == latestJdk
37-
// def latestJavaHome = System.getenv("JAVA_${latestJdk}_HOME")
37+
// def latestJavaHome = providers.environmentVariable("JAVA_${latestJdk}_HOME").orNull
3838
// if (isLatestJdk && latestJavaHome) {
3939
// dependsOn buildLatestJdkApp
4040
// }

dd-smoke-tests/debugger-integration-tests/latest-jdk-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ shadowJar {
1111

1212
def latestJdk = 17
1313

14-
def latestJdkHome = System.getenv("JAVA_${latestJdk}_HOME")
14+
def latestJdkHome = providers.environmentVariable("JAVA_${latestJdk}_HOME").orNull
1515
if (latestJdkHome != null) {
1616
tasks.withType(JavaCompile) {
1717
options.fork = true

dd-smoke-tests/kafka-3/application/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818
}
1919
}
2020

21-
def isCI = System.getenv("CI") != null
21+
def isCI = providers.environmentVariable("CI").isPresent()
2222

2323
// Don't pollute the dependency cache with the build cache
2424
if (isCI) {

dd-smoke-tests/log-injection/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,10 @@ tasks.withType(Test).configureEach {
355355

356356
// Runtime.getRuntime().availableProcessors() is used to scale the parallelism by default,
357357
// but it returns weird values in Gitlab/kubernetes, so fix to a specific value when available
358-
def override = System.getenv("RUNTIME_AVAILABLE_PROCESSORS_OVERRIDE")
359-
maxParallelForks = override?.toInteger() ?: Math.max(1, (Runtime.runtime.availableProcessors() / 2).toInteger())
358+
maxParallelForks = providers.environmentVariable("RUNTIME_AVAILABLE_PROCESSORS_OVERRIDE")
359+
.map { it.toInteger() }
360+
.orElse(Math.max(1, (Runtime.runtime.availableProcessors() / 2).toInteger()))
361+
.get()
360362
}
361363

362364

dd-smoke-tests/quarkus-native/application/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pluginManagement {
2121
}
2222
}
2323

24-
def isCI = System.getenv("CI") != null
24+
def isCI = providers.environmentVariable("CI").isPresent()
2525

2626
// Don't pollute the dependency cache with the build cache
2727
if (isCI) {

dd-smoke-tests/quarkus-native/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ dependencies {
55
}
66
def testJvm = gradle.startParameter.projectProperties.getOrDefault('testJvm', '')
77
// In order to support GraalVM 21 we need at least Java 17 for Gradle
8-
def java17Home = System.getenv('JAVA_17_HOME')
8+
def java17Home = providers.environmentVariable('JAVA_17_HOME').orNull
99
// Check 'testJvm' gradle command parameter to be at least GraalVM 17
1010
def matcher = testJvm?.toLowerCase(Locale.ROOT) =~ /graalvm([0-9]+)/
1111
def version = matcher?.size() == 1 ? Integer.parseInt(matcher[0][1]) : -1
1212
if (version >= 17) {
1313
// Retrieve GRAALVM_HOME from JVM environment variables
1414
def testJvmEnv = "JAVA_${testJvm}_HOME"
15-
def testJvmHome = System.getenv(testJvmEnv)
15+
def testJvmHome = providers.environmentVariable(testJvmEnv).orNull
1616
if (!testJvmHome) {
1717
throw new GradleException("Unable to find launcher for Java '$testJvm'. Have you set '$testJvmEnv'?")
1818
}

dd-smoke-tests/quarkus/application/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pluginManagement {
2121
}
2222
}
2323

24-
def isCI = System.getenv("CI") != null
24+
def isCI = providers.environmentVariable("CI").isPresent()
2525

2626
// Don't pollute the dependency cache with the build cache
2727
if (isCI) {

dd-smoke-tests/rum/wildfly-15/rum-ear/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818
}
1919
}
2020

21-
def isCI = System.getenv("CI") != null
21+
def isCI = providers.environmentVariable("CI").isPresent()
2222

2323
// Don't pollute the dependency cache with the build cache
2424
if (isCI) {

0 commit comments

Comments
 (0)