// Path: native-image-support/src/main/java/com/google/cloud/nativeimage/features/NativeImageUtils.java
// public static void registerClassForReflection(FeatureAccess access, String name) {
//   Class<?> clazz = access.findClassByName(name);
//   if (clazz != null) {
//     RuntimeReflection.register(clazz);
//     RuntimeReflection.register(clazz.getDeclaredConstructors());
//     RuntimeReflection.register(clazz.getDeclaredFields());
//     RuntimeReflection.register(clazz.getDeclaredMethods());
//   } else {
//     LOGGER.warning(
//         "Failed to find " + name + " on the classpath for reflection.");
//   }
// }


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;
/*
 * Copyright 2020-2021 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.core;



/**
 * 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(
// Path: native-image-support/src/main/java/com/google/cloud/nativeimage/features/NativeImageUtils.java
// public static void registerClassForReflection(FeatureAccess access, String name) {
//   Class<?> clazz = access.findClassByName(name);
//   if (clazz != null) {
//     RuntimeReflection.register(clazz);
//     RuntimeReflection.register(clazz.getDeclaredConstructors());
//     RuntimeReflection.register(clazz.getDeclaredFields());
//     RuntimeReflection.register(clazz.getDeclaredMethods());
//   } else {
//     LOGGER.warning(
//         "Failed to find " + name + " on the classpath for reflection.");
//   }
// }


// Path: native-image-support/src/main/java/com/google/cloud/nativeimage/features/core/GoogleJsonClientFeature.java
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;

/*
 * Copyright 2020-2021 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.core;



/**
 * 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()),