|
| 1 | +package com.google.api.client.extensions.appengine.nativeimage; |
| 2 | + |
| 3 | +import com.google.common.collect.ImmutableList; |
| 4 | +import java.util.List; |
| 5 | +import org.graalvm.nativeimage.hosted.Feature; |
| 6 | +import org.graalvm.nativeimage.hosted.RuntimeReflection; |
| 7 | + |
| 8 | +public class HttpAppEngineFeature implements Feature { |
| 9 | + private static final List<String> APP_ENGINE_CLASSES = |
| 10 | + ImmutableList.of( |
| 11 | + "com.google.appengine.api.appidentity.AppIdentityServicePb", |
| 12 | + "com.google.appengine.api.capabilities.CapabilityServicePb", |
| 13 | + "com.google.appengine.api.modules.ModulesServicePb"); |
| 14 | + |
| 15 | + private static final List<String> APP_HOSTING_CLASSES = |
| 16 | + ImmutableList.of( |
| 17 | + "com.google.apphosting.api.UserServicePb", |
| 18 | + "com.google.apphosting.api.logservice.LogServicePb"); |
| 19 | + |
| 20 | + @Override |
| 21 | + public void beforeAnalysis(BeforeAnalysisAccess access) { |
| 22 | + try { |
| 23 | + for (String className : APP_ENGINE_CLASSES) { |
| 24 | + registerClassForReflection(className, access); |
| 25 | + } |
| 26 | + for (String className : APP_HOSTING_CLASSES) { |
| 27 | + registerClassForReflection(className, access); |
| 28 | + } |
| 29 | + } catch (Throwable e) { |
| 30 | + throw new RuntimeException("Error configuring TestFeature", e); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + private void registerClassForReflection( |
| 35 | + String classFullQualifiedName, BeforeAnalysisAccess access) { |
| 36 | + Class<?> clazz = access.findClassByName(classFullQualifiedName); |
| 37 | + RuntimeReflection.register(clazz); |
| 38 | + RuntimeReflection.register(clazz.getDeclaredConstructors()); |
| 39 | + RuntimeReflection.register(clazz.getDeclaredMethods()); |
| 40 | + RuntimeReflection.register(clazz.getDeclaredFields()); |
| 41 | + for (Class<?> subClass : clazz.getInterfaces()) { |
| 42 | + registerClassForReflection(subClass.getName(), access); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments