|
16 | 16 |
|
17 | 17 | import com.google.api.client.util.SecurityUtils;
|
18 | 18 | import com.google.common.annotations.VisibleForTesting;
|
19 |
| - |
20 | 19 | import java.io.IOException;
|
21 | 20 | import java.io.InputStream;
|
22 | 21 | import java.security.GeneralSecurityException;
|
23 | 22 | import java.security.KeyStore;
|
| 23 | +import java.util.Properties; |
24 | 24 | import java.util.regex.Matcher;
|
25 | 25 | import java.util.regex.Pattern;
|
26 | 26 |
|
|
32 | 32 | */
|
33 | 33 | public final class GoogleUtils {
|
34 | 34 |
|
35 |
| -// NOTE: toString() so compiler thinks it isn't a constant, so it won't inline it |
36 |
| -// {x-version-update-start:google-api-client:current} |
37 | 35 | /** Current release version. */
|
38 |
| -public static final String VERSION = "1.30.3".toString(); |
39 |
| -// {x-version-update-end:google-api-client:current} |
| 36 | +public static final String VERSION = getVersion(); |
40 | 37 |
|
41 | 38 | // NOTE: Integer instead of int so compiler thinks it isn't a constant, so it won't inline it
|
42 | 39 | /**
|
@@ -91,5 +88,24 @@ public static synchronized KeyStore getCertificateTrustStore()
|
91 | 88 | return certTrustStore;
|
92 | 89 | }
|
93 | 90 |
|
| 91 | +private static String getVersion() { |
| 92 | +String version = GoogleUtils.class.getPackage().getImplementationVersion(); |
| 93 | +// in a non-packaged environment (local), there's no implementation version to read |
| 94 | +if (version == null) { |
| 95 | +// fall back to reading from a properties file - note this value is expected to be cached |
| 96 | +try (InputStream inputStream = |
| 97 | +GoogleUtils.class.getResourceAsStream("google-api-client.properties")) { |
| 98 | +if (inputStream != null) { |
| 99 | +Properties properties = new Properties(); |
| 100 | +properties.load(inputStream); |
| 101 | +version = properties.getProperty("google-api-client.version"); |
| 102 | +} |
| 103 | +} catch (IOException e) { |
| 104 | +// ignore |
| 105 | +} |
| 106 | +} |
| 107 | +return version; |
| 108 | +} |
| 109 | + |
94 | 110 | private GoogleUtils() {}
|
95 | 111 | }
|
0 commit comments