You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/05/08 07:09:01 UTC

[shardingsphere] branch master updated: Restrict Espresso API to only detect JAVA_HOME under Native Image (#25515)

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

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 909990dd3d0 Restrict Espresso API to only detect JAVA_HOME under Native Image (#25515)
909990dd3d0 is described below

commit 909990dd3d0119c612cdd4ddf99cfe8716456004
Author: Ling Hengqian <li...@outlook.com>
AuthorDate: Mon May 8 15:08:53 2023 +0800

    Restrict Espresso API to only detect JAVA_HOME under Native Image (#25515)
---
 .../infra/expr/espresso/EspressoInlineExpressionParser.java    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/infra/expr/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParser.java b/infra/expr/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParser.java
index ea4914a4144..e9def8450b0 100644
--- a/infra/expr/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParser.java
+++ b/infra/expr/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParser.java
@@ -34,14 +34,14 @@ import java.util.Objects;
  */
 public final class EspressoInlineExpressionParser implements JVMInlineExpressionParser {
 
-    private static final String JAVA_HOME;
-
     private static final String JAVA_CLASSPATH;
 
     static {
         // TODO https://github.com/oracle/graal/issues/4555 not yet closed
-        JAVA_HOME = System.getenv("JAVA_HOME");
-        ShardingSpherePreconditions.checkNotNull(JAVA_HOME, () -> new RuntimeException("Failed to determine the system's environment variable JAVA_HOME!"));
+        if ("Substrate VM".equals(System.getProperty("java.vm.name"))) {
+            String javaHome = System.getenv("JAVA_HOME");
+            ShardingSpherePreconditions.checkNotNull(javaHome, () -> new RuntimeException("Failed to determine the system's environment variable JAVA_HOME!"));
+        }
         URL resource = Objects.requireNonNull(EspressoInlineExpressionParser.class.getClassLoader().getResource("espresso-need-libs"));
         String dir = resource.getPath();
         JAVA_CLASSPATH = String.join(":", dir + "/groovy.jar", dir + "/guava.jar", dir + "/shardingsphere-infra-expr-hotsopt.jar");
@@ -84,7 +84,7 @@ public final class EspressoInlineExpressionParser implements JVMInlineExpression
 
     private Context getContext() {
         return Context.newBuilder().allowAllAccess(true)
-                .option("java.Properties.org.graalvm.home", JAVA_HOME)
+                .option("java.Properties.org.graalvm.home", System.getenv("JAVA_HOME"))
                 .option("java.MultiThreaded", Boolean.TRUE.toString())
                 .option("java.Classpath", JAVA_CLASSPATH)
                 .build();