From b67f6fecc173ff1272284f3e47f95d493fab331d Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sat, 6 May 2017 11:37:13 +0800 Subject: [PATCH] HBASE-15199 (addendum) - When JRUBY_HOME is specified, update CLASSPATH and HBASE_OPTS when jruby is needed Signed-off-by: Sean Busbey Signed-off-by: tedyu Signed-off-by: Jerry He --- bin/hbase | 46 ++++++++++++++++++++++++---------------------- bin/hbase.cmd | 42 +++++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/bin/hbase b/bin/hbase index 579c413d1ac..fa70f6e3abc 100755 --- a/bin/hbase +++ b/bin/hbase @@ -294,32 +294,34 @@ if [ "$AUTH_AS_SERVER" == "true" ] || [ "$COMMAND" = "hbck" ]; then fi # for jruby -# (1) when JRUBY_HOME is specified explicitly, eg. export JRUBY_HOME=/usr/local/share/jruby -# for all commands, CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME specified -# (2) when JRUBY_HOME is not specified explicitly -# A. for jruby_cmds defined below, add JRUBY_PACKAGED_WITH_HBASE into CLASSPATH -# B. for other commands, do nothing +# (1) for the commands which need jruby (see jruby_cmds defined below) +# A. when JRUBY_HOME is specified explicitly, eg. export JRUBY_HOME=/usr/local/share/jruby +# CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME specified +# B. when JRUBY_HOME is not specified explicitly +# add jruby packaged with HBase to CLASSPATH +# (2) for other commands, do nothing -if [ "$JRUBY_HOME" != "" ]; then # JRUBY_HOME is specified explicitly, eg. export JRUBY_HOME=/usr/local/share/jruby - # add jruby.jar into CLASSPATH - CLASSPATH="$JRUBY_HOME/lib/jruby.jar:$CLASSPATH" +# check if the commmand needs jruby +declare -a jruby_cmds=("shell" "org.jruby.Main") +for cmd in "${jruby_cmds[@]}"; do + if [[ $cmd == "$COMMAND" ]]; then + jruby_needed=true + break + fi +done - # add jruby to HBASE_OPTS - HBASE_OPTS="$HBASE_OPTS -Djruby.home=$JRUBY_HOME -Djruby.lib=$JRUBY_HOME/lib" +# the command needs jruby +if [[ $jruby_needed ]]; then + if [ "$JRUBY_HOME" != "" ]; then # JRUBY_HOME is specified explicitly, eg. export JRUBY_HOME=/usr/local/share/jruby + # add jruby.jar into CLASSPATH + CLASSPATH="$JRUBY_HOME/lib/jruby.jar:$CLASSPATH" -else # JRUBY_HOME is not specified explicitly - # check if the commmand needs jruby - declare -a jruby_cmds=("shell" "org.jruby.Main") - for cmd in "${jruby_cmds[@]}"; do - if [[ $cmd == "$COMMAND" ]]; then - jruby_needed=true - break - fi - done + # add jruby to HBASE_OPTS + HBASE_OPTS="$HBASE_OPTS -Djruby.home=$JRUBY_HOME -Djruby.lib=$JRUBY_HOME/lib" - # add JRUBY_PACKAGED_WITH_HBASE to CLASSPATH when jruby is needed - JRUBY_PACKAGED_WITH_HBASE="$HBASE_HOME/lib/ruby/*.jar" - if [[ $jruby_needed ]]; then # the command needs jruby + else # JRUBY_HOME is not specified explicitly + # add jruby packaged with HBase to CLASSPATH + JRUBY_PACKAGED_WITH_HBASE="$HBASE_HOME/lib/ruby/*.jar" for jruby_jar in $JRUBY_PACKAGED_WITH_HBASE; do CLASSPATH=$jruby_jar:$CLASSPATH; done diff --git a/bin/hbase.cmd b/bin/hbase.cmd index 44cb9d3dbf0..67a3bc1c2d8 100644 --- a/bin/hbase.cmd +++ b/bin/hbase.cmd @@ -263,30 +263,34 @@ if defined service_entry ( ) @rem for jruby -@rem (1) when JRUBY_HOME is defined -@rem for all commands, CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME specified -@rem (2) when JRUBY_HOME is not defined -@rem A. for jruby-commands defined below, add JRUBY_PACKAGED_WITH_HBASE into CLASSPATH -@rem B. for other commands, do nothing +@rem (1) for the commands which need jruby (see jruby-commands defined below) +@rem A. when JRUBY_HOME is defined +@rem CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME defined +@rem B. when JRUBY_HOME is not defined +@rem add jruby packaged with HBase to CLASSPATH +@rem (2) for other commands, do nothing -@rem JRUBY_HOME is defined -if defined JRUBY_HOME ( - set CLASSPATH=%CLASSPATH%;%JRUBY_HOME%\lib\jruby.jar - set HBASE_OPTS=%HBASE_OPTS% -Djruby.home="%JRUBY_HOME%" -Djruby.lib="%JRUBY_HOME%\lib" +@rem check if the commmand needs jruby +set jruby-commands=shell org.jruby.Main +for %%i in ( %jruby-commands% ) do ( + if "%hbase-command%"=="%%i" set jruby-needed=true ) -@rem JRUBY_HOME is not defined -if not defined JRUBY_HOME ( - @rem check if the commmand needs jruby - set jruby-commands=shell org.jruby.Main - for %%i in ( !jruby-commands! ) do ( - if "%hbase-command%"=="%%i" set jruby-needed=true +@rem the command needs jruby +if defined jruby-needed ( + @rem JRUBY_HOME is defined + if defined JRUBY_HOME ( + set CLASSPATH=%JRUBY_HOME%\lib\jruby.jar;%CLASSPATH% + set HBASE_OPTS=%HBASE_OPTS% -Djruby.home="%JRUBY_HOME%" -Djruby.lib="%JRUBY_HOME%\lib" ) - @rem add JRUBY_PACKAGED_WITH_HBASE to CLASSPATH if jruby is needed - set JRUBY_PACKAGED_WITH_HBASE=%HBASE_HOME%\lib\ruby\* - if defined jruby-needed ( - set CLASSPATH=!JRUBY_PACKAGED_WITH_HBASE!;!CLASSPATH! + @rem JRUBY_HOME is not defined + if not defined JRUBY_HOME ( + @rem add jruby packaged with HBase to CLASSPATH + set JRUBY_PACKAGED_WITH_HBASE=%HBASE_HOME%\lib\ruby\* + if defined jruby-needed ( + set CLASSPATH=!JRUBY_PACKAGED_WITH_HBASE!;!CLASSPATH! + ) ) )