فهرست منبع

Remove support for JAVA_HOME (#69149)

This commit removes support for JAVA_HOME. As we previously deprecated
usage of JAVA_HOME to override the path for the JDK, this commit follows
up by removing support for JAVA_HOME. Note that we do not treat
JAVA_HOME being set as a failure, as it is perfectly reasonable for a
user to have JAVA_HOME configured at the system level.
Jason Tedor 4 سال پیش
والد
کامیت
d3ac7c9806

+ 5 - 5
distribution/src/bin/elasticsearch-env

@@ -39,11 +39,6 @@ ES_CLASSPATH="$ES_HOME/lib/*"
 if [ ! -z "$ES_JAVA_HOME" ]; then
 if [ ! -z "$ES_JAVA_HOME" ]; then
   JAVA="$ES_JAVA_HOME/bin/java"
   JAVA="$ES_JAVA_HOME/bin/java"
   JAVA_TYPE="ES_JAVA_HOME"
   JAVA_TYPE="ES_JAVA_HOME"
-elif [ ! -z "$JAVA_HOME" ]; then
-  # fallback to JAVA_HOME
-  echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
-  JAVA="$JAVA_HOME/bin/java"
-  JAVA_TYPE="JAVA_HOME"
 else
 else
   # use the bundled JDK (default)
   # use the bundled JDK (default)
   if [ "$(uname -s)" = "Darwin" ]; then
   if [ "$(uname -s)" = "Darwin" ]; then
@@ -66,6 +61,11 @@ if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then
   unset JAVA_TOOL_OPTIONS
   unset JAVA_TOOL_OPTIONS
 fi
 fi
 
 
+# warn that we are not observing the value of JAVA_HOME
+if [ ! -z "$JAVA_HOME" ]; then
+  echo "warning: ignoring JAVA_HOME=$JAVA_HOME; using $JAVA_TYPE" >&2
+fi
+
 # JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
 # JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
 # warn them that we are not observing the value of $JAVA_OPTS
 # warn them that we are not observing the value of $JAVA_OPTS
 if [ ! -z "$JAVA_OPTS" ]; then
 if [ ! -z "$JAVA_OPTS" ]; then

+ 7 - 8
distribution/src/bin/elasticsearch-env.bat

@@ -35,23 +35,17 @@ if "%ES_BUNDLED_JDK%" == "false" (
 
 
 cd /d "%ES_HOME%"
 cd /d "%ES_HOME%"
 
 
-rem now set the path to java, pass "nojava" arg to skip setting JAVA_HOME and JAVA
+rem now set the path to java, pass "nojava" arg to skip setting ES_JAVA_HOME and JAVA
 if "%1" == "nojava" (
 if "%1" == "nojava" (
    exit /b
    exit /b
 )
 )
 
 
 rem comparing to empty string makes this equivalent to bash -v check on env var
 rem comparing to empty string makes this equivalent to bash -v check on env var
 rem and allows to effectively force use of the bundled jdk when launching ES
 rem and allows to effectively force use of the bundled jdk when launching ES
-rem by setting JAVA_HOME=
+rem by setting ES_JAVA_HOME=
 if defined ES_JAVA_HOME (
 if defined ES_JAVA_HOME (
   set JAVA="%ES_JAVA_HOME%\bin\java.exe"
   set JAVA="%ES_JAVA_HOME%\bin\java.exe"
   set JAVA_TYPE=ES_JAVA_HOME
   set JAVA_TYPE=ES_JAVA_HOME
-) else if defined JAVA_HOME (
-  rem fallback to JAVA_HOME
-  echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
-  set JAVA="%JAVA_HOME%\bin\java.exe"
-  set "ES_JAVA_HOME=%JAVA_HOME%"
-  set JAVA_TYPE=JAVA_HOME
 ) else (
 ) else (
   rem use the bundled JDK (default)
   rem use the bundled JDK (default)
   set JAVA="%ES_HOME%\jdk\bin\java.exe"
   set JAVA="%ES_HOME%\jdk\bin\java.exe"
@@ -70,6 +64,11 @@ if defined JAVA_TOOL_OPTIONS (
   set JAVA_TOOL_OPTIONS=
   set JAVA_TOOL_OPTIONS=
 )
 )
 
 
+rem warn that we are not observing the value of $JAVA_HOME
+if defined JAVA_HOME (
+  echo warning: ignoring JAVA_HOME=%JAVA_HOME%; using %JAVA_TYPE% >&2
+)
+
 rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
 rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
 rem warn them that we are not observing the value of %JAVA_OPTS%
 rem warn them that we are not observing the value of %JAVA_OPTS%
 if defined JAVA_OPTS (
 if defined JAVA_OPTS (

+ 14 - 0
docs/reference/migration/migrate_8_0/packaging.asciidoc

@@ -15,3 +15,17 @@ Use Java 11 or higher. Attempts to run {es} 8.0 using earlier Java versions will
 fail.
 fail.
 ====
 ====
 //end::notable-breaking-changes[]
 //end::notable-breaking-changes[]
+
+//tag::notable-breaking-changes[]
+.JAVA_HOME is no longer supported.
+[%collapsible]
+====
+*Details* +
+`JAVA_HOME` is no longer supported to set the path for the JDK. Instead, use
+the bundled JDK (preferable), or set `ES_JAVA_HOME`.
+
+*Impact* +
+Use the bundled JDK (preferable), or set `ES_JAVA_HOME`. `JAVA_HOME` will be
+ignored.
+====
+//end::notable-breaking-changes[]

+ 6 - 30
qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java

@@ -147,7 +147,8 @@ public class ArchiveTests extends PackagingTestCase {
         assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
         assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
     }
     }
 
 
-    public void test51JavaHomeOverride() throws Exception {
+    public void test51JavaHomeIgnored() throws Exception {
+        assumeTrue(distribution().hasJdk);
         Platforms.onLinux(() -> {
         Platforms.onLinux(() -> {
             String systemJavaHome1 = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
             String systemJavaHome1 = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
             sh.getEnv().put("JAVA_HOME", systemJavaHome1);
             sh.getEnv().put("JAVA_HOME", systemJavaHome1);
@@ -163,40 +164,15 @@ public class ArchiveTests extends PackagingTestCase {
 
 
         final Installation.Executables bin = installation.executables();
         final Installation.Executables bin = installation.executables();
         final Result runResult = sh.run(bin.elasticsearch.toString() + " -V");
         final Result runResult = sh.run(bin.elasticsearch.toString() + " -V");
-        assertThat(runResult.stderr, containsString("warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME"));
+        assertThat(runResult.stderr, containsString("warning: ignoring JAVA_HOME=" + systemJavaHome + "; using bundled JDK"));
 
 
         startElasticsearch();
         startElasticsearch();
         ServerUtils.runElasticsearchTests();
         ServerUtils.runElasticsearchTests();
         stopElasticsearch();
         stopElasticsearch();
 
 
-        String systemJavaHome1 = sh.getEnv().get("JAVA_HOME");
-        assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
-    }
-
-    public void test51EsJavaHomeOverrideOverridesJavaHome() throws Exception {
-        Platforms.onLinux(() -> {
-            String systemJavaHome1 = sh.run("echo $SYSTEM_JAVA_HOME").stdout.trim();
-            sh.getEnv().put("ES_JAVA_HOME", systemJavaHome1);
-            // deliberately set to a location that does not exist, if ES_JAVA_HOME takes precedence this is ignored
-            sh.getEnv().put("JAVA_HOME", "doesnotexist");
-        });
-        Platforms.onWindows(() -> {
-            final String systemJavaHome1 = sh.run("$Env:SYSTEM_JAVA_HOME").stdout.trim();
-            sh.getEnv().put("ES_JAVA_HOME", systemJavaHome1);
-            // deliberately set to a location that does not exist, if ES_JAVA_HOME takes precedence this is ignored
-            sh.getEnv().put("JAVA_HOME", "doesnotexist");
-        });
-
-        final Installation.Executables bin = installation.executables();
-        final Result runResult = sh.run(bin.elasticsearch.toString() + " -V");
-        assertThat(runResult.stderr, not(containsString("warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME")));
-
-        startElasticsearch();
-        ServerUtils.runElasticsearchTests();
-        stopElasticsearch();
-
-        String systemJavaHome1 = sh.getEnv().get("ES_JAVA_HOME");
-        assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(systemJavaHome1));
+        // if the JDK started with the bundled JDK then we know that JAVA_HOME was ignored
+        String bundledJdk = installation.bundledJdk.toString();
+        assertThat(FileUtils.slurpAllLogs(installation.logs, "elasticsearch.log", "*.log.gz"), containsString(bundledJdk));
     }
     }
 
 
     public void test52BundledJdkRemoved() throws Exception {
     public void test52BundledJdkRemoved() throws Exception {

+ 0 - 1
qa/os/src/test/java/org/elasticsearch/packaging/util/Shell.java

@@ -156,7 +156,6 @@ public class Shell {
             setWorkingDirectory(builder, workingDirectory);
             setWorkingDirectory(builder, workingDirectory);
         }
         }
         builder.environment().keySet().remove("ES_JAVA_HOME"); // start with a fresh environment
         builder.environment().keySet().remove("ES_JAVA_HOME"); // start with a fresh environment
-        builder.environment().keySet().remove("JAVA_HOME");
         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());
         }
         }