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

Generalize Google JSON client configurations #81

Merged
merged 1 commit into from
Feb 24, 2021
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
public class GoogleJsonClientFeature implements Feature {

private static final String GOOGLE_API_CLIENT_CLASS =
"com.google.api.client.googleapis.GoogleUtils";
"com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient";

private static final String GOOGLE_HTTP_CLIENT_CLASS =
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
Expand All @@ -44,35 +47,38 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {

private void loadApiClient(BeforeAnalysisAccess access) {
// For com.google.api-client:google-api-client
Class<?> googleApiClass = access.findClassByName(GOOGLE_API_CLIENT_CLASS);
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));

if (googleApiClass != null) {
// Resources
ResourcesRegistry resourcesRegistry = ImageSingletons.lookup(ResourcesRegistry.class);
resourcesRegistry.addResources(
"\\Qcom/google/api/client/googleapis/google-api-client.properties\\E");

// Reflection calls
registerClassForReflection(
access, "com.google.api.client.googleapis.json.GoogleJsonError");
registerClassForReflection(
access, "com.google.api.client.googleapis.json.GoogleJsonError$ErrorInfo");
registerClassForReflection(
access, "com.google.api.client.googleapis.services.AbstractGoogleClientRequest");
registerClassForReflection(
access, "com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest");
}
}

private void loadHttpClient(BeforeAnalysisAccess access) {
// For com.google.http-client:google-http-client
Class<?> googleHttpClientClass = access.findClassByName(GOOGLE_HTTP_CLIENT_CLASS);
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);

if (googleHttpClientClass != null) {
registerClassForReflection(
access, "com.google.api.client.util.GenericData");
registerClassForReflection(
access, "com.google.api.client.json.GenericJson");
registerClassForReflection(
access, "com.google.api.client.json.webtoken.JsonWebToken");
registerClassForReflection(
Expand Down