From 744839f51a01301390297b4a5cb037547eefc4c0 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 17 Dec 2019 17:28:00 -0600 Subject: [PATCH] fix: update GoogleUtils#getVersion() to use stable logic (#1452) * fix: update GoogleUtils#getVersion() to use stable logic * fix: fix property name * fix: handle case where property is not found --- .../api/client/googleapis/GoogleUtils.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java b/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java index 9bb2fc74c..b4eca557f 100644 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java +++ b/google-api-client/src/main/java/com/google/api/client/googleapis/GoogleUtils.java @@ -89,22 +89,20 @@ public static synchronized KeyStore getCertificateTrustStore() } private static String getVersion() { - String version = GoogleUtils.class.getPackage().getImplementationVersion(); - // in a non-packaged environment (local), there's no implementation version to read - if (version == null) { - // fall back to reading from a properties file - note this value is expected to be cached - try (InputStream inputStream = - GoogleUtils.class.getResourceAsStream("google-api-client.properties")) { - if (inputStream != null) { - Properties properties = new Properties(); - properties.load(inputStream); - version = properties.getProperty("google-api-client.version"); - } - } catch (IOException e) { - // ignore + // attempt to read the library's version from a properties file generated during the build + // this value should be read and cached for later use + String version = null; + try (InputStream inputStream = + GoogleUtils.class.getResourceAsStream("google-api-client.properties")) { + if (inputStream != null) { + Properties properties = new Properties(); + properties.load(inputStream); + version = properties.getProperty("google-api-client.version"); } + } catch (IOException e) { + // ignore } - return version; + return version == null ? "unknown-version" : version; } private GoogleUtils() {}