From 20a27af5b29b0c392ee9cd77bdbcfa50172e09cb Mon Sep 17 00:00:00 2001 From: Daniel Zou Date: Fri, 26 Feb 2021 19:21:09 -0500 Subject: [PATCH] Use alternate JSON client language header method (#83) --- .../ApiClientVersionSubstitutions.java | 38 +++++++------------ .../native-image.properties | 3 +- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/google-cloud-graalvm-support/src/main/java/com/google/cloud/graalvm/features/substitutions/ApiClientVersionSubstitutions.java b/google-cloud-graalvm-support/src/main/java/com/google/cloud/graalvm/features/substitutions/ApiClientVersionSubstitutions.java index de71f1a4..a62a89e9 100644 --- a/google-cloud-graalvm-support/src/main/java/com/google/cloud/graalvm/features/substitutions/ApiClientVersionSubstitutions.java +++ b/google-cloud-graalvm-support/src/main/java/com/google/cloud/graalvm/features/substitutions/ApiClientVersionSubstitutions.java @@ -17,9 +17,7 @@ package com.google.cloud.graalvm.features.substitutions; import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.RecomputeFieldValue.CustomFieldValueTransformer; -import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; +import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import java.util.function.BooleanSupplier; @@ -33,33 +31,23 @@ final class ApiClientVersionSubstitutions { @Alias - @RecomputeFieldValue(kind = Kind.Custom, declClass = ApiVersionTransformer.class) - private static String DEFAULT_VERSION; + private String versionString; - private ApiClientVersionSubstitutions() { - } - - static class ApiVersionTransformer implements CustomFieldValueTransformer { - - @Override - public Object transform( - jdk.vm.ci.meta.MetaAccessProvider metaAccess, - jdk.vm.ci.meta.ResolvedJavaField original, - jdk.vm.ci.meta.ResolvedJavaField annotated, - Object receiver, - Object originalValue) { - String originalHeader = (String) originalValue; - String[] tokens = originalHeader.split(" "); + @Substitute + public String toString() { + String[] tokens = versionString.split(" "); - if (tokens.length > 0 && tokens[0].startsWith("gl-java")) { - tokens[0] += "-graalvm"; - return String.join(" ", tokens); - } else { - return originalValue; - } + if (tokens.length > 0 && tokens[0].startsWith("gl-java")) { + tokens[0] += "-graalvm"; + return String.join(" ", tokens); + } else { + return versionString; } } + private ApiClientVersionSubstitutions() { + } + static class OnlyIfInClassPath implements BooleanSupplier { @Override diff --git a/google-cloud-graalvm-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-graalvm-support/native-image.properties b/google-cloud-graalvm-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-graalvm-support/native-image.properties index 6f726893..db1cb1f9 100644 --- a/google-cloud-graalvm-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-graalvm-support/native-image.properties +++ b/google-cloud-graalvm-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-graalvm-support/native-image.properties @@ -8,4 +8,5 @@ Args = -H:+AllowIncompleteClasspath --report-unsupported-elements-at-runtime \ io.grpc.netty.shaded.io.netty.internal.tcnative.SSLPrivateKeyMethod,\ io.grpc.netty.shaded.io.grpc.netty,\ io.grpc.netty.shaded.io.netty.channel.epoll,\ - io.grpc.netty.shaded.io.netty.channel.unix + io.grpc.netty.shaded.io.netty.channel.unix,\ + com.google.api.client.googleapis.services.AbstractGoogleClientRequest$ApiClientVersion