This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch branch-1.6
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/branch-1.6 by this push:
     new c0dff6ab8 [KYUUBI #3619] Enhance JAVA_HOME detection to support RPM
c0dff6ab8 is described below

commit c0dff6ab8ca05c68b39a6b2e39f0202b624cc055
Author: Cheng Pan <[email protected]>
AuthorDate: Fri Oct 14 12:35:00 2022 +0800

    [KYUUBI #3619] Enhance JAVA_HOME detection to support RPM
    
    ### _Why are the changes needed?_
    
    By default, on CentOS 7 w/ openJDK 8 installed via YUM/RPM, the 
`/usr/bin/java` links to `/usr/lib/jvm/java-1.8.0-openjdk/jre/bin/java`, the 
current detection logic will think the `JAVA_HOME` is 
`/usr/lib/jvm/java-1.8.0-openjdk/jre`, and then cause the issue.
    
    ```
    [ERROR] Failed to execute goal 
net.alchim31.maven:scala-maven-plugin:4.6.1:compile (scala-compile-first) on 
project kyuubi-common_2.12: wrap: java.io.IOException: Cannot run program 
"/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64/jre/bin/javac" 
(in directory "/home/pancheng/apache-kyuubi"): error=2, No such file or 
directory -> [Help 1]
    ```
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including 
negative and positive cases if possible
    
    - [x] Add screenshots for manual tests if appropriate
    
    w/ this patch, the `build/dist` works expected on CentOS w/ openJDK 8 
installed via `yum`, the debug info shows it detected the right `JAVA_HOME`
    ```
    + [[ -z '' ]]
    ++ command -v rpm
    + '[' /usr/bin/rpm ']'
    ++ rpm -E %java_home
    + RPM_JAVA_HOME=/usr/lib/jvm/java
    + '[' /usr/lib/jvm/java '!=' %java_home ']'
    + JAVA_HOME=/usr/lib/jvm/java
    + echo 'No JAVA_HOME set, proceeding with '\''/usr/lib/jvm/java'\'' learned 
from rpm'
    No JAVA_HOME set, proceeding with '/usr/lib/jvm/java' learned from rpm
    + '[' -z /usr/lib/jvm/java ']'
    + [[ -z /usr/lib/jvm/java ]]
    + echo 'JAVA_HOME is set to /usr/lib/jvm/java'
    JAVA_HOME is set to /usr/lib/jvm/java
    ```
    
    - [ ] [Run 
test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests)
 locally before make a pull request
    
    Closes #3619 from pan3793/java-home.
    
    Closes #3619
    
    b6e10a78 [Cheng Pan] nit
    2a59d299 [Cheng Pan] [BUILD] Detect JAVA_HOME from rpm
    
    Authored-by: Cheng Pan <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
    (cherry picked from commit 90a7d1921ace270ef0d895e1fca275a0fda4d94e)
    Signed-off-by: Cheng Pan <[email protected]>
---
 build/dist | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/build/dist b/build/dist
index fefdd4dbd..b7dc3f9b0 100755
--- a/build/dist
+++ b/build/dist
@@ -101,11 +101,23 @@ while (( "$#" )); do
   esac
   shift
 done
+
 # Setup java
 if [[ -z "$JAVA_HOME" ]]; then
-  if [[ `command -v java` ]]; then
-    # If java is in /usr/bin/java, we want /usr
-    JAVA_HOME="$(dirname $(dirname $(which java)))"
+  # Fallback on JAVA_HOME from rpm, if found
+  if [ $(command -v rpm) ]; then
+    RPM_JAVA_HOME="$(rpm -E %java_home 2>/dev/null)"
+    if [ "$RPM_JAVA_HOME" != "%java_home" ]; then
+      JAVA_HOME="$RPM_JAVA_HOME"
+      echo "No JAVA_HOME set, proceeding with '$JAVA_HOME' learned from rpm"
+    fi
+  fi
+
+  if [ -z "$JAVA_HOME" ]; then
+    if [[ `command -v java` ]]; then
+      # If java is in /usr/bin/java, we want /usr
+      JAVA_HOME="$(dirname $(dirname $(which java)))"
+    fi
   fi
 fi
 
@@ -114,6 +126,7 @@ if [[ -z "$JAVA_HOME" ]]; then
   exit -1
 fi
 
+export JAVA_HOME="$JAVA_HOME"
 echo "JAVA_HOME is set to $JAVA_HOME"
 
 if [[ $(command -v git) ]]; then
@@ -133,7 +146,6 @@ fi
 
 echo "MVN is set to $MVN"
 
-
 VERSION=$("$MVN" help:evaluate -Dexpression=project.version $@ 2>/dev/null\
     | grep -v "INFO"\
     | grep -v "WARNING"\

Reply via email to