19
19
20
20
package co .elastic .clients .transport ;
21
21
22
- import co .elastic .clients .ApiClient ;
23
-
24
22
import javax .annotation .Nullable ;
25
- import java .io .InputStream ;
26
23
import java .util .Objects ;
27
- import java .util .Properties ;
28
24
29
25
/**
30
26
* This class represents a SemVer version, with an optional patch revision.
@@ -49,20 +45,20 @@ public static Version parse(String version) {
49
45
int hyphen = version .indexOf ('-' );
50
46
if (hyphen >= 0 ) {
51
47
// Has prerelease. May be followed buy build information
52
- prerelease = version .substring (hyphen + 1 );
48
+ prerelease = version .substring (hyphen + 1 );
53
49
version = version .substring (0 , hyphen );
54
50
55
51
int plus = prerelease .indexOf ('+' );
56
52
if (plus >= 0 ) {
57
- build = prerelease .substring (0 , plus + 1 );
53
+ build = prerelease .substring (0 , plus + 1 );
58
54
prerelease = prerelease .substring (0 , plus );
59
55
}
60
56
}
61
57
62
58
int plus = version .indexOf ('+' );
63
59
if (plus >= 0 ) {
64
60
// Has build information
65
- build = version .substring (0 , plus + 1 );
61
+ build = version .substring (0 , plus + 1 );
66
62
version = version .substring (0 , plus );
67
63
}
68
64
@@ -72,7 +68,8 @@ public static Version parse(String version) {
72
68
int minor = (bits .length >= 2 ) ? Integer .parseInt (bits [1 ]) : 0 ;
73
69
int maintenance = (bits .length >= 3 ) ? Integer .parseInt (bits [2 ]) : -1 ;
74
70
return new Version (major , minor , maintenance , prerelease , build );
75
- } catch (NumberFormatException ex ) {
71
+ }
72
+ catch (NumberFormatException ex ) {
76
73
return null ;
77
74
}
78
75
}
@@ -81,8 +78,7 @@ public Version(int major, int minor, int maintenance, boolean isPreRelease) {
81
78
this (major , minor , maintenance , isPreRelease ? "p" : null , null );
82
79
}
83
80
84
- public Version (int major , int minor , int maintenance , @ Nullable String prerelease ,
85
- @ Nullable String build ) {
81
+ public Version (int major , int minor , int maintenance , @ Nullable String prerelease , @ Nullable String build ) {
86
82
this .major = major ;
87
83
this .minor = minor ;
88
84
this .maintenance = maintenance ;
@@ -112,10 +108,10 @@ public boolean equals(Object other) {
112
108
if (!(other instanceof Version )) return false ;
113
109
Version that = (Version ) other ;
114
110
return (major == that .major &&
115
- minor == that .minor &&
116
- maintenance == that .maintenance &&
117
- Objects .equals (prerelease , that .prerelease ) &&
118
- Objects .equals (build , that .build ));
111
+ minor == that .minor &&
112
+ maintenance == that .maintenance &&
113
+ Objects .equals (prerelease , that .prerelease ) &&
114
+ Objects .equals (build , that .build ));
119
115
}
120
116
121
117
@ Override
@@ -150,19 +146,10 @@ public String toString() {
150
146
151
147
static {
152
148
Version version = null ;
153
- InputStream in = ApiClient .class .getResourceAsStream ("version.properties" );
154
- if (in != null ) {
155
- Properties properties = new Properties ();
156
- try {
157
- properties .load (in );
158
- String versionStr = properties .getProperty ("version" );
159
- if (versionStr != null ) {
160
- version = Version .parse (versionStr );
161
- }
162
- } catch (Exception e ) {
163
- // Failed to parse version from file, trying from VersionInfo
164
- version = Version .parse (VersionInfo .VERSION );
165
- }
149
+ try {
150
+ version = Version .parse (VersionInfo .VERSION );
151
+ } catch (Exception e ) {
152
+ // Failed to parse version
166
153
}
167
154
VERSION = version ;
168
155
}
0 commit comments