From 6f600ab9629ec988eaa9c72db433401a6b36891e Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Mon, 11 Apr 2022 17:16:32 -0400 Subject: [PATCH 1/2] feat: remove GoogleJsonClentFeature and OpenCensusFeature after relocation --- .../features/GoogleJsonClientFeature.java | 99 ------------------- .../features/clients/OpenCensusFeature.java | 42 -------- 2 files changed, 141 deletions(-) delete mode 100644 native-image-support/src/main/java/com/google/cloud/nativeimage/features/GoogleJsonClientFeature.java delete mode 100644 native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/OpenCensusFeature.java diff --git a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/GoogleJsonClientFeature.java b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/GoogleJsonClientFeature.java deleted file mode 100644 index 8cc3107f4e..0000000000 --- a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/GoogleJsonClientFeature.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.nativeimage.features; - -import static com.google.cloud.nativeimage.features.NativeImageUtils.registerClassForReflection; - -import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.configure.ResourcesRegistry; -import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.hosted.Feature; - -/** Configures Native Image settings for the Google JSON Client. */ -@AutomaticFeature -final class GoogleJsonClientFeature implements Feature { - - private static final String GOOGLE_API_CLIENT_CLASS = - "com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient"; - - private static final String GOOGLE_API_CLIENT_REQUEST_CLASS = - "com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest"; - - private static final String GENERIC_JSON_CLASS = "com.google.api.client.json.GenericJson"; - - @Override - public void beforeAnalysis(BeforeAnalysisAccess access) { - loadApiClient(access); - loadHttpClient(access); - loadMiscClasses(access); - } - - private void loadApiClient(BeforeAnalysisAccess access) { - // For com.google.api-client:google-api-client - Class googleApiClientClass = access.findClassByName(GOOGLE_API_CLIENT_CLASS); - - if (googleApiClientClass != null) { - // All reachable instances of the AbstractGoogleJsonClient must be registered. - access.registerSubtypeReachabilityHandler( - (duringAccess, subtype) -> registerClassForReflection(access, subtype.getName()), - googleApiClientClass); - - // All reachable instances of the AbstractGoogleJsonClientRequest must be registered. - access.registerSubtypeReachabilityHandler( - (duringAccess, subtype) -> registerClassForReflection(access, subtype.getName()), - access.findClassByName(GOOGLE_API_CLIENT_REQUEST_CLASS)); - - // Resources - ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class); - resourcesRegistry.addResources( - "\\Qcom/google/api/client/googleapis/google-api-client.properties\\E"); - resourcesRegistry.addResources("\\Qcom/google/api/client/googleapis/google.p12\\E"); - resourcesRegistry.addResources( - "\\Qcom/google/api/client/http/google-http-client.properties\\E"); - } - } - - private void loadHttpClient(BeforeAnalysisAccess access) { - // For com.google.http-client:google-http-client - Class genericJsonClass = access.findClassByName(GENERIC_JSON_CLASS); - - if (genericJsonClass != null) { - // All reachable instances of GenericJson must be registered. - access.registerSubtypeReachabilityHandler( - (duringAccess, subtype) -> registerClassForReflection(access, subtype.getName()), - genericJsonClass); - - registerClassForReflection(access, "com.google.api.client.util.GenericData"); - registerClassForReflection(access, "com.google.api.client.json.webtoken.JsonWebToken"); - registerClassForReflection(access, "com.google.api.client.json.webtoken.JsonWebToken$Header"); - registerClassForReflection( - access, "com.google.api.client.json.webtoken.JsonWebToken$Payload"); - registerClassForReflection( - access, "com.google.api.client.json.webtoken.JsonWebSignature$Header"); - registerClassForReflection(access, "com.google.api.client.json.webtoken.JsonWebSignature"); - registerClassForReflection(access, "com.google.api.client.http.UrlEncodedContent"); - registerClassForReflection(access, "com.google.api.client.http.GenericUrl"); - registerClassForReflection(access, "com.google.api.client.http.HttpRequest"); - registerClassForReflection(access, "com.google.api.client.http.HttpHeaders"); - } - } - - private void loadMiscClasses(BeforeAnalysisAccess access) { - registerClassForReflection(access, "com.google.common.util.concurrent.AbstractFuture"); - registerClassForReflection(access, "com.google.common.util.concurrent.AbstractFuture$Waiter"); - } -} diff --git a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/OpenCensusFeature.java b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/OpenCensusFeature.java deleted file mode 100644 index e718f28567..0000000000 --- a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/clients/OpenCensusFeature.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.nativeimage.features.clients; - -import static com.google.cloud.nativeimage.features.NativeImageUtils.registerForReflectiveInstantiation; - -import com.oracle.svm.core.annotate.AutomaticFeature; -import org.graalvm.nativeimage.hosted.Feature; - -/** Registers reflection usage in OpenCensus libraries. */ -@AutomaticFeature -final class OpenCensusFeature implements Feature { - - 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(STATS_COMPONENT_CLASS) != null) { - registerForReflectiveInstantiation(access, STATS_COMPONENT_CLASS); - } - if (access.findClassByName(TAGS_COMPONENT_CLASS) != null) { - registerForReflectiveInstantiation(access, "io.opencensus.impl.metrics.MetricsComponentImpl"); - registerForReflectiveInstantiation(access, "io.opencensus.impl.tags.TagsComponentImpl"); - registerForReflectiveInstantiation(access, "io.opencensus.impl.trace.TraceComponentImpl"); - } - } -} From cfbadf7e5ca87b48a78e8137d843c63cd0447e5c Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Mon, 11 Apr 2022 17:37:54 -0400 Subject: [PATCH 2/2] remove unused dependency --- native-image-support/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/native-image-support/pom.xml b/native-image-support/pom.xml index d1b6884e0f..e2c4ed978b 100644 --- a/native-image-support/pom.xml +++ b/native-image-support/pom.xml @@ -21,11 +21,6 @@ - - com.google.guava - guava - - io.grpc grpc-netty-shaded