Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Copy over configurations from java-core/native-image-support #384

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.oracle.svm.core.configure.ResourcesRegistry;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.impl.ConfigurationCondition;

/**
* Registers Spanner library classes for reflection.
Expand All @@ -28,9 +29,57 @@
final class SpannerFeature implements Feature {

private static final String SPANNER_CLASS = "com.google.spanner.v1.SpannerGrpc";
private static final String SPANNER_TEST_CLASS = "com.google.cloud.spanner.GceTestEnvConfig";
private static final String MOCK_CLASS = "com.google.cloud.spanner.MockDatabaseAdminServiceImpl";
private static final String CLIENT_SIDE_IMPL_CLASS =
"com.google.cloud.spanner.connection.ClientSideStatementImpl";
private static final String CLIENT_SIDE_VALUE_CONVERTER =
"com.google.cloud.spanner.connection.ClientSideStatementValueConverters";
private static final String CONNECTION_IMPL =
"com.google.cloud.spanner.connection.ConnectionImpl";
private static final String CLIENT_SIDE_STATEMENTS =
"com.google.cloud.spanner.connection.ClientSideStatements";
private static final String CONNECTION_STATEMENT_EXECUTOR =
"com.google.cloud.spanner.connection.ConnectionStatementExecutor";
private static final String CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR =
"com.google.cloud.spanner.connection.ClientSideStatementNoParamExecutor";
private static final String CLIENT_SIDE_STATEMENT_SET_EXECUTOR =
"com.google.cloud.spanner.connection.ClientSideStatementSetExecutor";
private static final String ABSTRACT_STATEMENT_PARSER =
"com.google.cloud.spanner.connection.AbstractStatementParser";
private static final String STATEMENT_PARSER =
"com.google.cloud.spanner.connection.SpannerStatementParser";

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
registerSpannerTestClasses(access);
if (access.findClassByName(CLIENT_SIDE_IMPL_CLASS) != null) {
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_IMPL_CLASS);
}
if (access.findClassByName(CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_NO_PARAM_EXECUTOR);
}
if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR);
}
if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) {
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER);
}
if (access.findClassByName(CLIENT_SIDE_STATEMENTS) != null) {
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENTS);
}
if (access.findClassByName(CONNECTION_STATEMENT_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(access, CONNECTION_STATEMENT_EXECUTOR);
}
if (access.findClassByName(CONNECTION_IMPL) != null) {
NativeImageUtils.registerClassForReflection(access, CONNECTION_IMPL);
}
if (access.findClassByName(ABSTRACT_STATEMENT_PARSER) != null) {
NativeImageUtils.registerClassHierarchyForReflection(access, ABSTRACT_STATEMENT_PARSER);
}
if (access.findClassByName(STATEMENT_PARSER) != null) {
NativeImageUtils.registerConstructorsForReflection(access, STATEMENT_PARSER);
}
Class<?> spannerClass = access.findClassByName(SPANNER_CLASS);
if (spannerClass != null) {
NativeImageUtils.registerClassHierarchyForReflection(
Expand All @@ -43,9 +92,27 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
// Resources
ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class);
resourcesRegistry.addResources(
ConfigurationCondition.alwaysTrue(),
"\\Qcom/google/cloud/spanner/connection/ClientSideStatements.json\\E");
resourcesRegistry.addResources(
ConfigurationCondition.alwaysTrue(),
"\\Qcom/google/cloud/spanner/spi/v1/grpc-gcp-apiconfig.json\\E");
resourcesRegistry.addResources(
ConfigurationCondition.alwaysTrue(),
"\\Qcom/google/cloud/spanner/connection/ITSqlScriptTest_TestQueryOptions.sql\\E");
}
}


private void registerSpannerTestClasses(BeforeAnalysisAccess access) {
Class<?> spannerTestClass = access.findClassByName(SPANNER_TEST_CLASS);
if (spannerTestClass != null) {
NativeImageUtils.registerConstructorsForReflection(access, SPANNER_TEST_CLASS);
}
Class<?> mockClass = access.findClassByName(MOCK_CLASS);
if (mockClass != null) {
NativeImageUtils.registerClassForReflection(
access, "com.google.cloud.spanner.MockDatabaseAdminServiceImpl$MockBackup");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
@AutomaticFeature
final class OpenCensusFeature implements Feature {

private static final String OPEN_CENSUS_CLASS = "io.opencensus.impl.tags.TagsComponentImpl";
private static final String TAGS_COMPONENT_CLASS = "io.opencensus.impl.tags.TagsComponentImpl";
private static final String STATS_COMPONENT_CLASS = "io.opencensus.impl.stats.StatsComponentImpl";

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
if (access.findClassByName(OPEN_CENSUS_CLASS) != null) {
if (access.findClassByName(STATS_COMPONENT_CLASS) != null) {
registerForReflectiveInstantiation(access, STATS_COMPONENT_CLASS);
}
if (access.findClassByName(TAGS_COMPONENT_CLASS) != null) {
registerForReflectiveInstantiation(
access, "io.opencensus.impl.metrics.MetricsComponentImpl");
registerForReflectiveInstantiation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Args = --allow-incomplete-classpath \
--enable-url-protocols=https,http \
--initialize-at-build-time=org.conscrypt \
--initialize-at-build-time=org.conscrypt,\
org.slf4j.LoggerFactory,\
org.junit.platform.engine.TestTag,\
com.google.cloud.spanner.IntegrationTestEnv \
--initialize-at-run-time=io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl,\
io.grpc.netty.shaded.io.netty.internal.tcnative.SSL,\
io.grpc.netty.shaded.io.netty.internal.tcnative.CertificateVerifier,\
Expand Down