@@ -3,7 +3,6 @@ package buildplanner
33import (
44 "encoding/json"
55 "errors"
6- "regexp"
76 "strconv"
87 "strings"
98 "time"
@@ -172,25 +171,16 @@ func processBuildPlannerError(bpErr error, fallbackMessage string) error {
172171 return & response.BuildPlannerError {Err : locale .NewExternalError ("err_buildplanner" , "{{.V0}}: Encountered unexpected error: {{.V1}}" , fallbackMessage , bpErr .Error ())}
173172}
174173
175- var versionRe = regexp .MustCompile (`^\d+(\.\d+)*$` )
176-
177- func isExactVersion (version string ) bool {
178- return versionRe .MatchString (version )
174+ func isRangeVersion (version string ) bool {
175+ return strings .Contains (version , "=" ) || strings .Contains (version , "<" ) || strings .Contains (version , ">" )
179176}
180177
181178func isWildcardVersion (version string ) bool {
182179 return strings .Contains (version , ".x" ) || strings .Contains (version , ".X" )
183180}
184181
185182func VersionStringToRequirements (version string ) ([]types.VersionRequirement , error ) {
186- if isExactVersion (version ) {
187- return []types.VersionRequirement {{
188- types .VersionRequirementComparatorKey : "eq" ,
189- types .VersionRequirementVersionKey : version ,
190- }}, nil
191- }
192-
193- if ! isWildcardVersion (version ) {
183+ if isRangeVersion (version ) {
194184 // Ask the Platform to translate a string like ">=1.2,<1.3" into a list of requirements.
195185 // Note that:
196186 // - The given requirement name does not matter; it is not looked up.
@@ -210,33 +200,41 @@ func VersionStringToRequirements(version string) ([]types.VersionRequirement, er
210200 return requirements , nil
211201 }
212202
213- // Construct version constraints to be >= given version, and < given version's last part + 1.
214- // For example, given a version number of 3.10.x, constraints should be >= 3.10, < 3.11.
215- // Given 2.x, constraints should be >= 2, < 3.
216- requirements := []types.VersionRequirement {}
217- parts := strings .Split (version , "." )
218- for i , part := range parts {
219- if part != "x" && part != "X" {
220- continue
221- }
222- if i == 0 {
223- return nil , locale .NewInputError ("err_version_wildcard_start" , "A version number cannot start with a wildcard" )
224- }
225- requirements = append (requirements , types.VersionRequirement {
226- types .VersionRequirementComparatorKey : types .ComparatorGTE ,
227- types .VersionRequirementVersionKey : strings .Join (parts [:i ], "." ),
228- })
229- previousPart , err := strconv .Atoi (parts [i - 1 ])
230- if err != nil {
231- return nil , locale .WrapInputError (err , "err_version_number_expected" , "Version parts are expected to be numeric" )
203+ if isWildcardVersion (version ) {
204+ // Construct version constraints to be >= given version, and < given version's last part + 1.
205+ // For example, given a version number of 3.10.x, constraints should be >= 3.10, < 3.11.
206+ // Given 2.x, constraints should be >= 2, < 3.
207+ requirements := []types.VersionRequirement {}
208+ parts := strings .Split (version , "." )
209+ for i , part := range parts {
210+ if part != "x" && part != "X" {
211+ continue
212+ }
213+ if i == 0 {
214+ return nil , locale .NewInputError ("err_version_wildcard_start" , "A version number cannot start with a wildcard" )
215+ }
216+ requirements = append (requirements , types.VersionRequirement {
217+ types .VersionRequirementComparatorKey : types .ComparatorGTE ,
218+ types .VersionRequirementVersionKey : strings .Join (parts [:i ], "." ),
219+ })
220+ previousPart , err := strconv .Atoi (parts [i - 1 ])
221+ if err != nil {
222+ return nil , locale .WrapInputError (err , "err_version_number_expected" , "Version parts are expected to be numeric" )
223+ }
224+ parts [i - 1 ] = strconv .Itoa (previousPart + 1 )
225+ requirements = append (requirements , types.VersionRequirement {
226+ types .VersionRequirementComparatorKey : types .ComparatorLT ,
227+ types .VersionRequirementVersionKey : strings .Join (parts [:i ], "." ),
228+ })
232229 }
233- parts [i - 1 ] = strconv .Itoa (previousPart + 1 )
234- requirements = append (requirements , types.VersionRequirement {
235- types .VersionRequirementComparatorKey : types .ComparatorLT ,
236- types .VersionRequirementVersionKey : strings .Join (parts [:i ], "." ),
237- })
230+ return requirements , nil
238231 }
239- return requirements , nil
232+
233+ return []types.VersionRequirement {{
234+ types .VersionRequirementComparatorKey : "eq" ,
235+ types .VersionRequirementVersionKey : version ,
236+ }}, nil
237+
240238}
241239
242240// pollBuildPlanned polls the buildplan until it has passed the planning stage (ie. it's either planned or further along).
0 commit comments