diff --git a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/ApiClientVersionSubstitutions.java b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/ApiClientVersionSubstitutions.java deleted file mode 100644 index c170c2ea7a..0000000000 --- a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/ApiClientVersionSubstitutions.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2022 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.substitutions; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import java.util.function.BooleanSupplier; - -/** Substitution for setting Java version correctly in the Google Java Http Client. */ -@TargetClass( - className = - "com.google.api.client.googleapis.services.AbstractGoogleClientRequest$ApiClientVersion", - onlyWith = ApiClientVersionSubstitutions.OnlyIfInClassPath.class) -final class ApiClientVersionSubstitutions { - - @Alias private String versionString; - - @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 versionString; - } - } - - private ApiClientVersionSubstitutions() {} - - static class OnlyIfInClassPath implements BooleanSupplier { - - @Override - public boolean getAsBoolean() { - try { - // Note: Set initialize = false to avoid initializing the class when looking it up. - Class.forName( - "com.google.api.client.googleapis.services." - + "AbstractGoogleClientRequest$ApiClientVersion", - false, - Thread.currentThread().getContextClassLoader()); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - } -} diff --git a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/GaxPropertiesSubstitutions.java b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/GaxPropertiesSubstitutions.java deleted file mode 100644 index 54245a8ee8..0000000000 --- a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/GaxPropertiesSubstitutions.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2022 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.substitutions; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; -import com.oracle.svm.core.annotate.TargetClass; -import java.util.function.BooleanSupplier; - -/** - * This file contains the GaxProperties substitution to correctly set the Java language string in - * API call headers for Native Image users. - */ -@TargetClass( - className = "com.google.api.gax.core.GaxProperties", - onlyWith = GaxPropertiesSubstitutions.OnlyIfInClassPath.class) -final class GaxPropertiesSubstitutions { - - @Alias - @RecomputeFieldValue(kind = Kind.FromAlias) - private static String JAVA_VERSION = System.getProperty("java.version") + "-graalvm"; - - private GaxPropertiesSubstitutions() {} - - static class OnlyIfInClassPath implements BooleanSupplier { - - @Override - public boolean getAsBoolean() { - try { - // Note: Set initialize = false to avoid initializing the class when looking it up. - Class.forName( - "com.google.api.gax.core.GaxProperties", - false, - Thread.currentThread().getContextClassLoader()); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - } -} diff --git a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/NettyInternalLoggerFactorySubstitutions.java b/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/NettyInternalLoggerFactorySubstitutions.java deleted file mode 100644 index 7fcea16318..0000000000 --- a/native-image-support/src/main/java/com/google/cloud/nativeimage/features/substitutions/NettyInternalLoggerFactorySubstitutions.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2022 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.substitutions; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory; -import io.grpc.netty.shaded.io.netty.util.internal.logging.JdkLoggerFactory; -import java.util.function.BooleanSupplier; - -/** - * Substitutions for {@link InternalLoggerFactory} which are needed to avoid dynamic loading of - * logging library. - */ -@TargetClass( - className = "io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory", - onlyWith = NettyInternalLoggerFactorySubstitutions.OnlyIfInClassPath.class) -final class NettyInternalLoggerFactorySubstitutions { - - @Substitute - private static InternalLoggerFactory newDefaultFactory(String name) { - return JdkLoggerFactory.INSTANCE; - } - - static class OnlyIfInClassPath implements BooleanSupplier { - - @Override - public boolean getAsBoolean() { - try { - // Note: Set initialize = false to avoid initializing the class when looking it up. - Class.forName( - "io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory", - false, - Thread.currentThread().getContextClassLoader()); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - } -} diff --git a/native-image-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-core/native-image.properties b/native-image-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-core/native-image.properties index 2228a1f094..52e277f574 100644 --- a/native-image-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-core/native-image.properties +++ b/native-image-support/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-core/native-image.properties @@ -14,5 +14,4 @@ Args = --allow-incomplete-classpath \ io.grpc.netty.shaded.io.netty.channel.unix,\ io.grpc.netty.shaded.io.netty.handler.ssl,\ io.grpc.internal.RetriableStream,\ - com.google.api.client.googleapis.services.AbstractGoogleClientRequest$ApiClientVersion,\ com.google.cloud.firestore.FirestoreImpl