Skip to content

Commit 702e8a7

Browse files
dpcollins-googledpcollins-google
andauthored
Generate major and minor version numbers using gax. (#42)
Co-authored-by: dpcollins-google <[email protected]>
1 parent 2e211ce commit 702e8a7

File tree

1 file changed

+35
-3
lines changed
  • google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire

1 file changed

+35
-3
lines changed

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/Versions.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,42 @@
1616

1717
package com.google.cloud.pubsublite.internal.wire;
1818

19-
/** The version number of this library. Should be updated whenever the version is updated. */
19+
import com.google.api.gax.core.GaxProperties;
20+
21+
/** The version number of this library.*/
2022
final class Versions {
2123
private Versions() {}
2224

23-
static final int MAJOR_VERSION = 0;
24-
static final int MINOR_VERSION = 0;
25+
private static String[] GetVersionSplits() {
26+
try {
27+
String versionString = GaxProperties.getLibraryVersion(Versions.class);
28+
return versionString.split(".");
29+
} catch (Exception e) {
30+
return new String[0];
31+
}
32+
}
33+
34+
private static int GetMajorVersion() {
35+
String[] splits = GetVersionSplits();
36+
if (splits.length != 3) return 0;
37+
try {
38+
return Integer.parseInt(splits[0]);
39+
} catch (NumberFormatException e) {
40+
return 0;
41+
}
42+
}
43+
44+
private static int GetMinorVersion() {
45+
String[] splits = GetVersionSplits();
46+
if (splits.length != 3) return 0;
47+
try {
48+
return Integer.parseInt(splits[1]);
49+
} catch (NumberFormatException e) {
50+
return 0;
51+
}
52+
}
53+
54+
// TODO: Do this using generation automation as opposed to maven packaging.
55+
static final int MAJOR_VERSION = GetMajorVersion();
56+
static final int MINOR_VERSION = GetMinorVersion();
2557
}

0 commit comments

Comments
 (0)