70
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
|
3 |
Object subclass:#MCPackageLoader
|
|
4 |
instanceVariableNames:'requirements unloadableDefinitions obsoletions additions removals
|
|
5 |
errorDefinitions provisions'
|
|
6 |
classVariableNames:''
|
|
7 |
poolDictionaries:''
|
|
8 |
category:'Monticello-Loading'
|
|
9 |
!
|
|
10 |
|
|
11 |
|
|
12 |
!MCPackageLoader class methodsFor:'as yet unclassified'!
|
|
13 |
|
|
14 |
installSnapshot: aSnapshot
|
|
15 |
self new
|
|
16 |
installSnapshot: aSnapshot;
|
|
17 |
load
|
|
18 |
!
|
|
19 |
|
|
20 |
new
|
|
21 |
^ self basicNew initialize
|
|
22 |
!
|
|
23 |
|
|
24 |
unloadPackage: aPackage
|
|
25 |
self new
|
|
26 |
unloadPackage: aPackage;
|
|
27 |
loadWithNameLike: aPackage name, '-unload'
|
|
28 |
!
|
|
29 |
|
|
30 |
updatePackage: aPackage withSnapshot: aSnapshot
|
|
31 |
self new
|
|
32 |
updatePackage: aPackage withSnapshot: aSnapshot;
|
|
33 |
load
|
|
34 |
! !
|
|
35 |
|
|
36 |
!MCPackageLoader methodsFor:'patch ops'!
|
|
37 |
|
|
38 |
addDefinition: aDefinition
|
|
39 |
additions add: aDefinition
|
|
40 |
!
|
|
41 |
|
|
42 |
modifyDefinition: old to: new
|
|
43 |
self addDefinition: new.
|
|
44 |
obsoletions at: new put: old.
|
|
45 |
!
|
|
46 |
|
|
47 |
removeDefinition: aDefinition
|
|
48 |
removals add: aDefinition
|
|
49 |
! !
|
|
50 |
|
|
51 |
!MCPackageLoader methodsFor:'private'!
|
|
52 |
|
|
53 |
analyze
|
|
54 |
| sorter |
|
|
55 |
sorter _ self sorterForItems: additions.
|
|
56 |
additions _ sorter orderedItems.
|
|
57 |
requirements _ sorter externalRequirements.
|
|
58 |
unloadableDefinitions _ sorter itemsWithMissingRequirements asSortedCollection.
|
|
59 |
|
|
60 |
sorter _ self sorterForItems: removals.
|
|
61 |
removals _ sorter orderedItems reversed.
|
|
62 |
!
|
|
63 |
|
|
64 |
basicLoad
|
|
65 |
errorDefinitions _ OrderedCollection new.
|
|
66 |
[[additions do: [:ea | self tryToLoad: ea] displayingProgress: 'Loading...'.
|
|
67 |
removals do: [:ea | ea unload] displayingProgress: 'Cleaning up...'.
|
|
68 |
self shouldWarnAboutErrors ifTrue: [self warnAboutErrors].
|
|
69 |
errorDefinitions do: [:ea | ea loadOver: (self obsoletionFor: ea)] displayingProgress: 'Reloading...'.
|
|
70 |
additions do: [:ea | ea postloadOver: (self obsoletionFor: ea)] displayingProgress: 'Initializing...']
|
|
71 |
on: InMidstOfFileinNotification
|
|
72 |
do: [:n | n resume: true]]
|
|
73 |
ensure: [self flushChangesFile]
|
|
74 |
!
|
|
75 |
|
|
76 |
dependencyWarning
|
|
77 |
^ String streamContents:
|
|
78 |
[:s |
|
|
79 |
s nextPutAll: 'This package depends on the following classes:'; cr.
|
|
80 |
requirements do: [:ea | s space; space; nextPutAll: ea; cr].
|
|
81 |
s nextPutAll: 'You must resolve these dependencies before you will be able to load these definitions: '; cr.
|
|
82 |
unloadableDefinitions do: [:ea | s space; space; nextPutAll: ea summary; cr]]
|
|
83 |
!
|
|
84 |
|
|
85 |
errorDefinitionWarning
|
|
86 |
^ String streamContents:
|
|
87 |
[:s |
|
|
88 |
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.
|
|
89 |
errorDefinitions do: [:ea | s space; space; nextPutAll: ea summary; cr]]
|
|
90 |
!
|
|
91 |
|
|
92 |
flushChangesFile
|
|
93 |
"The changes file is second in the SourceFiles array"
|
|
94 |
|
|
95 |
(SourceFiles at: 2) flush
|
|
96 |
!
|
|
97 |
|
|
98 |
initialize
|
|
99 |
additions _ OrderedCollection new.
|
|
100 |
removals _ OrderedCollection new.
|
|
101 |
obsoletions _ Dictionary new.
|
|
102 |
!
|
|
103 |
|
|
104 |
obsoletionFor: aDefinition
|
|
105 |
^ obsoletions at: aDefinition ifAbsent: [nil]
|
|
106 |
!
|
|
107 |
|
|
108 |
orderDefinitionsForLoading: aCollection
|
|
109 |
^ (self sorterForItems: aCollection) orderedItems
|
|
110 |
!
|
|
111 |
|
|
112 |
orderedAdditions
|
|
113 |
^ additions
|
|
114 |
!
|
|
115 |
|
|
116 |
provisions
|
|
117 |
^ provisions ifNil: [provisions _ Set withAll: Smalltalk keys]
|
|
118 |
!
|
|
119 |
|
|
120 |
shouldWarnAboutErrors
|
|
121 |
^ errorDefinitions isEmpty not and: [false "should make this a preference"]
|
|
122 |
!
|
|
123 |
|
|
124 |
sorterForItems: aCollection
|
|
125 |
| sorter |
|
|
126 |
sorter _ MCDependencySorter items: aCollection.
|
|
127 |
sorter addExternalProvisions: self provisions.
|
|
128 |
^ sorter
|
|
129 |
!
|
|
130 |
|
|
131 |
tryToLoad: aDefinition
|
|
132 |
[aDefinition loadOver: (self obsoletionFor: aDefinition)] on: Error do: [errorDefinitions add: aDefinition].
|
|
133 |
!
|
|
134 |
|
|
135 |
useChangeSetNamed: baseName during: aBlock
|
|
136 |
"Use the named change set, or create one with the given name."
|
|
137 |
| changeHolder oldChanges newChanges |
|
|
138 |
changeHolder _ (ChangeSet respondsTo: #newChanges:)
|
|
139 |
ifTrue: [ChangeSet]
|
|
140 |
ifFalse: [Smalltalk].
|
|
141 |
oldChanges _ (ChangeSet respondsTo: #current)
|
|
142 |
ifTrue: [ChangeSet current]
|
|
143 |
ifFalse: [Smalltalk changes].
|
|
144 |
|
|
145 |
newChanges _ (ChangeSorter changeSetNamed: baseName) ifNil: [ ChangeSet new name: baseName ].
|
|
146 |
changeHolder newChanges: newChanges.
|
|
147 |
[aBlock value] ensure: [changeHolder newChanges: oldChanges].
|
|
148 |
!
|
|
149 |
|
|
150 |
useNewChangeSetDuring: aBlock
|
|
151 |
^self useNewChangeSetNamedLike: 'MC' during: aBlock
|
|
152 |
!
|
|
153 |
|
|
154 |
useNewChangeSetNamedLike: baseName during: aBlock
|
|
155 |
^self useChangeSetNamed: (ChangeSet uniqueNameLike: baseName) during: aBlock
|
|
156 |
!
|
|
157 |
|
|
158 |
warnAboutDependencies
|
|
159 |
self notify: self dependencyWarning
|
|
160 |
!
|
|
161 |
|
|
162 |
warnAboutErrors
|
|
163 |
self notify: self errorDefinitionWarning.
|
|
164 |
! !
|
|
165 |
|
|
166 |
!MCPackageLoader methodsFor:'public'!
|
|
167 |
|
|
168 |
installSnapshot: aSnapshot
|
|
169 |
| patch |
|
|
170 |
patch _ aSnapshot patchRelativeToBase: MCSnapshot empty.
|
|
171 |
patch applyTo: self.
|
|
172 |
!
|
|
173 |
|
|
174 |
load
|
|
175 |
self analyze.
|
|
176 |
unloadableDefinitions isEmpty ifFalse: [self warnAboutDependencies].
|
|
177 |
self useNewChangeSetDuring: [self basicLoad]
|
|
178 |
!
|
|
179 |
|
|
180 |
loadWithName: baseName
|
|
181 |
self analyze.
|
|
182 |
unloadableDefinitions isEmpty ifFalse: [self warnAboutDependencies].
|
|
183 |
self useChangeSetNamed: baseName during: [self basicLoad]
|
|
184 |
!
|
|
185 |
|
|
186 |
loadWithNameLike: baseName
|
|
187 |
self analyze.
|
|
188 |
unloadableDefinitions isEmpty ifFalse: [self warnAboutDependencies].
|
|
189 |
self useNewChangeSetNamedLike: baseName during: [self basicLoad]
|
|
190 |
!
|
|
191 |
|
|
192 |
unloadPackage: aPackage
|
|
193 |
self updatePackage: aPackage withSnapshot: MCSnapshot empty
|
|
194 |
!
|
|
195 |
|
|
196 |
updatePackage: aPackage withSnapshot: aSnapshot
|
|
197 |
| patch packageSnap |
|
|
198 |
packageSnap _ aPackage snapshot.
|
|
199 |
patch _ aSnapshot patchRelativeToBase: packageSnap.
|
|
200 |
patch applyTo: self.
|
|
201 |
packageSnap definitions do: [:ea | self provisions addAll: ea provisions]
|
|
202 |
! !
|
|
203 |
|
|
204 |
!MCPackageLoader class methodsFor:'documentation'!
|
|
205 |
|
|
206 |
version
|
|
207 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCPackageLoader.st,v 1.1 2006-11-22 13:12:56 cg Exp $'
|
|
208 |
! !
|