@@ -14,8 +14,7 @@ namespace Elastic.Stack.ArtifactsApi
14
14
{
15
15
public class ElasticVersion : Version , IComparable < string >
16
16
{
17
- private readonly ConcurrentDictionary < string , Artifact >
18
- _resolved = new ConcurrentDictionary < string , Artifact > ( ) ;
17
+ private readonly ConcurrentDictionary < string , Artifact > _resolved = new ( ) ;
19
18
20
19
protected ElasticVersion ( string version , ArtifactBuildState state , string buildHash = null ) : base ( version )
21
20
{
@@ -28,7 +27,7 @@ protected ElasticVersion(string version, ArtifactBuildState state, string buildH
28
27
29
28
public int CompareTo ( string other )
30
29
{
31
- var v = ( ElasticVersion ) other ;
30
+ var v = ( ElasticVersion ) other ;
32
31
return CompareTo ( v ) ;
33
32
}
34
33
@@ -73,25 +72,29 @@ ArtifactBuildState GetReleaseState(string s)
73
72
: ArtifactBuildState . BuildCandidate ;
74
73
}
75
74
76
- if ( string . IsNullOrWhiteSpace ( managedVersionString ) ) return null ;
75
+ if ( string . IsNullOrWhiteSpace ( managedVersionString ) )
76
+ return null ;
77
77
78
78
var version = managedVersionString ;
79
79
var state = GetReleaseState ( version ) ;
80
80
var buildHash = string . Empty ;
81
81
82
82
switch ( managedVersionString )
83
83
{
84
- case string _ when managedVersionString . StartsWith ( "latest-" , StringComparison . OrdinalIgnoreCase ) :
84
+ case { } when managedVersionString . StartsWith ( "latest-" , StringComparison . OrdinalIgnoreCase ) :
85
85
var major = int . Parse ( managedVersionString . Replace ( "latest-" , "" ) ) ;
86
86
version = SnapshotApiResolver . LatestReleaseOrSnapshotForMajor ( major ) . ToString ( ) ;
87
87
state = GetReleaseState ( version ) ;
88
88
if ( state == ArtifactBuildState . BuildCandidate )
89
89
buildHash = ApiResolver . LatestBuildHash ( version ) ;
90
90
break ;
91
- case string _ when managedVersionString . EndsWith ( "-snapshot" , StringComparison . OrdinalIgnoreCase ) :
91
+ // When the version is not yet released but contains the alpha label, we treat it in the same way as snapshots so it is resolved correctly
92
+ case { } _ when managedVersionString . EndsWith ( "-snapshot" , StringComparison . OrdinalIgnoreCase )
93
+ || state != ArtifactBuildState . Released &&
94
+ managedVersionString . IndexOf ( "-alpha" , StringComparison . OrdinalIgnoreCase ) >= 0 :
92
95
state = ArtifactBuildState . Snapshot ;
93
96
break ;
94
- case string _ when TryParseBuildCandidate ( managedVersionString , out var v , out buildHash ) :
97
+ case { } _ when TryParseBuildCandidate ( managedVersionString , out var v , out buildHash ) :
95
98
state = ArtifactBuildState . BuildCandidate ;
96
99
version = v ;
97
100
break ;
@@ -109,7 +112,8 @@ internal static bool TryParseBuildCandidate(string passedVersion, out string ver
109
112
version = null ;
110
113
gitHash = null ;
111
114
var tokens = passedVersion . Split ( ':' ) ;
112
- if ( tokens . Length < 2 ) return false ;
115
+ if ( tokens . Length < 2 )
116
+ return false ;
113
117
version = tokens [ 1 ] . Trim ( ) ;
114
118
gitHash = tokens [ 0 ] . Trim ( ) ;
115
119
return true ;
@@ -124,7 +128,8 @@ public bool InRange(string range)
124
128
public bool InRange ( Range versionRange )
125
129
{
126
130
var satisfied = versionRange . IsSatisfied ( this ) ;
127
- if ( satisfied ) return true ;
131
+ if ( satisfied )
132
+ return true ;
128
133
129
134
//Semver can only match snapshot version with ranges on the same major and minor
130
135
//anything else fails but we want to know e.g 2.4.5-SNAPSHOT satisfied by <5.0.0;
@@ -135,24 +140,24 @@ public bool InRange(Range versionRange)
135
140
136
141
public static implicit operator ElasticVersion ( string version ) => From ( version ) ;
137
142
138
- public static bool operator < ( ElasticVersion first , string second ) => first < ( ElasticVersion ) second ;
139
- public static bool operator > ( ElasticVersion first , string second ) => first > ( ElasticVersion ) second ;
143
+ public static bool operator < ( ElasticVersion first , string second ) => first < ( ElasticVersion ) second ;
144
+ public static bool operator > ( ElasticVersion first , string second ) => first > ( ElasticVersion ) second ;
140
145
141
- public static bool operator < ( string first , ElasticVersion second ) => ( ElasticVersion ) first < second ;
142
- public static bool operator > ( string first , ElasticVersion second ) => ( ElasticVersion ) first > second ;
146
+ public static bool operator < ( string first , ElasticVersion second ) => ( ElasticVersion ) first < second ;
147
+ public static bool operator > ( string first , ElasticVersion second ) => ( ElasticVersion ) first > second ;
143
148
144
- public static bool operator <= ( ElasticVersion first , string second ) => first <= ( ElasticVersion ) second ;
145
- public static bool operator >= ( ElasticVersion first , string second ) => first >= ( ElasticVersion ) second ;
149
+ public static bool operator <= ( ElasticVersion first , string second ) => first <= ( ElasticVersion ) second ;
150
+ public static bool operator >= ( ElasticVersion first , string second ) => first >= ( ElasticVersion ) second ;
146
151
147
- public static bool operator <= ( string first , ElasticVersion second ) => ( ElasticVersion ) first <= second ;
148
- public static bool operator >= ( string first , ElasticVersion second ) => ( ElasticVersion ) first >= second ;
152
+ public static bool operator <= ( string first , ElasticVersion second ) => ( ElasticVersion ) first <= second ;
153
+ public static bool operator >= ( string first , ElasticVersion second ) => ( ElasticVersion ) first >= second ;
149
154
150
- public static bool operator == ( ElasticVersion first , string second ) => first == ( ElasticVersion ) second ;
151
- public static bool operator != ( ElasticVersion first , string second ) => first != ( ElasticVersion ) second ;
155
+ public static bool operator == ( ElasticVersion first , string second ) => first == ( ElasticVersion ) second ;
156
+ public static bool operator != ( ElasticVersion first , string second ) => first != ( ElasticVersion ) second ;
152
157
153
158
154
- public static bool operator == ( string first , ElasticVersion second ) => ( ElasticVersion ) first == second ;
155
- public static bool operator != ( string first , ElasticVersion second ) => ( ElasticVersion ) first != second ;
159
+ public static bool operator == ( string first , ElasticVersion second ) => ( ElasticVersion ) first == second ;
160
+ public static bool operator != ( string first , ElasticVersion second ) => ( ElasticVersion ) first != second ;
156
161
157
162
// ReSharper disable once UnusedMember.Local
158
163
private bool Equals ( ElasticVersion other ) => base . Equals ( other ) ;
0 commit comments