From 7e9b957da591569d11a46b85b7e3ba99c527fa7a Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 24 Sep 2020 16:59:25 -0700 Subject: [PATCH] Handle JAVA_HOME better in packaging tests (#62905) JAVA_HOME is set as necessary in packaging tests, depending on whether it is needed for no-jdk distributions or testing override behavior. We currently rely on gradle finding java through PATH. However, JAVA_HOME can sometimes be set by the system itself, which then leaks through to the packaging test. This commit reworks our handling of JAVA_HOME to pass it through for gradle, and then explicitly clear it whenever running shell commands in packaging tests. --- .../org/elasticsearch/gradle/test/DistroTestPlugin.java | 9 ++------- .../java/org/elasticsearch/packaging/util/Shell.java | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java index f641e9227bf..13b69b76410 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java @@ -289,13 +289,8 @@ public class DistroTestPlugin implements Plugin { VagrantExtension vagrant = project.getExtensions().getByType(VagrantExtension.class); vagrant.setBox(box); vagrant.vmEnv("SYSTEM_JAVA_HOME", convertPath(project, vagrant, systemJdkProvider, "", "")); - vagrant.vmEnv("JAVA_HOME", convertPath(project, vagrant, gradleJdkProvider, "", "")); // make sure any default java on the system is - // ignored - // also set RUNTIME_JAVA_HOME, not because it is used, but to ensure the bundled jdk version is not loaded by gradle on legacy - // systems - vagrant.vmEnv("RUNTIME_JAVA_HOME", convertPath(project, vagrant, gradleJdkProvider, "", "")); - vagrant.vmEnv("PATH", convertPath(project, vagrant, gradleJdkProvider, "/bin:$PATH", "\\bin;$Env:PATH")); - // pass these along to get correct build scans + // set java home for gradle to use. package tests will overwrite/remove this for each test case + vagrant.vmEnv("JAVA_HOME", convertPath(project, vagrant, gradleJdkProvider, "", "")); if (System.getenv("JENKINS_URL") != null) { Stream.of("JOB_NAME", "JENKINS_URL", "BUILD_NUMBER", "BUILD_URL").forEach(name -> vagrant.vmEnv(name, System.getenv(name))); } diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java b/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java index 6411a1aa100..859f718ec76 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java @@ -166,6 +166,7 @@ public class Shell { if (workingDirectory != null) { setWorkingDirectory(builder, workingDirectory); } + builder.environment().keySet().remove("JAVA_HOME"); // start with a fresh environment for (Map.Entry entry : env.entrySet()) { builder.environment().put(entry.getKey(), entry.getValue()); }