1
|
1 |
"{ Package: 'stx:goodies/metacello' }"
|
|
2 |
|
|
3 |
Object subclass:#MetacelloProjectRegistration
|
|
4 |
instanceVariableNames:'projectName configurationProjectSpec baselineProjectSpec
|
|
5 |
loadedInImage locked mutable'
|
|
6 |
classVariableNames:'Registry'
|
|
7 |
poolDictionaries:''
|
|
8 |
category:'Metacello-Core-Scripts'
|
|
9 |
!
|
|
10 |
|
|
11 |
|
|
12 |
!MetacelloProjectRegistration class methodsFor:'instance creation'!
|
|
13 |
|
|
14 |
fromMCBaselineProjectSpec: aProjectSpec
|
|
15 |
^ self new
|
|
16 |
projectName: aProjectSpec name;
|
|
17 |
baselineProjectSpec: aProjectSpec;
|
|
18 |
yourself
|
|
19 |
!
|
|
20 |
|
|
21 |
fromMCConfigurationProjectSpec: aProjectSpec
|
|
22 |
^ self new
|
|
23 |
projectName: aProjectSpec name;
|
|
24 |
configurationProjectSpec: aProjectSpec;
|
|
25 |
yourself
|
|
26 |
! !
|
|
27 |
|
|
28 |
!MetacelloProjectRegistration class methodsFor:'accessing'!
|
|
29 |
|
|
30 |
baselineClasses
|
|
31 |
"Return a set of the Metacello baseline classes that have been loaded into the image."
|
|
32 |
|
|
33 |
"self baselineClasses"
|
|
34 |
|
|
35 |
^ BaselineOf allSubclasses
|
|
36 |
!
|
|
37 |
|
|
38 |
baselineProjectSpecs
|
|
39 |
"MetacelloProjectRegistration baselineProjectSpecs"
|
|
40 |
|
|
41 |
^ self registry baselineProjectSpecs
|
|
42 |
!
|
|
43 |
|
|
44 |
configurationClasses
|
|
45 |
"Return a set of the Metacello configuration classes that have been loaded into the image."
|
|
46 |
|
|
47 |
"self configurationClasses"
|
|
48 |
|
|
49 |
| answer |
|
|
50 |
answer := IdentitySet new.
|
|
51 |
ConfigurationOf allSubclasses
|
|
52 |
do: [ :cl |
|
|
53 |
(cl == BaselineOf or: [ cl inheritsFrom: BaselineOf ])
|
|
54 |
ifFalse: [ answer add: cl ] ].
|
|
55 |
Object allSubclasses
|
|
56 |
do: [ :cl |
|
|
57 |
(answer includes: cl)
|
|
58 |
ifFalse: [
|
|
59 |
(([ cl isMetacelloConfig ]
|
|
60 |
on: Error
|
|
61 |
do: [ :ex | ex return: false ]) and: [ cl name asString beginsWith: 'ConfigurationOf' ])
|
|
62 |
ifTrue: [ answer add: cl ] ] ].
|
|
63 |
^ answer
|
|
64 |
!
|
|
65 |
|
|
66 |
configurationProjectSpecs
|
|
67 |
"MetacelloProjectRegistration configurationProjectSpecs"
|
|
68 |
|
|
69 |
^ self registry configurationProjectSpecs
|
|
70 |
!
|
|
71 |
|
|
72 |
primeRegistryFromImage
|
|
73 |
"MetacelloProjectRegistration primeRegistryFromImage"
|
|
74 |
|
|
75 |
self registry primeRegistryFromImage
|
|
76 |
!
|
|
77 |
|
|
78 |
projectSpecs
|
|
79 |
"MetacelloProjectRegistration projectSpecs"
|
|
80 |
|
|
81 |
^ self configurationProjectSpecs , self baselineProjectSpecs
|
|
82 |
!
|
|
83 |
|
|
84 |
registry
|
|
85 |
Registry ifNil: [ Registry := MetacelloProjectRegistry new ].
|
|
86 |
^ Registry
|
|
87 |
!
|
|
88 |
|
|
89 |
registry: aMetacelloProjectRegistry
|
|
90 |
Registry := aMetacelloProjectRegistry
|
|
91 |
!
|
|
92 |
|
|
93 |
resetRegistry
|
|
94 |
Registry := nil
|
|
95 |
! !
|
|
96 |
|
|
97 |
!MetacelloProjectRegistration class methodsFor:'mutability'!
|
|
98 |
|
|
99 |
copyRegistryRestoreOnErrorWhile: aBlock
|
|
100 |
"install copy of registry for duration of <aBlock> execution."
|
|
101 |
|
|
102 |
"registrations will be copied on write during <aBlock> execution."
|
|
103 |
|
|
104 |
"if <aBlock> does not return control to this context, revert to the original
|
|
105 |
version of the registry. Otherwise leave the new copy installed."
|
|
106 |
|
|
107 |
| oldRegistry newRegistry |
|
|
108 |
oldRegistry := self registry.
|
|
109 |
newRegistry := self registry copy.
|
|
110 |
self registry: newRegistry.
|
|
111 |
aBlock
|
|
112 |
ensure: [
|
|
113 |
"install old version of registry"
|
|
114 |
self registry: oldRegistry ].
|
|
115 |
self registry: newRegistry "if control returned, install newRegistry"
|
|
116 |
!
|
|
117 |
|
|
118 |
copyRegistryWhile: aBlock
|
|
119 |
"install copy of registry for duration of <aBlock> execution."
|
|
120 |
|
|
121 |
"registrations will be copied on write during <aBlock> execution."
|
|
122 |
|
|
123 |
"Unconditionally revert to the original
|
|
124 |
version of the registry. Otherwise leave the new copy installed."
|
|
125 |
|
|
126 |
| oldRegistry newRegistry |
|
|
127 |
oldRegistry := self registry.
|
|
128 |
newRegistry := self registry copy.
|
|
129 |
self registry: newRegistry.
|
|
130 |
aBlock
|
|
131 |
ensure: [
|
|
132 |
"install old version of registry"
|
|
133 |
self registry: oldRegistry ]
|
|
134 |
! !
|
|
135 |
|
|
136 |
!MetacelloProjectRegistration class methodsFor:'querying'!
|
|
137 |
|
|
138 |
projectSpecForClassNamed: aClassName ifAbsent: absentBlock
|
|
139 |
^ self registry projectSpecForClassNamed: aClassName ifAbsent: absentBlock
|
|
140 |
!
|
|
141 |
|
|
142 |
registrationForClassNamed: aClassName ifAbsent: absentBlock
|
|
143 |
^ self registry registrationForClassNamed: aClassName ifAbsent: absentBlock
|
|
144 |
!
|
|
145 |
|
|
146 |
registrationForProjectSpec: aProjectSpec ifAbsent: absentBlock ifPresent: presentBlock
|
|
147 |
| newRegistration |
|
|
148 |
newRegistration := aProjectSpec asProjectRegistration.
|
|
149 |
self registry
|
|
150 |
registrationFor: newRegistration
|
|
151 |
ifPresent: [ :existing | ^ presentBlock value: existing value: newRegistration ]
|
|
152 |
ifAbsent: [ ^ absentBlock value: newRegistration ]
|
|
153 |
! !
|
|
154 |
|
|
155 |
!MetacelloProjectRegistration class methodsFor:'registration'!
|
|
156 |
|
|
157 |
registerProjectSpec: aProjectSpec ifPresent: presentBlock
|
|
158 |
| newRegistration |
|
|
159 |
newRegistration := aProjectSpec asProjectRegistration.
|
|
160 |
^ self registry
|
|
161 |
registrationFor: newRegistration
|
|
162 |
ifPresent: [ :existing | presentBlock value: existing value: newRegistration ]
|
|
163 |
ifAbsent: [ newRegistration registerProject ]
|
|
164 |
! !
|
|
165 |
|
|
166 |
!MetacelloProjectRegistration methodsFor:'accessing'!
|
|
167 |
|
|
168 |
baseName
|
|
169 |
^ MetacelloScriptEngine baseNameOf: (configurationProjectSpec ifNil: [ baselineProjectSpec ]) className
|
|
170 |
!
|
|
171 |
|
|
172 |
baselineProjectSpec
|
|
173 |
^ baselineProjectSpec
|
|
174 |
!
|
|
175 |
|
|
176 |
baselineProjectSpec: anObject
|
|
177 |
self shouldBeMutable.
|
|
178 |
baselineProjectSpec := anObject
|
|
179 |
!
|
|
180 |
|
|
181 |
baselineProjectSpecIfAbsent: absentBlock
|
|
182 |
^ baselineProjectSpec ifNil: absentBlock
|
|
183 |
!
|
|
184 |
|
|
185 |
baselineProjectSpecIfPresent: presentBlock ifAbsent: absentBlock
|
|
186 |
^ baselineProjectSpec ifNotNil: [ presentBlock cull: baselineProjectSpec ] ifNil: absentBlock
|
|
187 |
!
|
|
188 |
|
|
189 |
configurationProjectSpec
|
|
190 |
^ configurationProjectSpec
|
|
191 |
!
|
|
192 |
|
|
193 |
configurationProjectSpec: anObject
|
|
194 |
self shouldBeMutable.
|
|
195 |
configurationProjectSpec := anObject
|
|
196 |
!
|
|
197 |
|
|
198 |
configurationProjectSpecIfAbsent: absentBlock
|
|
199 |
^ configurationProjectSpec ifNil: absentBlock
|
|
200 |
!
|
|
201 |
|
|
202 |
configurationProjectSpecIfPresent: presentBlock ifAbsent: absentBlock
|
|
203 |
^ configurationProjectSpec ifNotNil: [ presentBlock cull: configurationProjectSpec ] ifNil: absentBlock
|
|
204 |
!
|
|
205 |
|
|
206 |
loadedInImage
|
|
207 |
loadedInImage ifNil: [ loadedInImage := false ].
|
|
208 |
^ loadedInImage
|
|
209 |
!
|
|
210 |
|
|
211 |
loadedInImage: anObject
|
|
212 |
self shouldBeMutable.
|
|
213 |
loadedInImage := anObject
|
|
214 |
!
|
|
215 |
|
|
216 |
locked
|
|
217 |
locked ifNil: [ locked := false ].
|
|
218 |
^ locked
|
|
219 |
!
|
|
220 |
|
|
221 |
locked: anObject
|
|
222 |
self shouldBeMutable.
|
|
223 |
locked := anObject
|
|
224 |
!
|
|
225 |
|
|
226 |
projectName
|
|
227 |
^ projectName
|
|
228 |
!
|
|
229 |
|
|
230 |
projectName: anObject
|
|
231 |
self shouldBeMutable.
|
|
232 |
projectName := anObject
|
|
233 |
!
|
|
234 |
|
|
235 |
repositoryDescriptions
|
|
236 |
^ (self configurationProjectSpecIfAbsent: [ self baselineProjectSpec ]) repositoryDescriptions
|
|
237 |
!
|
|
238 |
|
|
239 |
version
|
|
240 |
^ (self configurationProjectSpecIfAbsent: [ ^ MetacelloMCBaselineProject singletonVersionName ]) versionString
|
|
241 |
! !
|
|
242 |
|
|
243 |
!MetacelloProjectRegistration methodsFor:'comparision'!
|
|
244 |
|
|
245 |
= aRegistration
|
|
246 |
aRegistration class == self class
|
|
247 |
ifFalse: [ ^ false ].
|
|
248 |
^ (configurationProjectSpec registrationsCompareEqual: aRegistration configurationProjectSpec)
|
|
249 |
and: [ baselineProjectSpec registrationsCompareEqual: aRegistration baselineProjectSpec ]
|
|
250 |
!
|
|
251 |
|
|
252 |
hash
|
|
253 |
^ ((String stringHash: projectName initialHash: 0) bitXor: configurationProjectSpec metacelloRegistrationHash)
|
|
254 |
bitXor: baselineProjectSpec metacelloRegistrationHash
|
|
255 |
! !
|
|
256 |
|
|
257 |
!MetacelloProjectRegistration methodsFor:'copying'!
|
|
258 |
|
|
259 |
postCopy
|
|
260 |
super postCopy.
|
|
261 |
mutable := nil
|
|
262 |
! !
|
|
263 |
|
|
264 |
!MetacelloProjectRegistration methodsFor:'lookup'!
|
|
265 |
|
|
266 |
lookupBaselineSpec
|
3
|
267 |
|
|
268 |
baselineProjectSpec ifNotNil: [ ^ baselineProjectSpec ].
|
1
|
269 |
^ configurationProjectSpec
|
|
270 |
!
|
|
271 |
|
|
272 |
lookupConfigurationSpec
|
3
|
273 |
configurationProjectSpec ifNotNil: [ ^ configurationProjectSpec ].
|
1
|
274 |
^ baselineProjectSpec
|
|
275 |
!
|
|
276 |
|
|
277 |
lookupSpec: aProjectSpec
|
3
|
278 |
| spec |
|
|
279 |
|
|
280 |
(spec := self configurationProjectSpec)
|
|
281 |
ifNotNil: [
|
1
|
282 |
spec className = aProjectSpec className
|
|
283 |
ifTrue: [ ^ spec ] ].
|
3
|
284 |
(spec := self baselineProjectSpec)
|
|
285 |
ifNotNil: [
|
1
|
286 |
spec className = aProjectSpec className
|
|
287 |
ifTrue: [ ^ spec ] ].
|
|
288 |
^ nil
|
|
289 |
! !
|
|
290 |
|
|
291 |
!MetacelloProjectRegistration methodsFor:'merging'!
|
|
292 |
|
|
293 |
merge: aProjectRegistration
|
|
294 |
"should only be called from MetacelloProjectRegistration class>>mergeRegistration:with: ... merge is done when a spec has been loaded into the image"
|
|
295 |
|
|
296 |
"nil specs are ignored in the merge, otherwise aProjectRegistration specs win"
|
|
297 |
|
|
298 |
"(self hasMergeConflicts: aProjectRegistration)
|
|
299 |
ifTrue: [ ^ self error: 'Attempt to merge registrations with conflicts' ]."
|
|
300 |
|
|
301 |
self shouldBeMutable.
|
|
302 |
configurationProjectSpec
|
|
303 |
ifNil: [ configurationProjectSpec := aProjectRegistration configurationProjectSpec ]
|
|
304 |
ifNotNil: [
|
|
305 |
aProjectRegistration configurationProjectSpec
|
|
306 |
ifNotNil: [ configurationProjectSpec := aProjectRegistration configurationProjectSpec ] ].
|
|
307 |
baselineProjectSpec
|
|
308 |
ifNil: [ baselineProjectSpec := aProjectRegistration baselineProjectSpec ]
|
|
309 |
ifNotNil: [ aProjectRegistration baselineProjectSpec ifNotNil: [ baselineProjectSpec := aProjectRegistration baselineProjectSpec ] ]
|
|
310 |
! !
|
|
311 |
|
|
312 |
!MetacelloProjectRegistration methodsFor:'mutability'!
|
|
313 |
|
|
314 |
copyOnWrite: aBlock
|
|
315 |
"assume that only registered projects are immutable ... otherwise you'll get an error"
|
|
316 |
|
|
317 |
| copy |
|
|
318 |
self class registry
|
|
319 |
registrationFor: self
|
|
320 |
ifPresent: [ :existing | ]
|
|
321 |
ifAbsent: [
|
|
322 |
aBlock value: self.
|
|
323 |
^ self ].
|
|
324 |
self unregisterProject.
|
|
325 |
copy := self copy.
|
|
326 |
aBlock value: copy.
|
|
327 |
copy registerProject.
|
|
328 |
^ copy
|
|
329 |
!
|
|
330 |
|
|
331 |
immutable
|
|
332 |
mutable := false
|
|
333 |
!
|
|
334 |
|
|
335 |
isMutable
|
|
336 |
mutable ifNil: [ ^ true ].
|
|
337 |
^ mutable
|
|
338 |
!
|
|
339 |
|
|
340 |
mutable
|
|
341 |
mutable := true
|
|
342 |
!
|
|
343 |
|
|
344 |
shouldBeMutable
|
|
345 |
self isMutable
|
|
346 |
ifTrue: [ ^ self ].
|
|
347 |
self error: 'Not allowed to modify an immutable object'
|
|
348 |
! !
|
|
349 |
|
|
350 |
!MetacelloProjectRegistration methodsFor:'printing'!
|
|
351 |
|
|
352 |
printOn: aStream
|
|
353 |
| label versionString descriptions |
|
|
354 |
self
|
|
355 |
configurationProjectSpecIfPresent: [ :spec |
|
|
356 |
label := spec className.
|
|
357 |
versionString := spec versionString ]
|
|
358 |
ifAbsent: [
|
|
359 |
"baseline"
|
|
360 |
label := self baselineProjectSpec className.
|
|
361 |
versionString := '[baseline]' ].
|
|
362 |
aStream
|
|
363 |
nextPutAll: label;
|
|
364 |
space;
|
|
365 |
nextPutAll: versionString.
|
|
366 |
(descriptions := self repositoryDescriptions) isEmpty
|
|
367 |
ifTrue: [ ^ self ].
|
|
368 |
aStream nextPutAll: ' from '.
|
|
369 |
descriptions size = 1
|
|
370 |
ifTrue: [ aStream nextPutAll: descriptions first ]
|
|
371 |
ifFalse: [
|
|
372 |
aStream nextPut: ${.
|
|
373 |
descriptions do: [ :description | aStream nextPutAll: description ].
|
|
374 |
aStream nextPut: $} ]
|
|
375 |
! !
|
|
376 |
|
|
377 |
!MetacelloProjectRegistration methodsFor:'querying'!
|
|
378 |
|
|
379 |
currentlyLoadedClassesInProject
|
|
380 |
| classes |
|
|
381 |
classes := Set new.
|
|
382 |
self
|
|
383 |
configurationProjectSpecIfPresent: [ :spec | classes addAll: spec currentlyLoadedClassesInVersion ]
|
|
384 |
ifAbsent: [ ].
|
|
385 |
self baselineProjectSpecIfPresent: [ :spec | classes addAll: spec currentlyLoadedClassesInVersion ] ifAbsent: [ ].
|
|
386 |
^ classes
|
|
387 |
! !
|
|
388 |
|
|
389 |
!MetacelloProjectRegistration methodsFor:'registration'!
|
|
390 |
|
|
391 |
registerProject
|
|
392 |
"unconditionally register <newRegistration> ... use with care"
|
|
393 |
|
|
394 |
self class registry registerProjectRegistration: self
|
|
395 |
!
|
|
396 |
|
|
397 |
unregisterProject
|
|
398 |
self class registry unregisterProjectRegistration: self
|
|
399 |
! !
|
|
400 |
|
|
401 |
!MetacelloProjectRegistration methodsFor:'testing'!
|
|
402 |
|
|
403 |
canDowngradeTo: aProjectRegistration
|
|
404 |
"true if there are no load conflicts
|
|
405 |
OR
|
|
406 |
if the load conflicts involved two cofigurations ONLY and a downgrade is allowed"
|
|
407 |
|
|
408 |
(self hasLoadConflicts: aProjectRegistration)
|
|
409 |
ifFalse: [ ^ true ].
|
|
410 |
configurationProjectSpec
|
|
411 |
ifNotNil: [
|
|
412 |
aProjectRegistration configurationProjectSpec
|
|
413 |
ifNotNil: [
|
|
414 |
configurationProjectSpec ensureProjectLoaded.
|
|
415 |
^ configurationProjectSpec canDowngradeTo: aProjectRegistration configurationProjectSpec ] ].
|
|
416 |
^ false
|
|
417 |
!
|
|
418 |
|
|
419 |
canUpgradeTo: aProjectRegistration
|
|
420 |
"true if there are no load conflicts
|
|
421 |
OR
|
|
422 |
if the load conflicts involved two cofigurations ONLY and an upgrade is allowed"
|
|
423 |
|
|
424 |
(self hasLoadConflicts: aProjectRegistration)
|
|
425 |
ifFalse: [ ^ true ].
|
|
426 |
configurationProjectSpec
|
|
427 |
ifNotNil: [
|
|
428 |
aProjectRegistration configurationProjectSpec
|
|
429 |
ifNotNil: [
|
|
430 |
configurationProjectSpec copy ensureProjectLoaded.
|
|
431 |
^ configurationProjectSpec canUpgradeTo: aProjectRegistration configurationProjectSpec ] ].
|
|
432 |
^ false
|
|
433 |
!
|
|
434 |
|
|
435 |
hasLoadConflicts: aProjectRegistration
|
|
436 |
"5 combinations of loads with no load conflicts:
|
|
437 |
No configs and baselines =
|
|
438 |
configs = and no baselines
|
|
439 |
configs = and baselines =
|
|
440 |
configs = and no baseline loaded (self) with a baseline to load (aProjectRegistration)
|
|
441 |
config loaded (self), no config to load (aProjectRegistration) and no baseline loaded(self) with a baseline to load (aProjectRegistration) "
|
|
442 |
|
|
443 |
self isValid
|
|
444 |
ifFalse: [ self error: 'Invalid projectRegistration: ' , self printString ].
|
|
445 |
aProjectRegistration isValid
|
|
446 |
ifFalse: [ self error: 'Invalid projectRegistration: ' , aProjectRegistration printString ].
|
|
447 |
configurationProjectSpec
|
|
448 |
ifNil: [
|
|
449 |
aProjectRegistration configurationProjectSpec notNil
|
|
450 |
ifTrue: [ ^ true ] ]
|
|
451 |
ifNotNil: [
|
|
452 |
aProjectRegistration configurationProjectSpec
|
|
453 |
ifNotNil: [
|
|
454 |
(aProjectRegistration configurationProjectSpec registrationsCompareEqual: configurationProjectSpec) not
|
|
455 |
ifTrue: [ ^ true ] ] ].
|
|
456 |
^ baselineProjectSpec
|
|
457 |
ifNil: [ false ]
|
|
458 |
ifNotNil: [ (baselineProjectSpec registrationsCompareEqual: aProjectRegistration baselineProjectSpec) not ]
|
|
459 |
!
|
|
460 |
|
|
461 |
isValid
|
|
462 |
" has a name and one or the other of the projectSpecs is non-nil"
|
|
463 |
|
|
464 |
projectName ifNil: [ ^ false ].
|
|
465 |
^ configurationProjectSpec notNil or: [ baselineProjectSpec notNil ]
|
|
466 |
! !
|
|
467 |
|
|
468 |
!MetacelloProjectRegistration class methodsFor:'documentation'!
|
|
469 |
|
|
470 |
version_SVN
|
|
471 |
^ '$Id:: $'
|
|
472 |
! !
|