diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json index 02082e722764e..56e1291380d1a 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json @@ -65,31 +65,6 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, "name":"org.apache.shardingsphere.driver.api.yaml.YamlJDBCConfigurationCustomizer" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"}, - "name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath.AbsolutePathURLProvider", - "methods":[{"name":"","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"}, - "name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath.AbsolutePathWithEnvironmentURLProvider", - "methods":[{"name":"","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"}, - "name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathURLProvider", - "methods":[{"name":"","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"}, - "name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathWithEnvironmentURLProvider", - "methods":[{"name":"","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"}, - "name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathWithSystemPropsURLProvider", - "methods":[{"name":"","parameterTypes":[] }] -}, { "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.rule.EncryptRule"}, "name":"org.apache.shardingsphere.encrypt.algorithm.assisted.MD5AssistedEncryptAlgorithm", @@ -174,6 +149,45 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.config.shortcut.YamlRuleConfigurationShortcuts"}, "name":"org.apache.shardingsphere.globalclock.core.yaml.config.YamlGlobalClockRuleConfiguration" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.yaml.swapper.NewYamlEncryptRuleConfigurationSwapper"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", + "allDeclaredFields":true, + "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", + "allDeclaredFields":true, + "queryAllPublicMethods":true, + "methods":[{"name":"","parameterTypes":[] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }, {"name":"setType","parameterTypes":["java.lang.String"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mask.yaml.swapper.NewYamlMaskRuleConfigurationSwapper"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", + "allDeclaredFields":true, + "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.NewYamlShadowRuleConfigurationSwapper"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", + "allDeclaredFields":true, + "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.NewYamlShardingRuleConfigurationSwapper"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", + "allDeclaredFields":true, + "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationBeanInfo" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, + "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationCustomizer" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService"}, "name":"org.apache.shardingsphere.infra.instance.ComputeNodeData", @@ -189,6 +203,16 @@ "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.service.ComputeNodeStatusService"}, "name":"org.apache.shardingsphere.infra.instance.ComputeNodeDataCustomizer" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"}, + "name":"org.apache.shardingsphere.infra.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"}, + "name":"org.apache.shardingsphere.infra.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheBuilder"}, "name":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader" @@ -208,45 +232,6 @@ "name":"org.apache.shardingsphere.infra.util.yaml.YamlConfiguration", "queryAllPublicMethods":true }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.yaml.swapper.NewYamlEncryptRuleConfigurationSwapper"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration", - "allDeclaredFields":true, - "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration", - "allDeclaredFields":true, - "queryAllPublicMethods":true, - "methods":[{"name":"","parameterTypes":[] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }, {"name":"setType","parameterTypes":["java.lang.String"] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mask.yaml.swapper.NewYamlMaskRuleConfigurationSwapper"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration", - "allDeclaredFields":true, - "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.NewYamlShadowRuleConfigurationSwapper"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration", - "allDeclaredFields":true, - "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.NewYamlShardingRuleConfigurationSwapper"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration", - "allDeclaredFields":true, - "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfigurationBeanInfo" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, - "name":"org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfigurationCustomizer" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, "name":"org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration", @@ -365,16 +350,6 @@ "condition":{"typeReachable":"org.apache.shardingsphere.metadata.persist.service.schema.NewTableMetaDataPersistService"}, "name":"org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereTableCustomizer" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"}, - "name":"org.apache.shardingsphere.keygen.snowflake.algorithm.SnowflakeKeyGenerateAlgorithm", - "methods":[{"name":"","parameterTypes":[] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.rule.ShardingRule"}, - "name":"org.apache.shardingsphere.keygen.uuid.algorithm.UUIDKeyGenerateAlgorithm", - "methods":[{"name":"","parameterTypes":[] }] -}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.config.shortcut.YamlRuleConfigurationShortcuts"}, "name":"org.apache.shardingsphere.logging.yaml.config.YamlLoggingRuleConfiguration" @@ -979,7 +954,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, "name":"org.apache.shardingsphere.sql.parser.mysql.visitor.statement.type.MySQLDMLStatementVisitor", "methods":[{"name":"","parameterTypes":[] }] }, @@ -1004,7 +979,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, "name":"org.apache.shardingsphere.sql.parser.opengauss.visitor.statement.type.OpenGaussDMLStatementVisitor", "methods":[{"name":"","parameterTypes":[] }] }, @@ -1034,7 +1009,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, "name":"org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.type.PostgreSQLDMLStatementVisitor", "methods":[{"name":"","parameterTypes":[] }] }, @@ -1124,7 +1099,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.parser.cache.SQLStatementCacheLoader"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, "name":"org.apache.shardingsphere.sql.parser.sqlserver.visitor.statement.type.SQLServerDMLStatementVisitor", "methods":[{"name":"","parameterTypes":[] }] }, diff --git a/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java b/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java index dce0a566f3426..df3e6412e629d 100644 --- a/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java +++ b/infra/url/type/classpath/src/main/java/org/apache/shardingsphere/infra/url/classpath/ClassPathURLLoader.java @@ -20,10 +20,11 @@ import lombok.SneakyThrows; import org.apache.shardingsphere.infra.url.spi.ShardingSphereURLLoader; -import java.io.File; +import java.io.BufferedReader; import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.Properties; import java.util.stream.Collectors; @@ -36,12 +37,12 @@ public final class ClassPathURLLoader implements ShardingSphereURLLoader { @Override @SneakyThrows(IOException.class) public String load(final String configurationSubject, final Properties queryProps) { - return Files.readAllLines(getResourceFile(configurationSubject).toPath()).stream().collect(Collectors.joining(System.lineSeparator())); - } - - @SneakyThrows(URISyntaxException.class) - private File getResourceFile(final String configurationSubject) { - return new File(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(configurationSubject)).toURI().getPath()); + try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configurationSubject)) { + Objects.requireNonNull(inputStream); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + return reader.lines().collect(Collectors.joining(System.lineSeparator())); + } + } } @Override diff --git a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java index 94f691d680cfd..8a9085e64a35f 100644 --- a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java +++ b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java @@ -85,15 +85,10 @@ public static JDBCRepositorySQL load(final String type) { } /** - * Under the GraalVM Native Image, although there is - * `com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider`, the corresponding - * `com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem` does not autoload. This is mainly to align the - * behavior of `ZipFileSystemProvider`, so ShardingSphere need to manually open and close the FileSystem - * corresponding to the `resource:/` scheme. For more background reference oracle/graal#7682. - *

- * ShardingSphere use the System Property of `org.graalvm.nativeimage.imagecode` to identify whether this class is in the - * GraalVM Native Image environment. The background of this property comes from - * Annotation Interface DisabledInNativeImage. + * Under the GraalVM Native Image, `com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem` does not autoload. + * This is mainly to align the behavior of `jdk.nio.zipfs.ZipFileSystem`, + * so ShardingSphere need to manually open and close the FileSystem corresponding to the `resource:/` scheme. + * For more background reference oracle/graal#7682. * * @param url url * @param type type of JDBC repository SQL @@ -104,13 +99,12 @@ public static JDBCRepositorySQL load(final String type) { * @see sun.nio.fs.UnixFileSystemProvider */ private static JDBCRepositorySQL loadFromDirectory(final URL url, final String type) throws URISyntaxException, IOException { - if (null == System.getProperty("org.graalvm.nativeimage.imagecode") || !"runtime".equals(System.getProperty("org.graalvm.nativeimage.imagecode"))) { - return loadFromDirectoryLegacy(url, type); - } else { + if ("resource".equals(url.getProtocol())) { try (FileSystem ignored = FileSystems.newFileSystem(URI.create("resource:/"), Collections.emptyMap())) { return loadFromDirectoryInNativeImage(url, type); } } + return loadFromDirectoryLegacy(url, type); } /** diff --git a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json index 2c18921fb05aa..74ded5e33d0d7 100644 --- a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json +++ b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json @@ -5,7 +5,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.rule.EncryptRule"}, + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.features.EncryptTest"}, "name":"org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.TestQueryAssistedShardingEncryptAlgorithm", "methods":[{"name":"","parameterTypes":[] }] } diff --git a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json index eb118f6ef69d3..9722265d59c63 100644 --- a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json +++ b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json @@ -1,7 +1,7 @@ { "resources":{ "includes":[{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.NewMetaDataContextsFactory"}, + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.SQLServerTest"}, "pattern":"\\Qcontainer-license-acceptance.txt\\E" }, { "condition":{"typeReachable":"ch.qos.logback.core.util.Loader"},