Repository: impala Updated Branches: refs/heads/master 13b82624b -> 28b4ad14f
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 <[email protected]> Tested-by: Impala Public Jenkins <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/impala/repo Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/28b4ad14 Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/28b4ad14 Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/28b4ad14 Branch: refs/heads/master Commit: 28b4ad14f61bf6f0195b731195767d3a59e92ed8 Parents: 13b8262 Author: Joe McDonnell <[email protected]> Authored: Tue Jun 12 14:46:58 2018 -0700 Committer: Joe McDonnell <[email protected]> Committed: Mon Jun 18 21:42:22 2018 +0000 ---------------------------------------------------------------------- bin/impala-config.sh | 37 ++++++++++++++++++++++++++----------- docker/entrypoint.sh | 1 - 2 files changed, 26 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/impala/blob/28b4ad14/bin/impala-config.sh ---------------------------------------------------------------------- diff --git a/bin/impala-config.sh b/bin/impala-config.sh index 2c11d2c..568bdb9 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 @@ -235,6 +224,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 # http://git-wip-us.apache.org/repos/asf/impala/blob/28b4ad14/docker/entrypoint.sh ---------------------------------------------------------------------- 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 }
