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/13 12:27:40 UTC
[shardingsphere] branch master updated: Fix build-proxy-native-image on Nightly Build (#25632)
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 4e862ce4c24 Fix build-proxy-native-image on Nightly Build (#25632)
4e862ce4c24 is described below
commit 4e862ce4c247f81325551b2133584c37fbd0b2ec
Author: Ling Hengqian <li...@outlook.com>
AuthorDate: Sat May 13 20:27:28 2023 +0800
Fix build-proxy-native-image on Nightly Build (#25632)
---
.../expr/core/InlineExpressionParserFactory.java | 4 +-
.../core/InlineExpressionParserFactoryTest.java | 12 +++--
infra/expr/espresso/pom.xml | 18 +++++--
.../espresso/EspressoInlineExpressionParser.java | 56 ++++++++++++----------
.../EspressoInlineExpressionParserTest.java | 6 ++-
pom.xml | 2 +-
6 files changed, 62 insertions(+), 36 deletions(-)
diff --git a/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java b/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java
index 3d65e80fdf2..b9ca766679f 100644
--- a/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java
+++ b/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java
@@ -28,8 +28,8 @@ import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class InlineExpressionParserFactory {
- // workaround for https://github.com/helidon-io/helidon-build-tools/issues/858
- private static final boolean IS_SUBSTRATE_VM = "Substrate VM".equals(System.getProperty("java.vm.name"));
+ // workaround for https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/condition/EnabledInNativeImage.html
+ private static final boolean IS_SUBSTRATE_VM = "runtime".equals(System.getProperty("org.graalvm.nativeimage.imagecode"));
/**
* Create new instance of inline expression parser.
diff --git a/infra/expr/core/src/test/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactoryTest.java b/infra/expr/core/src/test/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactoryTest.java
index f68bf262241..931e47f3150 100644
--- a/infra/expr/core/src/test/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactoryTest.java
+++ b/infra/expr/core/src/test/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactoryTest.java
@@ -26,21 +26,25 @@ import static org.hamcrest.Matchers.is;
class InlineExpressionParserFactoryTest {
- private String originalJavaVmName;
+ private String originalImageCode;
@BeforeEach
public void setUp() {
- originalJavaVmName = System.getProperty("java.vm.name");
+ originalImageCode = System.getProperty("org.graalvm.nativeimage.imagecode");
}
@AfterEach
public void tearDown() {
- System.setProperty("java.vm.name", originalJavaVmName);
+ if (null != originalImageCode) {
+ System.setProperty("org.graalvm.nativeimage.imagecode", originalImageCode);
+ } else {
+ System.clearProperty("org.graalvm.nativeimage.imagecode");
+ }
}
@Test
void assertNewInstance() {
- System.setProperty("java.vm.name", "");
+ System.setProperty("org.graalvm.nativeimage.imagecode", "");
assertThat(InlineExpressionParserFactory.newInstance().getType(), is("HOTSPOT"));
}
}
diff --git a/infra/expr/espresso/pom.xml b/infra/expr/espresso/pom.xml
index e2bf5c7bb5e..f42acefa02d 100644
--- a/infra/expr/espresso/pom.xml
+++ b/infra/expr/espresso/pom.xml
@@ -66,13 +66,26 @@
<phase>prepare-package</phase>
<configuration>
<artifactItems>
+ <artifactItem>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-expr-spi</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-infra-util</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <overWrite>true</overWrite>
+ </artifactItem>
<artifactItem>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-expr-hotsopt</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
- <destFileName>shardingsphere-infra-expr-hotsopt.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.apache.groovy</groupId>
@@ -80,7 +93,6 @@
<version>${groovy.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
- <destFileName>groovy.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>com.google.guava</groupId>
@@ -88,9 +100,9 @@
<version>${guava.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
- <destFileName>guava.jar</destFileName>
</artifactItem>
</artifactItems>
+ <stripVersion>true</stripVersion>
<outputDirectory>${project.build.outputDirectory}/espresso-need-libs</outputDirectory>
</configuration>
</execution>
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 9c1d28d2a69..23b3f0b7168 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
@@ -26,9 +26,10 @@ import org.graalvm.polyglot.TypeLiteral;
import org.graalvm.polyglot.Value;
import java.net.URL;
-import java.util.Collections;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Espresso inline expression parser.
@@ -37,46 +38,53 @@ public final class EspressoInlineExpressionParser implements InlineExpressionPar
private static final String JAVA_CLASSPATH;
+ private static final String JAVA_HOME;
+
static {
- // TODO https://github.com/oracle/graal/issues/4555 not yet closed
- 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");
+ JAVA_HOME = System.getenv("JAVA_HOME");
+ URL resource = EspressoInlineExpressionParser.class.getClassLoader().getResource("espresso-need-libs");
+ String dir = null != resource ? resource.getPath() : null;
+ JAVA_CLASSPATH = Stream.of("groovy.jar", "guava.jar", "shardingsphere-infra-expr-hotsopt.jar",
+ "shardingsphere-infra-expr-spi.jar", "shardingsphere-infra-util.jar")
+ .map(s -> dir + "/" + s)
+ .collect(Collectors.joining(":"));
}
@Override
public String handlePlaceHolder(final String inlineExpression) {
- try (Context context = getContext()) {
- return context.getBindings("java").getMember(HotspotInlineExpressionParser.class.getName()).invokeMember("handlePlaceHolder", inlineExpression).asString();
+ try (Context context = createContext()) {
+ return createInlineExpressionParser(context).invokeMember("handlePlaceHolder", inlineExpression).asString();
}
}
@Override
public List<String> splitAndEvaluate(final String inlineExpression) {
- List<String> splitAndEvaluate = getInlineExpressionParser().invokeMember("splitAndEvaluate", inlineExpression).as(new TypeLiteral<List<String>>() {
- });
- // GraalVM Truffle Espresso 22.3.1 has a different behavior for generic List than Hotspot.
- return splitAndEvaluate.isEmpty() ? Collections.emptyList() : splitAndEvaluate;
+ try (Context context = createContext()) {
+ List<String> listProjection = createInlineExpressionParser(context).invokeMember("splitAndEvaluate", inlineExpression)
+ .as(new TypeLiteral<List<String>>() {
+ });
+ // org.graalvm.polyglot.Value#as only creates projections for classes in Truffle Context
+ return new ArrayList<>(listProjection);
+ }
}
@Override
public Closure<?> evaluateClosure(final String inlineExpression) {
- return getInlineExpressionParser().invokeMember("evaluateClosure", inlineExpression).as(Closure.class);
+ try (Context context = createContext()) {
+ return createInlineExpressionParser(context).invokeMember("evaluateClosure", inlineExpression).as(Closure.class);
+ }
}
- private Value getInlineExpressionParser() {
- try (Context context = getContext()) {
- return context.getBindings("java").getMember(HotspotInlineExpressionParser.class.getName()).newInstance();
- }
+ private Value createInlineExpressionParser(final Context context) {
+ return context.getBindings("java").getMember(HotspotInlineExpressionParser.class.getName()).newInstance();
}
- private Context getContext() {
- return Context.newBuilder().allowAllAccess(true)
- .option("java.Properties.org.graalvm.home", System.getenv("JAVA_HOME"))
+ private Context createContext() {
+ // TODO https://github.com/oracle/graal/issues/4555 not yet closed
+ ShardingSpherePreconditions.checkNotNull(JAVA_HOME, () -> new RuntimeException("Failed to determine the system's environment variable JAVA_HOME!"));
+ return Context.newBuilder()
+ .allowAllAccess(true)
+ .option("java.Properties.org.graalvm.home", JAVA_HOME)
.option("java.MultiThreaded", Boolean.TRUE.toString())
.option("java.Classpath", JAVA_CLASSPATH)
.build();
diff --git a/infra/expr/espresso/src/test/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParserTest.java b/infra/expr/espresso/src/test/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParserTest.java
index 6cbaefd6040..c5bc5e4c9f3 100644
--- a/infra/expr/espresso/src/test/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParserTest.java
+++ b/infra/expr/espresso/src/test/java/org/apache/shardingsphere/infra/expr/espresso/EspressoInlineExpressionParserTest.java
@@ -17,8 +17,9 @@
package org.apache.shardingsphere.infra.expr.espresso;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledInNativeImage;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import java.util.Collections;
@@ -29,6 +30,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@EnabledInNativeImage
+@DisabledIfSystemProperty(named = "org.graalvm.nativeimage.imagecode", matches = "agent", disabledReason = "Skip this unit test when using GraalVM Native Build Tools")
class EspressoInlineExpressionParserTest {
@Test
@@ -123,7 +125,7 @@ class EspressoInlineExpressionParserTest {
* Because `org.graalvm.polyglot.Value#as` does not allow this type to be returned from the guest JVM.
*/
@Test
- @DisabledInNativeImage
+ @Disabled
void assertEvaluateClosure() {
assertThat(new EspressoInlineExpressionParser().evaluateClosure("${1+2}").call().toString(), is("3"));
}
diff --git a/pom.xml b/pom.xml
index b84bf7d2c98..5f7275450be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -125,7 +125,7 @@
<dockerfile-maven.version>1.4.13</dockerfile-maven.version>
<docker-compose-maven-plugin.version>4.0.0</docker-compose-maven-plugin.version>
<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
- <native-maven-plugin.version>0.9.21</native-maven-plugin.version>
+ <native-maven-plugin.version>0.9.22</native-maven-plugin.version>
<!-- Compile plugin versions -->
<maven-enforcer-plugin.version>3.2.1</maven-enforcer-plugin.version>