You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/02/21 05:00:39 UTC
[impala] 01/03: IMPALA-7161: Fix impala-config.sh's handling of
JAVA_HOME
This is an automated email from the ASF dual-hosted git repository.
tarmstrong pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 6dabf9d9d3f6b4dc9ba287bbc8d712186589597f
Author: Joe McDonnell <jo...@cloudera.com>
AuthorDate: Tue Jun 12 14:46:58 2018 -0700
IMPALA-7161: Fix impala-config.sh's handling of JAVA_HOME
It is common for developers to specify JAVA_HOME in
bin/impala-config-local.sh, so wait until after it is
sourced to validate JAVA_HOME.
Also, try harder to auto-detect the system's JAVA_HOME
in case it has not been specified in the environment.
Here is a run through of different scenarios:
1. Not set in environment, not set in impala-config-local.sh:
Didn't work before, now tries to autodetect by looking
for javac on the PATH
2. Set in environment, not set in impala-config-local.sh:
No change
3. Not set in environment, set in impala-config-local.sh:
Didn't work before, now works
4. Set in environment and set in impala-config-local.sh:
This used to be potentially inconsistent (i.e. JAVA comes
from the environment's JAVA_HOME, but JAVA_HOME is
overwritten by impala-config-local.sh), now it always
uses the value from impala-config-local.sh.
Change-Id: Idf3521b4f44fdbdc841a90fd00c477c9423a75bb
Reviewed-on: http://gerrit.cloudera.org:8080/10702
Reviewed-by: Philip Zeyliger <ph...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
bin/impala-config.sh | 37 ++++++++++++++++++++++++++-----------
docker/entrypoint.sh | 1 -
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/bin/impala-config.sh b/bin/impala-config.sh
index 779cf10..e4ec6b9 100755
--- a/bin/impala-config.sh
+++ b/bin/impala-config.sh
@@ -34,17 +34,6 @@
# this script because scripts outside this repository may need to be updated and that
# is not practical at this time.
-export JAVA_HOME="${JAVA_HOME:-/usr/java/default}"
-if [ ! -d "$JAVA_HOME" ]; then
- echo "JAVA_HOME must be set to the location of your JDK!"
- return 1
-fi
-export JAVA="$JAVA_HOME/bin/java"
-if [[ ! -e "$JAVA" ]]; then
- echo "Could not find java binary at $JAVA" >&2
- return 1
-fi
-
if ! [[ "'$IMPALA_HOME'" =~ [[:blank:]] ]]; then
if [ -z "$IMPALA_HOME" ]; then
if [[ ! -z "$ZSH_NAME" ]]; then
@@ -202,6 +191,32 @@ if [ -f "$IMPALA_HOME/bin/impala-config-local.sh" ]; then
. "$IMPALA_HOME/bin/impala-config-local.sh"
fi
+# It is important to have a coherent view of the JAVA_HOME and JAVA executable.
+# The JAVA_HOME should be determined first, then the JAVA executable should be
+# derived from JAVA_HOME. bin/bootstrap_development.sh adds code to
+# bin/impala-config-local.sh to set JAVA_HOME, so it is important to pick up that
+# setting before deciding what JAVA_HOME to use.
+
+# Try to detect the system's JAVA_HOME
+# If javac exists, then the system has a Java SDK (JRE does not have javac).
+# Follow the symbolic links and use this to determine the system's JAVA_HOME.
+SYSTEM_JAVA_HOME="/usr/java/default"
+if [ -n "$(which javac)" ]; then
+ SYSTEM_JAVA_HOME=$(which javac | xargs readlink -f | sed "s:/bin/javac::")
+fi
+
+# Prefer the JAVA_HOME set in the environment, but use the system's JAVA_HOME otherwise
+export JAVA_HOME="${JAVA_HOME:-${SYSTEM_JAVA_HOME}}"
+if [ ! -d "$JAVA_HOME" ]; then
+ echo "JAVA_HOME must be set to the location of your JDK!"
+ return 1
+fi
+export JAVA="$JAVA_HOME/bin/java"
+if [[ ! -e "$JAVA" ]]; then
+ echo "Could not find java binary at $JAVA" >&2
+ return 1
+fi
+
#########################################################################################
# Below here are variables that can be overridden by impala-config-*.sh and environment #
# vars, variables computed based on other variables, and variables that cannot be #
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index 37809cd..382ca65 100755
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -80,7 +80,6 @@ function build() {
function impala_environment() {
pushd /home/impdev/Impala
export IMPALA_HOME=/home/impdev/Impala
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
source bin/impala-config.sh
popd
}