Repository: hbase
Updated Branches:
  refs/heads/master 30d0c3fdd -> 083796d2e


HBASE-15199 Move jruby jar so only on runtime classpath for hbase-shell and 
support scripts.

Signed-off-by: Sean Busbey <[email protected]>
Signed-off-by: Jerry He <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/083796d2
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/083796d2
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/083796d2

Branch: refs/heads/master
Commit: 083796d2e67cbfedf30053e826dbd6e0c0b2baec
Parents: 30d0c3f
Author: Xiang Li <[email protected]>
Authored: Wed Apr 26 23:48:34 2017 +0800
Committer: Sean Busbey <[email protected]>
Committed: Tue May 2 16:05:54 2017 -0500

----------------------------------------------------------------------
 bin/hbase                                       | 40 +++++++++++++++++---
 bin/hbase.cmd                                   | 34 ++++++++++++++---
 .../src/main/assembly/hadoop-two-compat.xml     | 19 +++++++++-
 3 files changed, 80 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/083796d2/bin/hbase
----------------------------------------------------------------------
diff --git a/bin/hbase b/bin/hbase
index f1114af..579c413 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"

http://git-wip-us.apache.org/repos/asf/hbase/blob/083796d2/bin/hbase.cmd
----------------------------------------------------------------------
diff --git a/bin/hbase.cmd b/bin/hbase.cmd
index 57a0cb4..44cb9d3 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"

http://git-wip-us.apache.org/repos/asf/hbase/blob/083796d2/hbase-assembly/src/main/assembly/hadoop-two-compat.xml
----------------------------------------------------------------------
diff --git a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml 
b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml
index 894ca67..3b8908c 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 @@
         <outputDirectory>lib</outputDirectory>
         <unpack>false</unpack>
         <dependencySets>
-          <dependencySet/>
+          <!-- Exclude jruby-complete from hbase_home/lib -->
+          <dependencySet>
+            <excludes>
+              <exclude>org.jruby:jruby-complete</exclude>
+            </excludes>
+          </dependencySet>
         </dependencySets>
       </binaries>
     </moduleSet>
@@ -81,4 +86,16 @@
       <lineEnding>unix</lineEnding>
     </file>
   </files>
+
+  <!-- Add jruby-complete to hbase_home/lib/ruby.
+       Update JRUBY_PACKAGED_WITH_HBASE in bin/hbase and hbase.cmd if you 
would like to update outputDirectory below -->
+  <dependencySets>
+    <dependencySet>
+      <outputDirectory>lib/ruby</outputDirectory>
+      <includes>
+        <include>org.jruby:jruby-complete</include>
+      </includes>
+    </dependencySet>
+  </dependencySets>
+
 </assembly>

Reply via email to