1
|
1 |
"{ Package: 'stx:goodies/metacello' }"
|
|
2 |
|
|
3 |
Magnitude subclass:#MetacelloVersionNumber
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Metacello-Core-Model'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!MetacelloVersionNumber class methodsFor:'instance creation'!
|
|
12 |
|
|
13 |
fromString: aString
|
|
14 |
|
|
15 |
| new components |
|
|
16 |
components := OrderedCollection new.
|
|
17 |
(aString findTokens: '.') do: [:subString | | strs |
|
|
18 |
strs := subString findTokens: '-'.
|
|
19 |
"first subString token could be an integer"
|
|
20 |
components add: (self extractNumericComponent: strs first).
|
|
21 |
strs size > 1
|
|
22 |
ifTrue: [
|
|
23 |
"remaining are uncoditionally Strings, because of leading $-"
|
|
24 |
components addAll: strs allButFirst ]].
|
|
25 |
new := self new: components size.
|
|
26 |
1 to: components size do: [:i | new at: i put: (components at: i) ].
|
|
27 |
^new
|
|
28 |
! !
|
|
29 |
|
|
30 |
!MetacelloVersionNumber class methodsFor:'private'!
|
|
31 |
|
|
32 |
extractNumericComponent: subString
|
|
33 |
"$. separated components are integers"
|
|
34 |
|
|
35 |
| number |
|
|
36 |
number := [subString asNumber]
|
|
37 |
on: Error
|
|
38 |
do: [:ex | ex return: subString ].
|
|
39 |
^number asString = subString
|
|
40 |
ifTrue: [ number ]
|
|
41 |
ifFalse: [ subString ]
|
|
42 |
! !
|
|
43 |
|
|
44 |
!MetacelloVersionNumber methodsFor:'accessing'!
|
|
45 |
|
|
46 |
approximateBase
|
|
47 |
|
|
48 |
| base |
|
|
49 |
base := self copyFrom: 1 to: self size - 1.
|
|
50 |
base at: base size put: (base at: base size) + 1.
|
|
51 |
^base
|
|
52 |
!
|
|
53 |
|
|
54 |
versionString
|
|
55 |
|
|
56 |
| strm |
|
|
57 |
strm := WriteStream on: String new.
|
|
58 |
self printOn: strm.
|
|
59 |
^strm contents
|
|
60 |
! !
|
|
61 |
|
|
62 |
!MetacelloVersionNumber methodsFor:'comparing'!
|
|
63 |
|
|
64 |
< aMetacelloVersionNumber
|
|
65 |
|
|
66 |
| condensed aCondensed |
|
|
67 |
aMetacelloVersionNumber species = self species
|
|
68 |
ifFalse: [ ^ false ].
|
|
69 |
condensed := self collapseZeros.
|
|
70 |
aCondensed := aMetacelloVersionNumber collapseZeros.
|
|
71 |
(condensed ~~ self or: [ aCondensed ~~ aMetacelloVersionNumber ])
|
|
72 |
ifTrue: [ ^ condensed compareLessThan: aCondensed ].
|
|
73 |
^ self compareLessThan: aMetacelloVersionNumber
|
|
74 |
!
|
|
75 |
|
|
76 |
= aMetacelloVersionNumber
|
|
77 |
|
|
78 |
| condensed aCondensed |
|
|
79 |
aMetacelloVersionNumber species = self species
|
|
80 |
ifFalse: [ ^ false ].
|
|
81 |
condensed := self collapseZeros.
|
|
82 |
aCondensed := aMetacelloVersionNumber collapseZeros.
|
|
83 |
(condensed ~~ self or: [ aCondensed ~~ aMetacelloVersionNumber ])
|
|
84 |
ifTrue: [ ^ condensed compareEqualTo: aCondensed ].
|
|
85 |
^ self compareEqualTo: aMetacelloVersionNumber
|
|
86 |
!
|
|
87 |
|
|
88 |
hash
|
|
89 |
|
|
90 |
"Returns a numeric hash key for the receiver."
|
|
91 |
|
|
92 |
| mySize interval hashValue |
|
|
93 |
|
|
94 |
(mySize := self size) == 0
|
|
95 |
ifTrue: [ ^15243 ].
|
|
96 |
|
|
97 |
"Choose an interval so that we sample at most 5 elements of the receiver"
|
|
98 |
interval := ((mySize - 1) // 4) max: 1.
|
|
99 |
|
|
100 |
hashValue := 4459.
|
|
101 |
1 to: mySize by: interval do: [ :i | | anElement |
|
|
102 |
anElement := self at: i.
|
|
103 |
(anElement isKindOf: SequenceableCollection)
|
|
104 |
ifTrue: [
|
|
105 |
hashValue := (hashValue bitShift: -1) bitXor: anElement size.
|
|
106 |
]
|
|
107 |
ifFalse: [
|
|
108 |
hashValue := (hashValue bitShift: -1) bitXor: anElement hash.
|
|
109 |
].
|
|
110 |
].
|
|
111 |
|
|
112 |
^ hashValue abs
|
|
113 |
!
|
|
114 |
|
|
115 |
match: aVersionPattern
|
|
116 |
"Answer whether the version number of the receiver matches the given pattern string.
|
|
117 |
|
|
118 |
A Metacello version number is made up of version sequences delimited by the characters $. and $-.
|
|
119 |
The $. introduces a numeric version sequence and $- introduces an alphanumeric version sequence.
|
|
120 |
|
|
121 |
A version pattern is made up of version pattern match sequences. also delimited by the characters $.
|
|
122 |
and $-.. Each pattern match sequence is tested against the corresponding version sequence of the
|
|
123 |
receiver, using the 'standard' pattern matching rules. All sequences must answer true for a match.
|
|
124 |
|
|
125 |
The special pattern sequence '?' is a match for the corresponding version sequence and all subsequent
|
|
126 |
version sequences. '?' as the version pattern matches all versions. No more version pattern
|
|
127 |
sequences are permitted once the '?' sequence is used. If used, it is the last version pattern
|
|
128 |
sequence. "
|
|
129 |
|
|
130 |
| patternVersion mySize patternSize |
|
|
131 |
patternVersion := aVersionPattern asMetacelloVersionNumber.
|
|
132 |
mySize := self size.
|
|
133 |
patternSize := patternVersion size.
|
|
134 |
mySize = patternSize
|
|
135 |
ifFalse: [
|
|
136 |
mySize < patternSize ifTrue: [ ^false ].
|
|
137 |
(patternVersion at: patternSize) ~= '?' ifTrue: [ ^false ].
|
|
138 |
mySize := patternSize ].
|
|
139 |
1 to: mySize do: [:i | | pattern |
|
|
140 |
pattern := (patternVersion at: i) asString.
|
|
141 |
pattern = '?'
|
|
142 |
ifTrue: [i = mySize ifFalse: [ ^self error: 'Invalid version match pattern: ', aVersionPattern printString ]]
|
|
143 |
ifFalse: [ (pattern match: (self at: i) asString) ifFalse: [ ^false ]]].
|
|
144 |
^true
|
|
145 |
"
|
|
146 |
'1.1.1' asMetacelloVersionNumber match: '*.*.*'. -> true
|
|
147 |
'1.1.1' asMetacelloVersionNumber match: '*.#.*'. -> true
|
|
148 |
'1.10.1' asMetacelloVersionNumber match: '*.#.*'. -> false
|
|
149 |
'1.1.1' asMetacelloVersionNumber match: '*.*'. -> false
|
|
150 |
'1.1.1' asMetacelloVersionNumber match: '*.?'. -> true
|
|
151 |
'1.0' asMetacelloVersionNumber match: '1.?'. -> true
|
|
152 |
'2.0' asMetacelloVersionNumber match: '1.?'. -> false
|
|
153 |
'1.1.1' asMetacelloVersionNumber match: '?'. -> true
|
|
154 |
'1' asMetacelloVersionNumber match: '*.?'. -> false
|
|
155 |
'1-alpha5.0' asMetacelloVersionNumber match: '1-alpha*.?'. -> true
|
|
156 |
'1-alpha15.0.1' asMetacelloVersionNumber match: '1-alpha*.?'. -> true
|
|
157 |
'1.1' asMetacelloVersionNumber match: '?.?'. -> ERROR: invalid version match pattern
|
|
158 |
"
|
|
159 |
!
|
|
160 |
|
|
161 |
~> aMetacelloVersionNumber
|
|
162 |
|
|
163 |
aMetacelloVersionNumber size == 1 ifTrue: [ ^false ].
|
|
164 |
^self >= aMetacelloVersionNumber and: [ self < aMetacelloVersionNumber approximateBase ]
|
|
165 |
! !
|
|
166 |
|
|
167 |
!MetacelloVersionNumber methodsFor:'converting'!
|
|
168 |
|
|
169 |
asMetacelloVersionNumber
|
|
170 |
|
|
171 |
^self
|
|
172 |
! !
|
|
173 |
|
|
174 |
!MetacelloVersionNumber methodsFor:'copying'!
|
|
175 |
|
|
176 |
copyFrom: start to: stop
|
|
177 |
"Answer a copy of a subset of the receiver, starting from element at
|
|
178 |
index start until element at index stop."
|
|
179 |
|
|
180 |
| newSize new j |
|
|
181 |
newSize := stop - start + 1.
|
|
182 |
new := self species new: newSize.
|
|
183 |
j := 0.
|
|
184 |
start to: stop do: [:i |
|
|
185 |
new at: j + 1 put: (self at: i).
|
|
186 |
j := j + 1 ].
|
|
187 |
^new
|
|
188 |
! !
|
|
189 |
|
|
190 |
!MetacelloVersionNumber methodsFor:'enumerating'!
|
|
191 |
|
|
192 |
do: aBlock
|
|
193 |
"Refer to the comment in Collection|do:."
|
|
194 |
1 to: self size do:
|
|
195 |
[:index | aBlock value: (self at: index)]
|
|
196 |
!
|
|
197 |
|
|
198 |
do: elementBlock separatedBy: separatorBlock
|
|
199 |
"Evaluate the elementBlock for all elements in the receiver,
|
|
200 |
and evaluate the separatorBlock between."
|
|
201 |
|
|
202 |
| beforeFirst |
|
|
203 |
beforeFirst := true.
|
|
204 |
self do:
|
|
205 |
[:each |
|
|
206 |
beforeFirst
|
|
207 |
ifTrue: [beforeFirst := false]
|
|
208 |
ifFalse: [separatorBlock value].
|
|
209 |
elementBlock value: each]
|
|
210 |
! !
|
|
211 |
|
|
212 |
!MetacelloVersionNumber methodsFor:'operations'!
|
|
213 |
|
|
214 |
decrementMinorVersionNumber
|
|
215 |
| int |
|
|
216 |
self size to: 1 by: -1 do: [ :index |
|
|
217 |
(int := self at: index) isString
|
|
218 |
ifFalse: [
|
|
219 |
int > 0
|
|
220 |
ifTrue: [ self at: index put: int - 1 ].
|
|
221 |
^ self ] ]
|
|
222 |
!
|
|
223 |
|
|
224 |
incrementMinorVersionNumber
|
|
225 |
|
|
226 |
| int |
|
|
227 |
self size to: 1 by: -1 do: [:index |
|
|
228 |
(int := self at: index) isString
|
|
229 |
ifFalse: [
|
|
230 |
self at: index put: int + 1.
|
|
231 |
^self ]].
|
|
232 |
! !
|
|
233 |
|
|
234 |
!MetacelloVersionNumber methodsFor:'printing'!
|
|
235 |
|
|
236 |
asString
|
|
237 |
"Answer a string that represents the receiver."
|
|
238 |
|
|
239 |
^ self printString
|
|
240 |
!
|
|
241 |
|
|
242 |
printOn: aStream
|
|
243 |
|
|
244 |
| beforeFirst |
|
|
245 |
beforeFirst := true.
|
|
246 |
self do:
|
|
247 |
[:each |
|
|
248 |
beforeFirst
|
|
249 |
ifTrue: [beforeFirst := false]
|
|
250 |
ifFalse: [
|
|
251 |
each isString
|
|
252 |
ifTrue: [ aStream nextPut: $- ]
|
|
253 |
ifFalse: [ aStream nextPut: $. ] ].
|
|
254 |
aStream nextPutAll: each asString ]
|
|
255 |
! !
|
|
256 |
|
|
257 |
!MetacelloVersionNumber methodsFor:'private'!
|
|
258 |
|
|
259 |
collapseZeros
|
|
260 |
"the rule must be that zeros can be collapsed as long as the series of zeros ends in a string term"
|
|
261 |
|
|
262 |
| collection newSize new j lastElementIsStringOrZero canCollapse |
|
|
263 |
(self size = 0 or: [ self at: 1 ]) == 0
|
|
264 |
ifTrue: [ ^ self ].
|
|
265 |
collection := OrderedCollection new.
|
|
266 |
lastElementIsStringOrZero := true.
|
|
267 |
canCollapse := true.
|
|
268 |
self size to: 1 by: -1 do: [ :i |
|
|
269 |
| element |
|
|
270 |
element := self at: i.
|
|
271 |
(canCollapse and: [ element == 0 ])
|
|
272 |
ifTrue: [
|
|
273 |
lastElementIsStringOrZero
|
|
274 |
ifFalse: [
|
|
275 |
canCollapse := false.
|
|
276 |
collection addFirst: element.]]
|
|
277 |
ifFalse: [
|
|
278 |
collection addFirst: element.
|
|
279 |
canCollapse := lastElementIsStringOrZero := element isString ] ].
|
|
280 |
collection size = self size
|
|
281 |
ifTrue: [ ^ self ].
|
|
282 |
newSize := collection size.
|
|
283 |
new := self species new: newSize.
|
|
284 |
j := 0.
|
|
285 |
collection
|
|
286 |
do: [ :element |
|
|
287 |
new at: j + 1 put: element.
|
|
288 |
j := j + 1 ].
|
|
289 |
^ new
|
|
290 |
!
|
|
291 |
|
|
292 |
compareEqualTo: aMetacelloVersionNumber
|
|
293 |
|
|
294 |
| mySize |
|
|
295 |
aMetacelloVersionNumber species = self species ifFalse: [ ^false ].
|
|
296 |
mySize := self size.
|
|
297 |
mySize = aMetacelloVersionNumber size
|
|
298 |
ifFalse: [ ^false ].
|
|
299 |
1 to: mySize do: [:i |
|
|
300 |
(self at: i) = (aMetacelloVersionNumber at: i) ifFalse: [ ^false ]].
|
|
301 |
^true
|
|
302 |
!
|
|
303 |
|
|
304 |
compareLessThan: aMetacelloVersionNumber
|
|
305 |
|
|
306 |
| mySize aSize commonSize count more |
|
|
307 |
mySize := self size.
|
|
308 |
aSize := aMetacelloVersionNumber size.
|
|
309 |
commonSize := mySize min: aSize.
|
|
310 |
count := 0.
|
|
311 |
more := true.
|
|
312 |
[ more and: [ count < commonSize ]] whileTrue: [
|
|
313 |
(self at: count + 1) = (aMetacelloVersionNumber at: count + 1)
|
|
314 |
ifTrue: [ count := count + 1 ]
|
|
315 |
ifFalse: [ more := false ]].
|
|
316 |
count < commonSize
|
|
317 |
ifTrue: [
|
|
318 |
^(self at: count + 1)
|
|
319 |
metacelloVersionComponentLessThan: (aMetacelloVersionNumber at: count + 1) ].
|
|
320 |
mySize < aSize
|
|
321 |
ifTrue: [
|
|
322 |
mySize = 0 ifTrue: [ ^true ].
|
|
323 |
"if the versions at commonSize are equal and the next version slot in aMetacelloVersionNumber
|
|
324 |
is a string, then it's considered that I'm > aMetacelloVersionNumber
|
|
325 |
(i.e., '2.9.9' is greater than '2.9.9-alpha.2')"
|
|
326 |
(self at: commonSize) = (aMetacelloVersionNumber at: commonSize)
|
|
327 |
ifFalse: [ ^true ].
|
|
328 |
^(aMetacelloVersionNumber at: commonSize+1) isString not]
|
|
329 |
ifFalse: [
|
|
330 |
mySize = aSize ifTrue: [ ^false ].
|
|
331 |
aSize <= 0 ifTrue: [ ^false ].
|
|
332 |
"if the versions at commonSize are equal and the next version slot is a string,
|
|
333 |
then it's considered that I'm < aMetacelloVersionNumber
|
|
334 |
(i.e., '2.9.9-alpha.2' is less than '2.9.9')"
|
|
335 |
(self at: commonSize) = (aMetacelloVersionNumber at: commonSize)
|
|
336 |
ifFalse: [ ^false ].
|
|
337 |
^(self at: commonSize+1) isString]
|
|
338 |
! !
|
|
339 |
|
|
340 |
!MetacelloVersionNumber class methodsFor:'documentation'!
|
|
341 |
|
|
342 |
version_SVN
|
|
343 |
^ '$Id:: $'
|
|
344 |
! !
|