Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Commit 257de0f

Browse files
fix(java): Register Spanner classes for reflection to fix Native Image tests (#760)
* fix(java): register Spanner classes and resource to fix Native Image tests * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent ccfd241 commit 257de0f

File tree

1 file changed

+51
-0
lines changed
  • native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients

1 file changed

+51
-0
lines changed

native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/SpannerFeature.java

+51
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,67 @@
2121
import com.oracle.svm.core.configure.ResourcesRegistry;
2222
import org.graalvm.nativeimage.ImageSingletons;
2323
import org.graalvm.nativeimage.hosted.Feature;
24+
import org.graalvm.nativeimage.impl.ConfigurationCondition;
2425

2526
/** Registers Spanner library classes for reflection. */
2627
@AutomaticFeature
2728
final class SpannerFeature implements Feature {
2829

2930
private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc";
3031
private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig";
32+
private static final String CLIENT_SIDE_IMPL_CLASS =
33+
"com.google.cloud.spanner.connection.ClientSideStatementImpl";
34+
private static final String CLIENT_SIDE_VALUE_CONVERTER =
35+
"com.google.cloud.spanner.connection.ClientSideStatementValueConverters";
36+
private static final String CONNECTION_IMPL =
37+
"com.google.cloud.spanner.connection.ConnectionImpl";
38+
private static final String CLIENT_SIDE_STATEMENTS =
39+
"com.google.cloud.spanner.connection.ClientSideStatements";
40+
private static final String CONNECTION_STATEMENT_EXECUTOR =
41+
"com.google.cloud.spanner.connection.ConnectionStatementExecutor";
42+
private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR =
43+
"com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor";
44+
private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR =
45+
"com.google.cloud.spanner.connection.ClientSideStatementSetExecutor";
46+
private static final String ABSTRACT_STATEMENT_PARSER =
47+
"com.google.cloud.spanner.connection.AbstractStatementParser";
48+
private static final String STATEMENT_PARSER =
49+
"com.google.cloud.spanner.connection.SpannerStatementParser";
3150

3251
@Override
3352
public void beforeAnalysis(BeforeAnalysisAccess access) {
3453
Class<?> spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS);
3554
if (spannerTestClass != null) {
3655
NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS);
3756
}
57+
if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) {
58+
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS);
59+
}
60+
if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) {
61+
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR);
62+
}
63+
if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) {
64+
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR);
65+
}
66+
if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) {
67+
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER);
68+
}
69+
if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) {
70+
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS);
71+
}
72+
if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) {
73+
NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR);
74+
}
75+
if (access.findClassByName(CONNECTION_IMPL) != null) {
76+
NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL);
77+
}
78+
if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) {
79+
NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER);
80+
}
81+
if (access.findClassByName(STATEMENT_PARSER) != null) {
82+
NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER);
83+
}
84+
3885
Class<?> spannerClass = access.findClassByName(SPANNER_CLASS);
3986
if (spannerClass != null) {
4087
NativeImageUtils.registerClassHierarchyForReflection(
@@ -47,9 +94,13 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
4794
// Resources
4895
ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class);
4996
resourcesRegistry.addResources(
97+
ConfigurationCondition.alwaysTrue(),
5098
"\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E");
5199
resourcesRegistry.addResources(
52100
"\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E");
101+
resourcesRegistry.addResources(
102+
ConfigurationCondition.alwaysTrue(),
103+
"\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E");
53104
}
54105
}
55106
}

0 commit comments

Comments
 (0)