@@ -20,18 +20,18 @@ import static com.github.jrubygradle.api.gems.GemVersion.Boundary.OPEN_ENDED
20
20
*
21
21
* When converting a GemSpec into a Ivy ivy.xml the translation of a
22
22
* gem version range into an Ivy version range. typically '~> 1.0' from ruby
23
- * becomes [1.0, 1.99999] or 1.0.+ on the Ivy side. so most dependencies from
23
+ * becomes { @code [1.0.0,2.0[ } on the Ivy side. so most dependencies from
24
24
* gem artifacts will use such version ranges.
25
25
*
26
26
* To help gradle to be closer to the rubygems world when resolving gem
27
27
* artifacts, it needs to calculate intersection between version ranges
28
28
* in maven manner.
29
29
*
30
- * this class basically represents an Ivy version range with boundary
31
- * (exclusive vs. inclusive) and its lower and upper bounded version and
30
+ * This class basically represents an Ivy version range with boundary
31
+ * (exclusive vs. inclusive or open-ended ) and its lower and upper bounded version and
32
32
* allows to intersect its range with another version range.
33
33
*
34
- * it also translate fixed version '1.0' to [1.0, 1.0] or the gradle notation
34
+ * It also translate fixed version '1.0' to [1.0, 1.0] or the gradle notation
35
35
* 1.2+ to [1.2, 1.99999] or 1.+ to [1.0, 1.99999] following the gemspec-to-pom
36
36
* pattern.
37
37
*
@@ -125,54 +125,44 @@ class GemVersion implements Comparable<GemVersion> {
125
125
static GemVersion gemVersionFromGemRequirement (String singleRequirement ) {
126
126
if (singleRequirement. matches(GREATER_EQUAL )) {
127
127
new GemVersion (
128
- true ,
128
+ INCLUSIVE ,
129
129
getVersionFromRequirement(singleRequirement, GREATER_EQUAL ),
130
- " ${ MAX_VERSION.toString() } .0.0 " ,
131
- true
130
+ null ,
131
+ OPEN_ENDED
132
132
)
133
133
} else if (singleRequirement. matches(GREATER )) {
134
134
new GemVersion (
135
- false ,
135
+ EXCLUSIVE ,
136
136
getVersionFromRequirement(singleRequirement, GREATER ),
137
- " ${ MAX_VERSION.toString() } .0.0 " ,
138
- true
137
+ null ,
138
+ OPEN_ENDED
139
139
)
140
140
} else if (singleRequirement. matches(EQUAL )) {
141
141
String exact = getVersionFromRequirement(singleRequirement, EQUAL )
142
142
new GemVersion (
143
- true ,
143
+ INCLUSIVE ,
144
144
exact,
145
145
exact,
146
- true
147
- )
148
- } else if (singleRequirement. matches(LESS )) {
149
- new GemVersion (
150
- true ,
151
- ' 0.0.0' ,
152
- getVersionFromRequirement(singleRequirement, LESS ),
153
- false
146
+ INCLUSIVE
154
147
)
155
148
} else if (singleRequirement. matches(LESS_EQUAL )) {
156
149
new GemVersion (
157
- true ,
158
- ' 0.0.0 ' ,
150
+ OPEN_ENDED ,
151
+ null ,
159
152
getVersionFromRequirement(singleRequirement, LESS_EQUAL ),
160
- true
153
+ INCLUSIVE
161
154
)
162
- } else if (singleRequirement. matches(TWIDDLE_WAKKA )) {
163
- String base = getVersionFromRequirement(singleRequirement, TWIDDLE_WAKKA )
164
- int adds = 3 - base. tokenize(' .' ). size()
165
- if (adds < 0 ) {
166
- adds = 0
167
- }
155
+ } else if (singleRequirement. matches(LESS )) {
168
156
new GemVersion (
169
- true ,
170
- " ${ base }${ '.0' * adds } " ,
171
- " ${ base }${ ('.' + MAX_VERSION) * adds } " ,
172
- true
157
+ OPEN_ENDED ,
158
+ null ,
159
+ getVersionFromRequirement(singleRequirement, LESS ) ,
160
+ EXCLUSIVE
173
161
)
162
+ } else if (singleRequirement. matches(TWIDDLE_WAKKA )) {
163
+ parseTwiddleWakka(singleRequirement)
174
164
} else {
175
- throw new GemVersionException (" Do not not how to process ${ singleRequirement} as a version string " )
165
+ throw new GemVersionException (" ' ${ singleRequirement} ' does not look like a GEM version requirement " )
176
166
}
177
167
}
178
168
@@ -356,19 +346,53 @@ class GemVersion implements Comparable<GemVersion> {
356
346
}
357
347
}
358
348
349
+ private static GemVersion parseTwiddleWakka (String singleRequirement ) {
350
+ String base = getVersionFromRequirement(singleRequirement, TWIDDLE_WAKKA )
351
+ List<String > parts = base. tokenize(' .' )
352
+ if (1 == parts) {
353
+ throw new GemVersionException (
354
+ " '${ singleRequirement} ' does not look like a correctly formattedGEM twiddle-wakka requirement"
355
+ )
356
+ }
357
+ String lastNumberPart = parts[0 .. -2 ]. reverse(). find {
358
+ it =~ ONLY_DIGITS
359
+ }
360
+ if (lastNumberPart == null ) {
361
+ throw new GemVersionException (" Cannot extract last number part from '${ singleRequirement} '. " +
362
+ ' This does not look like a standard GEM version requirement' )
363
+ }
364
+ int bottomAdds = 3 - parts. size()
365
+ if (bottomAdds < 0 ) {
366
+ bottomAdds = 0
367
+ }
368
+ try {
369
+ Integer nextUp = lastNumberPart. toInteger() + 1
370
+ String leader = parts. size() <= 2 ? ' ' : " ${ parts[0..-3].join('.')} ."
371
+ new GemVersion (
372
+ INCLUSIVE ,
373
+ " ${ base}${ '.0' * bottomAdds} " ,
374
+ " ${ leader}${ nextUp} .0" ,
375
+ EXCLUSIVE
376
+ )
377
+ } catch (NumberFormatException e) {
378
+ throw new GemVersionException (" Can extract last number part from '${ singleRequirement} '. " +
379
+ ' This does not look like a standard GEM version requirement' , e)
380
+ }
381
+ }
382
+
359
383
@CompileDynamic
360
384
@SuppressWarnings (' NoDef' )
361
385
private static String getVersionFromRequirement (String gemRevision , Pattern matchPattern ) {
362
386
def matcher = gemRevision =~ matchPattern
363
387
matcher[0 ][1 ]
364
388
}
365
389
366
- private GemVersion (Boolean lowInclusive , String low , String high , Boolean highInclusive ) {
367
- this . lowBoundary = lowInclusive ? INCLUSIVE : EXCLUSIVE
368
- this . low = low
369
- this . high = high
370
- this . highBoundary = highInclusive ? INCLUSIVE : EXCLUSIVE
371
- }
390
+ // private GemVersion(Boolean lowInclusive, String low, String high, Boolean highInclusive) {
391
+ // this.lowBoundary = lowInclusive ? INCLUSIVE : EXCLUSIVE
392
+ // this.low = low
393
+ // this.high = high
394
+ // this.highBoundary = highInclusive ? INCLUSIVE : EXCLUSIVE
395
+ // }
372
396
373
397
private GemVersion (Boundary pre , String low , String high , Boundary post ) {
374
398
this . lowBoundary = pre
0 commit comments