70
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
|
3 |
Object subclass:#MCPackageLoader
|
213
|
4 |
instanceVariableNames:'requirements unloadableDefinitions overrideDefinitions
|
|
5 |
obsoletions additions removals errorDefinitions provisions'
|
430
|
6 |
classVariableNames:'Debugging'
|
70
|
7 |
poolDictionaries:''
|
|
8 |
category:'Monticello-Loading'
|
|
9 |
!
|
|
10 |
|
|
11 |
|
213
|
12 |
!MCPackageLoader class methodsFor:'initialization'!
|
|
13 |
|
|
14 |
new
|
|
15 |
^self basicNew initialize
|
|
16 |
! !
|
|
17 |
|
70
|
18 |
!MCPackageLoader class methodsFor:'as yet unclassified'!
|
|
19 |
|
|
20 |
installSnapshot: aSnapshot
|
|
21 |
self new
|
|
22 |
installSnapshot: aSnapshot;
|
|
23 |
load
|
|
24 |
!
|
|
25 |
|
|
26 |
unloadPackage: aPackage
|
|
27 |
self new
|
|
28 |
unloadPackage: aPackage;
|
|
29 |
loadWithNameLike: aPackage name, '-unload'
|
|
30 |
!
|
|
31 |
|
|
32 |
updatePackage: aPackage withSnapshot: aSnapshot
|
|
33 |
self new
|
|
34 |
updatePackage: aPackage withSnapshot: aSnapshot;
|
|
35 |
load
|
|
36 |
! !
|
|
37 |
|
213
|
38 |
!MCPackageLoader methodsFor:'accessing'!
|
|
39 |
|
|
40 |
overrideDefinitions
|
|
41 |
^ overrideDefinitions
|
|
42 |
!
|
|
43 |
|
|
44 |
unloadableDefinitions
|
|
45 |
^ unloadableDefinitions
|
|
46 |
! !
|
|
47 |
|
70
|
48 |
!MCPackageLoader methodsFor:'patch ops'!
|
|
49 |
|
|
50 |
addDefinition: aDefinition
|
|
51 |
additions add: aDefinition
|
|
52 |
!
|
|
53 |
|
|
54 |
modifyDefinition: old to: new
|
|
55 |
self addDefinition: new.
|
|
56 |
obsoletions at: new put: old.
|
|
57 |
!
|
|
58 |
|
|
59 |
removeDefinition: aDefinition
|
|
60 |
removals add: aDefinition
|
|
61 |
! !
|
|
62 |
|
|
63 |
!MCPackageLoader methodsFor:'private'!
|
|
64 |
|
|
65 |
analyze
|
213
|
66 |
| sorter |
|
|
67 |
sorter := self sorterForItems: additions.
|
|
68 |
additions := sorter orderedItems.
|
|
69 |
requirements := sorter externalRequirements.
|
|
70 |
unloadableDefinitions := sorter itemsWithMissingRequirements asSortedCollection.
|
|
71 |
|
|
72 |
overrideDefinitions := additions select:[:e|e isOverrideDefinition].
|
|
73 |
additions := additions reject: [:e|e isOverrideDefinition].
|
|
74 |
|
|
75 |
sorter := self sorterForItems: removals.
|
|
76 |
removals := sorter orderedItems reversed.
|
|
77 |
|
|
78 |
"Modified: / 08-11-2010 / 17:34:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
70
|
79 |
!
|
|
80 |
|
|
81 |
basicLoad
|
213
|
82 |
| allowEmptyStatements allowSqueakExtensions |
|
|
83 |
|
|
84 |
allowEmptyStatements := ParserFlags allowEmptyStatements.
|
|
85 |
allowSqueakExtensions := ParserFlags allowSqueakExtensions.
|
|
86 |
ParserFlags allowEmptyStatements: true.
|
|
87 |
ParserFlags allowSqueakExtensions: true.
|
|
88 |
|
|
89 |
errorDefinitions := OrderedCollection new.
|
|
90 |
self warnAboutUnloadables.
|
|
91 |
|
|
92 |
|
|
93 |
[[
|
|
94 |
| oldErrorDefinitions |
|
|
95 |
additions do: [:ea | self tryToLoad: ea] displayingProgress: 'Loading...'.
|
|
96 |
removals do: [:ea | ea unload] displayingProgress: 'Cleaning up...'.
|
|
97 |
self shouldWarnAboutErrors ifTrue: [self warnAboutErrors].
|
|
98 |
oldErrorDefinitions := errorDefinitions.
|
|
99 |
errorDefinitions := OrderedCollection new.
|
|
100 |
oldErrorDefinitions do: [:ea | self tryToLoad: ea] displayingProgress: 'Reloading...'.
|
|
101 |
additions do: [:ea | ea postloadOver: (self obsoletionFor: ea)] displayingProgress: 'Initializing...'.
|
|
102 |
|
|
103 |
self warnAboutOverrides.
|
|
104 |
self warnAboutErrors.
|
|
105 |
|
|
106 |
]
|
|
107 |
|
|
108 |
on: InMidstOfFileinNotification
|
|
109 |
do: [:n | n resume: true]]
|
|
110 |
ensure:
|
|
111 |
[self flushChangesFile.
|
|
112 |
ParserFlags allowEmptyStatements: allowEmptyStatements.
|
|
113 |
ParserFlags allowSqueakExtensions: allowSqueakExtensions.
|
|
114 |
]
|
|
115 |
|
|
116 |
"Modified: / 08-11-2010 / 23:49:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
430
|
117 |
"Modified: / 20-08-2011 / 18:20:54 / cg"
|
70
|
118 |
!
|
|
119 |
|
|
120 |
dependencyWarning
|
|
121 |
^ String streamContents:
|
|
122 |
[:s |
|
|
123 |
s nextPutAll: 'This package depends on the following classes:'; cr.
|
|
124 |
requirements do: [:ea | s space; space; nextPutAll: ea; cr].
|
|
125 |
s nextPutAll: 'You must resolve these dependencies before you will be able to load these definitions: '; cr.
|
|
126 |
unloadableDefinitions do: [:ea | s space; space; nextPutAll: ea summary; cr]]
|
|
127 |
!
|
|
128 |
|
|
129 |
errorDefinitionWarning
|
|
130 |
^ String streamContents:
|
|
131 |
[:s |
|
|
132 |
s nextPutAll: 'The following definitions had errors while loading. Press Proceed to try to load them again (they may work on a second pass):'; cr.
|
|
133 |
errorDefinitions do: [:ea | s space; space; nextPutAll: ea summary; cr]]
|
|
134 |
!
|
|
135 |
|
|
136 |
flushChangesFile
|
213
|
137 |
"The changes file is second in the SourceFiles array"
|
|
138 |
|
|
139 |
"(SourceFiles at: 2) flush"
|
|
140 |
|
|
141 |
"Modified: / 11-09-2010 / 18:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
142 |
!
|
|
143 |
|
|
144 |
ifInteractive: aBlock
|
|
145 |
|
|
146 |
^self ifInteractive: aBlock else:[]
|
70
|
147 |
|
213
|
148 |
"Created: / 06-03-2011 / 20:32:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
149 |
!
|
|
150 |
|
|
151 |
ifInteractive: interactiveBlock else: noninteractiveBlock
|
|
152 |
|
|
153 |
MCInteractiveLoadingQuery query
|
|
154 |
ifTrue:[interactiveBlock value]
|
|
155 |
ifFalse:[noninteractiveBlock value].
|
|
156 |
|
|
157 |
"Created: / 06-03-2011 / 20:31:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
70
|
158 |
!
|
|
159 |
|
|
160 |
initialize
|
213
|
161 |
super initialize.
|
|
162 |
additions := OrderedCollection new.
|
|
163 |
removals := OrderedCollection new.
|
|
164 |
obsoletions := Dictionary new.
|
|
165 |
|
70
|
166 |
!
|
|
167 |
|
|
168 |
obsoletionFor: aDefinition
|
|
169 |
^ obsoletions at: aDefinition ifAbsent: [nil]
|
|
170 |
!
|
|
171 |
|
|
172 |
orderDefinitionsForLoading: aCollection
|
|
173 |
^ (self sorterForItems: aCollection) orderedItems
|
|
174 |
!
|
|
175 |
|
|
176 |
orderedAdditions
|
|
177 |
^ additions
|
|
178 |
!
|
|
179 |
|
|
180 |
provisions
|
213
|
181 |
^ provisions ifNil: [provisions := Set withAll: Smalltalk keys]
|
70
|
182 |
!
|
|
183 |
|
|
184 |
shouldWarnAboutErrors
|
|
185 |
^ errorDefinitions isEmpty not and: [false "should make this a preference"]
|
|
186 |
!
|
|
187 |
|
|
188 |
sorterForItems: aCollection
|
|
189 |
| sorter |
|
213
|
190 |
sorter := MCDependencySorter items: aCollection.
|
70
|
191 |
sorter addExternalProvisions: self provisions.
|
|
192 |
^ sorter
|
|
193 |
!
|
|
194 |
|
|
195 |
tryToLoad: aDefinition
|
430
|
196 |
[aDefinition loadOver: (self obsoletionFor: aDefinition)] on: Error do: [:ex |
|
|
197 |
Debugging == true ifTrue:[
|
|
198 |
ex reject
|
|
199 |
].
|
|
200 |
Transcript showCR:'error during load (to debug, set MCPackageLoader:Debugging to true): '.
|
|
201 |
Transcript showCR:ex description.
|
|
202 |
|
|
203 |
errorDefinitions add: aDefinition.
|
|
204 |
].
|
|
205 |
|
|
206 |
"Modified: / 20-08-2011 / 18:20:36 / cg"
|
70
|
207 |
!
|
|
208 |
|
213
|
209 |
tryToLoadAll: definitions label: label
|
|
210 |
|
|
211 |
definitions do:[:e|self tryToLoad: e] displayingProgress: label.
|
|
212 |
|
|
213 |
"Created: / 09-11-2010 / 17:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
214 |
!
|
|
215 |
|
70
|
216 |
useChangeSetNamed: baseName during: aBlock
|
213
|
217 |
"Use the named change set, or create one with the given name."
|
|
218 |
| changeHolder oldChanges newChanges |
|
|
219 |
changeHolder := (ChangeSet respondsTo: #newChanges:)
|
|
220 |
ifTrue: [ChangeSet]
|
|
221 |
ifFalse: [Smalltalk].
|
|
222 |
oldChanges := (ChangeSet respondsTo: #current)
|
|
223 |
ifTrue: [ChangeSet current]
|
|
224 |
ifFalse: [Smalltalk changes].
|
70
|
225 |
|
213
|
226 |
"/JV @ 2010-09-11: Don't cate about changes
|
|
227 |
"/newChanges := (ChangeSorter changeSetNamed: baseName) ifNil: [ ChangeSet new name: baseName ].
|
|
228 |
"/changeHolder newChanges: newChanges.
|
|
229 |
"/[aBlock value] ensure: [changeHolder newChanges: oldChanges].
|
|
230 |
Class withoutUpdatingChangesDo: aBlock
|
|
231 |
|
|
232 |
"Modified: / 08-11-2010 / 20:01:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
70
|
233 |
!
|
|
234 |
|
|
235 |
useNewChangeSetDuring: aBlock
|
|
236 |
^self useNewChangeSetNamedLike: 'MC' during: aBlock
|
|
237 |
!
|
|
238 |
|
|
239 |
useNewChangeSetNamedLike: baseName during: aBlock
|
|
240 |
^self useChangeSetNamed: (ChangeSet uniqueNameLike: baseName) during: aBlock
|
|
241 |
!
|
|
242 |
|
213
|
243 |
warnAboutDependencies
|
|
244 |
"
|
|
245 |
|
|
246 |
|
|
247 |
self notify: self dependencyWarning
|
|
248 |
"
|
|
249 |
|
|
250 |
"Modified: / 13-10-2010 / 15:44:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
70
|
251 |
!
|
|
252 |
|
|
253 |
warnAboutErrors
|
213
|
254 |
|
|
255 |
| changes |
|
|
256 |
|
|
257 |
errorDefinitions isNilOrEmptyCollection ifTrue:[^self].
|
|
258 |
changes := ChangeSet withAll:(errorDefinitions select:[:e|e notNil] thenCollect:[:e|e asChange]).
|
|
259 |
|
430
|
260 |
changes := Tools::ChangeSetBrowser2
|
213
|
261 |
openOn: changes
|
|
262 |
label:'Error definitions'.
|
|
263 |
|
|
264 |
"Created: / 08-11-2010 / 20:19:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
265 |
"Modified: / 06-03-2011 / 20:39:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
430
|
266 |
"Modified: / 20-08-2011 / 18:00:02 / cg"
|
213
|
267 |
!
|
|
268 |
|
|
269 |
warnAboutOverrides
|
|
270 |
|
431
|
271 |
| changes confirmedChanges definitions |
|
213
|
272 |
|
|
273 |
overrideDefinitions isNilOrEmptyCollection ifTrue:[^self].
|
|
274 |
self ifInteractive:[
|
|
275 |
changes := ChangeSet withAll:(overrideDefinitions collect:[:e|e asChange]).
|
431
|
276 |
self assert:(changes includes:nil) not.
|
|
277 |
confirmedChanges := Tools::ChangeSetBrowser2
|
213
|
278 |
confirmChanges: changes
|
|
279 |
label:'Overridden definitions. Load anyway?'.
|
433
|
280 |
confirmedChanges notEmpty ifTrue:[
|
|
281 |
confirmedChanges := confirmedChanges flatten.
|
|
282 |
definitions := confirmedChanges collect:[:e|e mcDefinition].
|
|
283 |
self assert:(definitions includes:nil) not.
|
|
284 |
self tryToLoadAll: definitions label: 'Loading overrides...'.
|
|
285 |
]
|
213
|
286 |
] else:[
|
|
287 |
self tryToLoadAll: overrideDefinitions label: 'Loading overrides...'.
|
|
288 |
]
|
|
289 |
|
|
290 |
"Created: / 08-11-2010 / 20:19:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
291 |
"Modified: / 06-03-2011 / 20:33:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
433
|
292 |
"Modified: / 20-08-2011 / 19:31:40 / cg"
|
213
|
293 |
!
|
|
294 |
|
|
295 |
warnAboutUnloadables
|
|
296 |
|
433
|
297 |
| changes confirmedChanges definitions |
|
213
|
298 |
|
|
299 |
unloadableDefinitions isNilOrEmptyCollection ifTrue:[^self].
|
|
300 |
self ifInteractive:[
|
|
301 |
changes := ChangeSet withAll:(unloadableDefinitions collect:[:e|e asChange]).
|
431
|
302 |
self assert:(changes includes:nil) not.
|
433
|
303 |
confirmedChanges := Tools::ChangeSetBrowser2
|
213
|
304 |
confirmChanges: changes
|
|
305 |
label:'Unsatisfied dependencies. Load anyway?'.
|
433
|
306 |
confirmedChanges notEmpty ifTrue:[
|
|
307 |
confirmedChanges := confirmedChanges flatten.
|
|
308 |
definitions := confirmedChanges collect:[:e|e mcDefinition].
|
|
309 |
self assert:(definitions includes:nil) not.
|
|
310 |
self tryToLoadAll: definitions label: 'Loading unloadables...'.
|
|
311 |
]
|
213
|
312 |
] else:[
|
|
313 |
self tryToLoadAll: unloadableDefinitions label: 'Loading unloadables...'.
|
|
314 |
]
|
|
315 |
|
|
316 |
"Created: / 08-11-2010 / 20:19:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
317 |
"Modified: / 06-03-2011 / 20:36:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
433
|
318 |
"Modified: / 20-08-2011 / 19:31:22 / cg"
|
70
|
319 |
! !
|
|
320 |
|
|
321 |
!MCPackageLoader methodsFor:'public'!
|
|
322 |
|
|
323 |
installSnapshot: aSnapshot
|
|
324 |
| patch |
|
213
|
325 |
patch := aSnapshot patchRelativeToBase: MCSnapshot empty.
|
70
|
326 |
patch applyTo: self.
|
213
|
327 |
|
70
|
328 |
!
|
|
329 |
|
|
330 |
load
|
|
331 |
self analyze.
|
|
332 |
unloadableDefinitions isEmpty ifFalse: [self warnAboutDependencies].
|
|
333 |
self useNewChangeSetDuring: [self basicLoad]
|
|
334 |
!
|
|
335 |
|
|
336 |
loadWithName: baseName
|
|
337 |
self analyze.
|
|
338 |
unloadableDefinitions isEmpty ifFalse: [self warnAboutDependencies].
|
|
339 |
self useChangeSetNamed: baseName during: [self basicLoad]
|
|
340 |
!
|
|
341 |
|
|
342 |
loadWithNameLike: baseName
|
|
343 |
self analyze.
|
|
344 |
unloadableDefinitions isEmpty ifFalse: [self warnAboutDependencies].
|
|
345 |
self useNewChangeSetNamedLike: baseName during: [self basicLoad]
|
|
346 |
!
|
|
347 |
|
|
348 |
unloadPackage: aPackage
|
|
349 |
self updatePackage: aPackage withSnapshot: MCSnapshot empty
|
|
350 |
!
|
|
351 |
|
|
352 |
updatePackage: aPackage withSnapshot: aSnapshot
|
213
|
353 |
| patch packageSnap |
|
|
354 |
MCStXPackageQuery answer: aPackage name do:
|
|
355 |
[packageSnap := aPackage snapshot.
|
|
356 |
patch := aSnapshot patchRelativeToBase: packageSnap.
|
|
357 |
patch applyTo: self.
|
|
358 |
packageSnap definitions do: [:ea | self provisions addAll: ea provisions]]
|
|
359 |
|
|
360 |
"Modified: / 14-09-2010 / 22:09:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
70
|
361 |
! !
|
|
362 |
|
|
363 |
!MCPackageLoader class methodsFor:'documentation'!
|
|
364 |
|
|
365 |
version
|
433
|
366 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCPackageLoader.st,v 1.6 2011-08-20 17:45:39 cg Exp $'
|
213
|
367 |
!
|
|
368 |
|
|
369 |
version_CVS
|
433
|
370 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCPackageLoader.st,v 1.6 2011-08-20 17:45:39 cg Exp $'
|
213
|
371 |
!
|
|
372 |
|
|
373 |
version_SVN
|
|
374 |
^ '§Id: MCPackageLoader.st 27 2011-03-07 03:48:48Z vranyj1 §'
|
70
|
375 |
! !
|