1445
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
1282
|
13 |
"{ Package: 'stx:libbasic3' }"
|
|
14 |
|
|
15 |
"{ NameSpace: Packages }"
|
|
16 |
|
|
17 |
Magnitude subclass:#VersionNumber
|
|
18 |
instanceVariableNames:'numbers'
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Package-helpers'
|
|
22 |
!
|
|
23 |
|
|
24 |
VersionNumber comment:'I am a version number. My representation allows me to handle an entire tree of versions. Once created, an instance should not change (note: VersionNumbers could be canonicalized like Symbols, but are not currently).
|
|
25 |
|
|
26 |
I am a magnitude so that you can see if one version preceeds another (only if the two versions are in the same branch).
|
|
27 |
|
|
28 |
''2.1'' asVersion < ''2.2.1'' asVersion "true"
|
|
29 |
''2.3'' asVersion < ''2.2.1'' asVersion "error different branches"
|
|
30 |
''2.3'' asVersion inSameBranchAs: ''2.2.1'' asVersion "false, why the previous one failed."
|
|
31 |
''2.1'' asVersion = ''2.1'' asVersion "true, obviously"
|
|
32 |
|
|
33 |
To get the next version number in the same branch:
|
|
34 |
|
|
35 |
''2.3.4'' asVersion next "2.3.5"
|
|
36 |
|
|
37 |
To get the next version number, starting a new branch:
|
|
38 |
|
|
39 |
''2.3.4'' asVersion branchNext "2.3.4.1"
|
|
40 |
|
|
41 |
To get the common base version of any two version numbers (useful for merging):
|
|
42 |
|
|
43 |
''2.3.8'' asVersion commonBase: ''2.3.4.1'' asVersion "2.3.4"'
|
|
44 |
!
|
|
45 |
|
|
46 |
!VersionNumber class methodsFor:'documentation'!
|
|
47 |
|
1445
|
48 |
copyright
|
|
49 |
"
|
|
50 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
51 |
All Rights Reserved
|
|
52 |
|
|
53 |
This software is furnished under a license and may be used
|
|
54 |
only in accordance with the terms of that license and with the
|
|
55 |
inclusion of the above copyright notice. This software may not
|
|
56 |
be provided or otherwise made available to, or used by, any
|
|
57 |
other person. No title to or ownership of the software is
|
|
58 |
hereby transferred.
|
|
59 |
"
|
|
60 |
!
|
|
61 |
|
1282
|
62 |
documentation
|
|
63 |
"
|
|
64 |
Taken from KomPackaging in squeak.
|
|
65 |
|
|
66 |
[author:]
|
|
67 |
|
|
68 |
[instance variables:]
|
|
69 |
|
|
70 |
[class variables:]
|
|
71 |
|
|
72 |
[see also:]
|
|
73 |
|
|
74 |
"
|
|
75 |
!
|
|
76 |
|
|
77 |
examples
|
|
78 |
"
|
|
79 |
|
|
80 |
more examples to be added:
|
|
81 |
[exBegin]
|
|
82 |
... add code fragment for
|
|
83 |
... executable example here ...
|
|
84 |
[exEnd]
|
|
85 |
"
|
|
86 |
!
|
|
87 |
|
|
88 |
history
|
|
89 |
"Created: / 20.5.2003 / 08:29:00 / james"
|
|
90 |
! !
|
|
91 |
|
|
92 |
!VersionNumber class methodsFor:'as yet unclassified'!
|
|
93 |
|
|
94 |
first
|
|
95 |
|
|
96 |
^self fromCollection: #(1)
|
|
97 |
!
|
|
98 |
|
|
99 |
fromCollection: aCollection
|
|
100 |
|
|
101 |
^self new
|
|
102 |
initializeNumbers: aCollection;
|
|
103 |
yourself
|
|
104 |
!
|
|
105 |
|
|
106 |
fromString: aString
|
|
107 |
|
|
108 |
^self fromCollection:
|
|
109 |
((aString findTokens: '.') collect: [:ea | ea asNumber ])
|
|
110 |
|
|
111 |
! !
|
|
112 |
|
|
113 |
!VersionNumber methodsFor:'accessing'!
|
|
114 |
|
|
115 |
branchNext
|
|
116 |
|
|
117 |
^self class fromCollection: (numbers, (Array with: 1))
|
|
118 |
!
|
|
119 |
|
|
120 |
commonBase: aVersion
|
|
121 |
|
|
122 |
| smallNums largeNums cutoff |
|
|
123 |
(aVersion numbers size <= numbers size)
|
|
124 |
ifTrue: [smallNums := aVersion numbers. largeNums := numbers]
|
|
125 |
ifFalse: [smallNums := numbers. largeNums := aVersion numbers].
|
|
126 |
|
|
127 |
cutoff := (1 to: smallNums size)
|
|
128 |
detect: [ :in | ((smallNums at: in) ~= (largeNums at: in))]
|
|
129 |
ifNone: [^self class fromCollection: smallNums].
|
|
130 |
|
|
131 |
^self class fromCollection:
|
|
132 |
((numbers copyFrom: 1 to: (cutoff - 1)),
|
|
133 |
(Array with: ((smallNums at: cutoff) min: (largeNums at: cutoff))))
|
|
134 |
!
|
|
135 |
|
|
136 |
next
|
|
137 |
|
|
138 |
| tmp |
|
|
139 |
tmp := numbers copy.
|
|
140 |
tmp at: numbers size put: (numbers last + 1).
|
|
141 |
^self class fromCollection: tmp
|
|
142 |
!
|
|
143 |
|
|
144 |
numbers
|
|
145 |
"Answer a copy (to discourage people from directly changing a version number).
|
|
146 |
VersionNumbers should never change, instead, instantiate a new instance."
|
|
147 |
|
|
148 |
^numbers copy
|
|
149 |
!
|
|
150 |
|
|
151 |
previous
|
|
152 |
|
|
153 |
| tmp |
|
|
154 |
numbers last = 1 ifTrue:
|
|
155 |
[^self class fromCollection: (numbers allButLast)].
|
|
156 |
tmp := numbers copy.
|
|
157 |
tmp at: numbers size put: (numbers last - 1).
|
|
158 |
^self class fromCollection: tmp
|
|
159 |
! !
|
|
160 |
|
|
161 |
!VersionNumber methodsFor:'comparing'!
|
|
162 |
|
|
163 |
< another
|
|
164 |
"Answer whether the receiver is less than the argument."
|
|
165 |
|
|
166 |
| tmp |
|
|
167 |
(self inSameBranchAs: another) ifFalse:
|
|
168 |
[^self error: 'Receiver and argument in different branches'].
|
|
169 |
|
|
170 |
tmp := another numbers.
|
|
171 |
(tmp size = numbers size) ifTrue:
|
|
172 |
[1 to: numbers size do:
|
|
173 |
[ :in | (numbers at: in) < (tmp at: in) ifTrue: [^true]].
|
|
174 |
^false].
|
|
175 |
|
|
176 |
^numbers size < tmp size
|
|
177 |
!
|
|
178 |
|
|
179 |
= aVersion
|
|
180 |
|
|
181 |
^numbers = aVersion numbers
|
|
182 |
!
|
|
183 |
|
|
184 |
hash
|
|
185 |
|
|
186 |
^numbers hash
|
|
187 |
! !
|
|
188 |
|
|
189 |
!VersionNumber methodsFor:'initialization'!
|
|
190 |
|
|
191 |
initializeNumbers: aCollection
|
|
192 |
|
|
193 |
aCollection do: [ :ea |
|
|
194 |
ea <= 0 ifTrue:
|
|
195 |
[^self error: 'VersionNumbers cannot contain zero or negative numbers']].
|
|
196 |
|
|
197 |
numbers := aCollection asArray
|
|
198 |
! !
|
|
199 |
|
|
200 |
!VersionNumber methodsFor:'printing'!
|
|
201 |
|
|
202 |
printOn: strm
|
|
203 |
|
|
204 |
self storeOn: strm
|
|
205 |
!
|
|
206 |
|
|
207 |
storeOn: strm
|
|
208 |
|
|
209 |
strm nextPut: $'.
|
|
210 |
self versionStringOn: strm.
|
|
211 |
strm nextPutAll: ''' asVersion'.
|
|
212 |
!
|
|
213 |
|
|
214 |
versionString
|
|
215 |
|
|
216 |
^String streamContents: [ :strm | self versionStringOn: strm ]
|
|
217 |
!
|
|
218 |
|
|
219 |
versionStringOn: strm
|
|
220 |
|
|
221 |
| first |
|
|
222 |
first := true.
|
|
223 |
numbers do: [ :ea |
|
|
224 |
first ifFalse: [strm nextPut: $.].
|
|
225 |
first := false.
|
|
226 |
ea printOn: strm]
|
|
227 |
|
|
228 |
! !
|
|
229 |
|
|
230 |
!VersionNumber methodsFor:'testing'!
|
|
231 |
|
|
232 |
inSameBranchAs: aVersion
|
|
233 |
|
|
234 |
| less more |
|
|
235 |
(aVersion numbers size <= numbers size)
|
|
236 |
ifTrue: [less := aVersion numbers. more := numbers]
|
|
237 |
ifFalse: [less := numbers. more := aVersion numbers].
|
|
238 |
|
|
239 |
1 to: (less size - 1) do: [ :in | ((less at: in) = (more at: in)) ifFalse: [^false]].
|
|
240 |
^less size = more size or:
|
|
241 |
[(less at: less size) <= (more at: less size)]
|
|
242 |
! !
|
|
243 |
|
|
244 |
!VersionNumber class methodsFor:'documentation'!
|
|
245 |
|
|
246 |
version
|
1445
|
247 |
^ '$Header: /cvs/stx/stx/libbasic3/packages/VersionNumber.st,v 1.2 2006-01-10 09:31:53 cg Exp $'
|
1282
|
248 |
! !
|