Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 2a50743

Browse files
authored
chore: remove use of Substitution for GaxProperties (#1675)
* chore: replace use of Substitution for GaxProperties
1 parent f99d15b commit 2a50743

File tree

4 files changed

+20
-71
lines changed

4 files changed

+20
-71
lines changed

‎gax/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ dependencies {
2121
testImplementation(libraries['maven.junit_junit'],
2222
libraries['maven.org_mockito_mockito_core'],
2323
libraries['maven.com_google_truth_truth'],
24-
libraries['maven.com_google_auto_value_auto_value'])
24+
libraries['maven.com_google_auto_value_auto_value'],
25+
libraries['maven.org_graalvm_sdk'])
2526

2627
annotationProcessor libraries['maven.com_google_auto_value_auto_value']
2728
testAnnotationProcessor libraries['maven.com_google_auto_value_auto_value']

‎gax/src/main/java/com/google/api/gax/core/GaxProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
*/
3030
package com.google.api.gax.core;
3131

32+
import static org.graalvm.nativeimage.ImageInfo.PROPERTY_IMAGE_CODE_KEY;
33+
import static org.graalvm.nativeimage.ImageInfo.PROPERTY_IMAGE_CODE_VALUE_RUNTIME;
34+
3235
import com.google.api.core.InternalApi;
3336
import java.io.IOException;
3437
import java.io.InputStream;
@@ -81,6 +84,12 @@ public static String getLibraryVersion(Class<?> libraryClass, String propertyNam
8184

8285
/** Returns the version of the running JVM */
8386
public static String getJavaVersion() {
87+
// When running the application as a native image, append `-graalvm` to the
88+
// version.
89+
String imageCode = System.getProperty(PROPERTY_IMAGE_CODE_KEY);
90+
if (imageCode != null && imageCode.equals(PROPERTY_IMAGE_CODE_VALUE_RUNTIME)) {
91+
return System.getProperty("java.version") + "-graalvm";
92+
}
8493
return JAVA_VERSION;
8594
}
8695

‎gax/src/main/java/com/google/api/gax/nativeimage/substitutions/GaxPropertiesSubstitutions.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

‎gax/src/test/java/com/google/api/gax/core/GaxPropertiesTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
package com.google.api.gax.core;
3131

32+
import static org.graalvm.nativeimage.ImageInfo.PROPERTY_IMAGE_CODE_KEY;
33+
import static org.graalvm.nativeimage.ImageInfo.PROPERTY_IMAGE_CODE_VALUE_RUNTIME;
3234
import static org.junit.Assert.assertTrue;
3335

3436
import java.util.regex.Pattern;
@@ -54,4 +56,11 @@ public void testGaxVersion() {
5456
assertTrue(minor >= 56);
5557
}
5658
}
59+
60+
@Test
61+
public void testGetVersion_nativeImage() {
62+
System.setProperty(PROPERTY_IMAGE_CODE_KEY, PROPERTY_IMAGE_CODE_VALUE_RUNTIME);
63+
String javaVersion = GaxProperties.getJavaVersion();
64+
assertTrue(javaVersion.endsWith("-graalvm"));
65+
}
5766
}

0 commit comments

Comments
 (0)