-
-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy pathSystemVersion.class.st
More file actions
379 lines (296 loc) · 9.23 KB
/
Copy pathSystemVersion.class.st
File metadata and controls
379 lines (296 loc) · 9.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
"
I am responsible for maintaining what version of Pharo and the VM is running. I also track all of the update items that have been included in the image.
I'm invoked at auto start to get the latest plugins, etc.
Some queries are
SystemVersion current major
SystemVersion current minor
SystemVersion current suffix
SystemVersion current highestUpdate
"
Class {
#name : 'SystemVersion',
#superclass : 'Object',
#instVars : [
'date',
'highestUpdate',
'type',
'major',
'minor',
'patch',
'suffix',
'build',
'commitHash'
],
#classVars : [
'Current'
],
#category : 'System-Support-Image',
#package : 'System-Support',
#tag : 'Image'
}
{ #category : 'accessing' }
SystemVersion class >> current [
"In the past we had a defensive strategy while it is not the case anymore. This is because the current version should be explicitly set during the bootstrap and not initialized by a defensive strategy. It can crash it this happens during the bootstrap."
^ Current
]
{ #category : 'private - accessing' }
SystemVersion class >> invalidBuildNumber [
"Return -1 to depict an invalid build number (allows to also accept 0 as build number)"
^ -1
]
{ #category : 'instance creation' }
SystemVersion class >> major: major minor: minor patch: patch [
"Create a new instance of the receiver with the given major minor number.
SystemVersion major: 6 minor: 1 patch: 199
"
^self major: major minor: minor patch: patch suffix: ''
]
{ #category : 'instance creation' }
SystemVersion class >> major: major minor: minor patch: patch suffix: aString [
"Create a new instance of the receiver with the given major minor number and suffix.
SystemVersion major: 6 minor: 1 patch: 199 suffix: 'alpha'
"
^self major: major minor: minor patch: patch suffix: aString build: self invalidBuildNumber
]
{ #category : 'instance creation' }
SystemVersion class >> major: major minor: minor patch: patch suffix: aString build: build [
"Create a new instance of the receiver with the given major minor number and suffix.
SystemVersion major: 6 minor: 1 patch: 199 suffix: 'alpha' build: 148
"
^ self new
major: major;
minor: minor;
patch: patch;
suffix: aString;
build: build;
yourself
]
{ #category : 'instance creation' }
SystemVersion class >> major: major minor: minor patch: patch suffix: aString build: build commitHash: hashString [
"Create a new instance of the receiver with the given major minor number and suffix.
SystemVersion major: 6 minor: 1 suffix: 'alpha'
"
^(self new)
major: major;
minor: minor;
patch: patch;
suffix: aString;
build: build;
commitHash: hashString;
yourself
]
{ #category : 'instance creation' }
SystemVersion class >> setMajor: major minor: minor patch: patch suffix: aString build: build commitHash: hashString [
"Create a SystemVersion instance and set it as current"
^ Current := self
major: major
minor: minor
patch: patch
suffix: aString
build: build
commitHash: hashString
]
{ #category : 'accessing' }
SystemVersion class >> useCurrent: aSystemVersion during: aBlock [
| backup |
backup := Current.
[
Current := aSystemVersion.
aBlock value ] ensure: [ Current := backup ]
]
{ #category : 'accessing - properties' }
SystemVersion >> build [
^ build extractIntegerPart
]
{ #category : 'accessing - properties' }
SystemVersion >> build: aBuildNumber [
build := aBuildNumber
]
{ #category : 'private' }
SystemVersion >> calculateHighestUpdate [
|result|
result := (self major * 10000) + (self minor * 1000).
self hasValidBuildNumber ifTrue: [ result := result + self build ].
^result
]
{ #category : 'accessing - properties' }
SystemVersion >> commitHash [
"Answer the hash of a Git commit from which the image was bootstrapped, e.g. '9ce829e86f978a84fa68df20008a3c1ee52e1fae'"
^ commitHash
]
{ #category : 'accessing - properties' }
SystemVersion >> commitHash: aString [
"Set the hash of a Git commit from which the image was bootstrapped"
commitHash := aString
]
{ #category : 'accessing' }
SystemVersion >> commitHashShort [
"Answer the shorten hash of a Git commit from which the image was bootstrapped, e.g. '9ce829e"
^ commitHash ifNotNil: [ commitHash first: (7 min: commitHash size) ]
]
{ #category : 'accessing - properties' }
SystemVersion >> date [
^date
]
{ #category : 'accessing - properties' }
SystemVersion >> date: newDate [
date := newDate
]
{ #category : 'accessing' }
SystemVersion >> dottedMajorMinor [
^ self majorMinor: '.'
]
{ #category : 'accessing' }
SystemVersion >> dottedMajorMinorPatch [
^ self majorMinorPatch: '.'
]
{ #category : 'testing' }
SystemVersion >> hasMetadataIdentifiers [
"Return true if we have metadata identifiers (see rule 10 on semver.org) that need to be separated with a + sign"
^self suffix notEmpty | self hasValidBuildNumber | self commitHash notEmpty
]
{ #category : 'testing' }
SystemVersion >> hasValidBuildNumber [
"Return true if we have a valid build number"
^self build ~= self class invalidBuildNumber
]
{ #category : 'compatibility' }
SystemVersion >> highestUpdate [
^highestUpdate ifNil: [ highestUpdate := self calculateHighestUpdate ]
]
{ #category : 'compatibility' }
SystemVersion >> highestUpdate: anInteger [
highestUpdate := anInteger
]
{ #category : 'accessing - version strings' }
SystemVersion >> imageVersionString [
"Print the version compatible with naming the image."
^String streamContents: [:str |
str nextPutAll: self type;
nextPut: $-;
nextPutAll: (self majorMinorPatch: '.').
self hasMetadataIdentifiers ifTrue: [ str nextPut: $+ ].
self suffix ifNotEmpty: [ str nextPutAll: self suffix ].
self hasValidBuildNumber ifTrue: [
self suffix ifNotEmpty: [ str nextPut: $.].
str nextPutAll: 'build.'; nextPutAll: self build asString ].
self commitHash ifNotEmpty: [ str nextPutAll: '.sha.'; nextPutAll: self commitHash ].
Smalltalk vm is32bit ifTrue: [ str nextPutAll: ' (32 Bit)' ]
ifFalse: [ str nextPutAll: ' (64 Bit)' ].
]
]
{ #category : 'initialization' }
SystemVersion >> initialize [
super initialize.
type := 'Pharo'.
major := 0.
minor := 0.
patch := 0.
suffix := ''.
build := self class invalidBuildNumber.
commitHash := ''.
date := Date today
]
{ #category : 'accessing - properties' }
SystemVersion >> major [
"Answer the major number of a version. 1 in '1.2'"
^ major extractIntegerPart
]
{ #category : 'accessing - properties' }
SystemVersion >> major: anInteger [
"Set the major part of the receiver"
major := anInteger
]
{ #category : 'utilities' }
SystemVersion >> majorMinor: aSeparatingString [
"Return the major/minor version number of the form XaSeparatingStringY, without any 'alpha' or 'beta' or other suffix."
"SystemVersion current majorMinor: '-'"
"SystemVersion current majorMinor: ''"
^String streamContents: [:str |
str
nextPutAll: self major printString;
nextPutAll: aSeparatingString;
nextPutAll: self minor printString ]
]
{ #category : 'utilities' }
SystemVersion >> majorMinorPatch: aSeparatingString [
"Return the major/minor/patch version number of the form XaSeparatingStringY, without any 'alpha' or 'beta' or other suffix."
"SystemVersion current majorMinorPatch: '-'"
"SystemVersion current majorMinorPatch: ''"
^String streamContents: [:str |
str
nextPutAll: self major printString;
nextPutAll: aSeparatingString;
nextPutAll: self minor printString;
nextPutAll: aSeparatingString;
nextPutAll: self patch printString ]
]
{ #category : 'accessing' }
SystemVersion >> majorMinorVersion [
^ self type, self dottedMajorMinorPatch
]
{ #category : 'accessing - properties' }
SystemVersion >> minor [
"Answer the minor number of a version. 2 in '1.2'"
^ minor extractIntegerPart
]
{ #category : 'accessing - properties' }
SystemVersion >> minor: anInteger [
"Set the minor part of the receiver"
minor := anInteger
]
{ #category : 'accessing' }
SystemVersion >> patch [
^ patch extractIntegerPart
]
{ #category : 'accessing' }
SystemVersion >> patch: anObject [
patch := anObject
]
{ #category : 'printing' }
SystemVersion >> printOn: stream [
stream nextPutAll: self imageVersionString
]
{ #category : 'accessing - version strings' }
SystemVersion >> shortVersionString [
"Print a short version string."
self type ifNil: [^'No version set'].
^String streamContents: [:str |
str
nextPutAll: self type;
nextPutAll: self major printString;
nextPut: $.;
nextPutAll: self minor printString;
nextPut: $.;
nextPutAll: self patch printString;
nextPutAll: self suffix ]
]
{ #category : 'accessing - properties' }
SystemVersion >> suffix [
"Answer the suffix (alpha, beta, rc of a version. beta in '1.2beta'"
^ suffix
]
{ #category : 'accessing - properties' }
SystemVersion >> suffix: anObject [
"Set the value of suffix"
suffix := anObject
]
{ #category : 'accessing - properties' }
SystemVersion >> type [
"Answer the value of type"
^ type
]
{ #category : 'accessing - properties' }
SystemVersion >> type: anObject [
"Set the value of type"
type := anObject
]
{ #category : 'accessing' }
SystemVersion >> version [
"Answer the short version string. If the receiver needs upgrading, do it."
^self shortVersionString
]
{ #category : 'accessing' }
SystemVersion >> versionWithoutPatch [
^ self type , (self majorMinor: '.')
]