From 083796d2e67cbfedf30053e826dbd6e0c0b2baec Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 26 Apr 2017 23:48:34 +0800 Subject: [PATCH] HBASE-15199 Move jruby jar so only on runtime classpath for hbase-shell and support scripts. Signed-off-by: Sean Busbey Signed-off-by: Jerry He --- bin/hbase | 40 ++++++++++++++++--- bin/hbase.cmd | 34 +++++++++++++--- .../src/main/assembly/hadoop-two-compat.xml | 19 ++++++++- 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/bin/hbase b/bin/hbase index f1114af0591..579c413d1ac 100755 --- a/bin/hbase +++ b/bin/hbase @@ -48,7 +48,7 @@ # JRUBY_HOME JRuby path: $JRUBY_HOME/lib/jruby.jar should exist. # Defaults to the jar packaged with HBase. # -# JRUBY_OPTS Extra options (eg '--1.9') passed to the hbase shell. +# JRUBY_OPTS Extra options (eg '--1.9') passed to hbase. # Empty by default. # # HBASE_SHELL_OPTS Extra options passed to the hbase shell. @@ -293,13 +293,41 @@ if [ "$AUTH_AS_SERVER" == "true" ] || [ "$COMMAND" = "hbck" ]; then fi 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 + +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" + + # add jruby to HBASE_OPTS + HBASE_OPTS="$HBASE_OPTS -Djruby.home=$JRUBY_HOME -Djruby.lib=$JRUBY_HOME/lib" + +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_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 + for jruby_jar in $JRUBY_PACKAGED_WITH_HBASE; do + CLASSPATH=$jruby_jar:$CLASSPATH; + done + fi +fi + # figure out which class to run if [ "$COMMAND" = "shell" ] ; then - # eg export JRUBY_HOME=/usr/local/share/jruby - if [ "$JRUBY_HOME" != "" ] ; then - CLASSPATH="$JRUBY_HOME/lib/jruby.jar:$CLASSPATH" - HBASE_OPTS="$HBASE_OPTS -Djruby.home=$JRUBY_HOME -Djruby.lib=$JRUBY_HOME/lib" - fi #find the hbase ruby sources if [ -d "$HBASE_HOME/lib/ruby" ]; then HBASE_OPTS="$HBASE_OPTS -Dhbase.ruby.sources=$HBASE_HOME/lib/ruby" diff --git a/bin/hbase.cmd b/bin/hbase.cmd index 57a0cb46090..44cb9d3dbf0 100644 --- a/bin/hbase.cmd +++ b/bin/hbase.cmd @@ -41,7 +41,7 @@ @rem JRUBY_HOME JRuby path: $JRUBY_HOME\lib\jruby.jar should exist. @rem Defaults to the jar packaged with HBase. @rem -@rem JRUBY_OPTS Extra options (eg '--1.9') passed to the hbase shell. +@rem JRUBY_OPTS Extra options (eg '--1.9') passed to hbase. @rem Empty by default. @rem HBASE_SHELL_OPTS Extra options passed to the hbase shell. @rem Empty by default. @@ -262,6 +262,33 @@ 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 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 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 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 Have JVM dump heap if we run out of memory. Files will be 'launch directory' @rem and are named like the following: java_pid21612.hprof. Apparently it does not @@ -307,11 +334,6 @@ endlocal goto :eof :shell - rem eg export JRUBY_HOME=/usr/local/share/jruby - 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 find the hbase ruby sources if exist "%HBASE_HOME%\lib\ruby" ( set HBASE_OPTS=%HBASE_OPTS% -Dhbase.ruby.sources="%HBASE_HOME%\lib\ruby" diff --git a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml index 894ca67cd7f..3b8908c7756 100644 --- a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml +++ b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml @@ -55,7 +55,12 @@ lib false - + + + + org.jruby:jruby-complete + + @@ -81,4 +86,16 @@ unix + + + + + lib/ruby + + org.jruby:jruby-complete + + + +