|
17 | 17 | package com.google.cloud.storage;
|
18 | 18 |
|
19 | 19 | import com.google.api.core.BetaApi;
|
| 20 | +import com.google.api.core.InternalApi; |
20 | 21 | import com.google.cloud.NoCredentials;
|
21 | 22 | import com.google.cloud.ServiceDefaults;
|
22 | 23 | import com.google.cloud.ServiceOptions;
|
|
26 | 27 | import com.google.cloud.storage.HttpStorageOptions.HttpStorageRpcFactory;
|
27 | 28 | import com.google.cloud.storage.TransportCompatibility.Transport;
|
28 | 29 | import com.google.cloud.storage.spi.StorageRpcFactory;
|
| 30 | +import java.io.IOException; |
| 31 | +import java.io.InputStream; |
| 32 | +import java.util.Properties; |
29 | 33 |
|
30 | 34 | public abstract class StorageOptions extends ServiceOptions<Storage, StorageOptions> {
|
31 | 35 |
|
32 | 36 | private static final long serialVersionUID = -7295846567928013233L;
|
| 37 | + private static final String VERSION; |
| 38 | + |
| 39 | + static { |
| 40 | + String tmp = "unresolved"; |
| 41 | + final Properties props = new Properties(); |
| 42 | + try { |
| 43 | + String resourcePath = |
| 44 | + String.format( |
| 45 | + "/META-INF/maven/%s/%s/pom.properties", "com.google.cloud", "google-cloud-storage"); |
| 46 | + InputStream resourceAsStream = StorageOptions.class.getResourceAsStream(resourcePath); |
| 47 | + if (resourceAsStream == null) { |
| 48 | + // some classloaders don't like a leading slash |
| 49 | + resourceAsStream = StorageOptions.class.getResourceAsStream(resourcePath.substring(1)); |
| 50 | + } |
| 51 | + if (resourceAsStream != null) { |
| 52 | + props.load(resourceAsStream); |
| 53 | + resourceAsStream.close(); |
| 54 | + |
| 55 | + tmp = props.getProperty("version", "unknown-version"); |
| 56 | + } |
| 57 | + } catch (IOException ignore) { |
| 58 | + // ignored |
| 59 | + } |
| 60 | + VERSION = tmp; |
| 61 | + } |
33 | 62 |
|
34 | 63 | /** @deprecated Use {@link HttpStorageFactory} */
|
35 | 64 | @Deprecated
|
@@ -86,6 +115,17 @@ protected boolean projectIdRequired() {
|
86 | 115 | return false;
|
87 | 116 | }
|
88 | 117 |
|
| 118 | + @Override |
| 119 | + public String getLibraryVersion() { |
| 120 | + return VERSION; |
| 121 | + } |
| 122 | + |
| 123 | + /* This can break at any time, the value produce is intended to be informative not authoritative */ |
| 124 | + @InternalApi |
| 125 | + public static String version() { |
| 126 | + return VERSION; |
| 127 | + } |
| 128 | + |
89 | 129 | @SuppressWarnings("unchecked")
|
90 | 130 | @Override
|
91 | 131 | public abstract StorageOptions.Builder toBuilder();
|
|
0 commit comments