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

Commit

Permalink
Use alternate JSON client language header method (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzou authored Feb 27, 2021
1 parent b5219df commit 20a27af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 20a27af

Please sign in to comment.