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.
This commit is contained in:
parent
acd49f89c7
commit
7e9b957da5
|
@ -289,13 +289,8 @@ public class DistroTestPlugin implements Plugin<Project> {
|
||||||
VagrantExtension vagrant = project.getExtensions().getByType(VagrantExtension.class);
|
VagrantExtension vagrant = project.getExtensions().getByType(VagrantExtension.class);
|
||||||
vagrant.setBox(box);
|
vagrant.setBox(box);
|
||||||
vagrant.vmEnv("SYSTEM_JAVA_HOME", convertPath(project, vagrant, systemJdkProvider, "", ""));
|
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
|
// set java home for gradle to use. package tests will overwrite/remove this for each test case
|
||||||
// ignored
|
vagrant.vmEnv("JAVA_HOME", convertPath(project, vagrant, gradleJdkProvider, "", ""));
|
||||||
// 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
|
|
||||||
if (System.getenv("JENKINS_URL") != null) {
|
if (System.getenv("JENKINS_URL") != null) {
|
||||||
Stream.of("JOB_NAME", "JENKINS_URL", "BUILD_NUMBER", "BUILD_URL").forEach(name -> vagrant.vmEnv(name, System.getenv(name)));
|
Stream.of("JOB_NAME", "JENKINS_URL", "BUILD_NUMBER", "BUILD_URL").forEach(name -> vagrant.vmEnv(name, System.getenv(name)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,6 +166,7 @@ public class Shell {
|
||||||
if (workingDirectory != null) {
|
if (workingDirectory != null) {
|
||||||
setWorkingDirectory(builder, workingDirectory);
|
setWorkingDirectory(builder, workingDirectory);
|
||||||
}
|
}
|
||||||
|
builder.environment().keySet().remove("JAVA_HOME"); // start with a fresh environment
|
||||||
for (Map.Entry<String, String> entry : env.entrySet()) {
|
for (Map.Entry<String, String> entry : env.entrySet()) {
|
||||||
builder.environment().put(entry.getKey(), entry.getValue());
|
builder.environment().put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue