author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 29 Jan 2012 12:51:41 +0000 | |
branch | jv |
changeset 3011 | 1997ff6e7e55 |
parent 1445 | b8cc2792ab97 |
permissions | -rw-r--r-- |
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 |
||
1230 | 13 |
"{ Package: 'stx:libbasic3' }" |
14 |
||
15 |
"{ NameSpace: Packages }" |
|
16 |
||
17 |
Object subclass:#StxPackageFileReader |
|
18 |
instanceVariableNames:'handler stream' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
category:'Package-Handlers' |
|
22 |
! |
|
23 |
||
24 |
Object subclass:#Version1 |
|
25 |
instanceVariableNames:'filename package' |
|
26 |
classVariableNames:'' |
|
27 |
poolDictionaries:'' |
|
28 |
privateIn:StxPackageFileReader |
|
29 |
! |
|
30 |
||
1445 | 31 |
!StxPackageFileReader class methodsFor:'documentation'! |
32 |
||
33 |
copyright |
|
34 |
" |
|
35 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
36 |
All Rights Reserved |
|
37 |
||
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
! ! |
|
1230 | 46 |
|
47 |
!StxPackageFileReader class methodsFor:'instance creation'! |
|
48 |
||
49 |
forFilename:aFilename |
|
50 |
||
51 |
(self isFileVersion1:aFilename) ifTrue:[ |
|
52 |
^ Version1 forFilename:aFilename |
|
53 |
]. |
|
54 |
||
55 |
self error:'File type unknown' |
|
56 |
! |
|
57 |
||
58 |
forPackage:aPackage |
|
59 |
||
60 |
^ (self version:1) forPackage:aPackage |
|
61 |
! |
|
62 |
||
63 |
version:aVersionNumber |
|
64 |
||
65 |
aVersionNumber == 1 ifTrue:[ |
|
66 |
^ Version1. |
|
67 |
]. |
|
68 |
self error:'Version unknown' |
|
69 |
! ! |
|
70 |
||
71 |
!StxPackageFileReader class methodsFor:'queries'! |
|
72 |
||
73 |
isFileBase:aFilename |
|
74 |
^ false |
|
75 |
! |
|
76 |
||
77 |
isFileVersion1:aFilename |
|
78 |
^ true |
|
79 |
! ! |
|
80 |
||
81 |
!StxPackageFileReader::Version1 class methodsFor:'globals'! |
|
82 |
||
83 |
smalltalkPackageManager |
|
84 |
^ PackageManager smalltalkPackageManager |
|
85 |
! ! |
|
86 |
||
87 |
!StxPackageFileReader::Version1 class methodsFor:'instance creation'! |
|
88 |
||
89 |
forFilename:aPackage |
|
90 |
^ self basicNew filename:aPackage |
|
91 |
! ! |
|
92 |
||
93 |
!StxPackageFileReader::Version1 methodsFor:'accessing'! |
|
94 |
||
95 |
filename |
|
96 |
"return the value of the instance variable 'filename' (automatically generated)" |
|
97 |
||
98 |
^ filename |
|
99 |
! |
|
100 |
||
101 |
filename:something |
|
102 |
"set the value of the instance variable 'filename' (automatically generated)" |
|
103 |
||
104 |
filename := something. |
|
105 |
! |
|
106 |
||
107 |
package |
|
108 |
"return the value of the instance variable 'package' (automatically generated)" |
|
109 |
||
110 |
^ package |
|
111 |
! |
|
112 |
||
113 |
package:something |
|
114 |
"set the value of the instance variable 'package' (automatically generated)" |
|
115 |
||
116 |
package := something. |
|
117 |
! ! |
|
118 |
||
119 |
!StxPackageFileReader::Version1 methodsFor:'api'! |
|
120 |
||
121 |
fileInFrom:aStream notifying:someone passChunk:passChunk single:single silent:beSilent |
|
122 |
"sent by a file browser or something similar" |
|
123 |
| packageManager | |
|
124 |
||
125 |
packageManager := PackageManager smalltalkPackageManager. |
|
126 |
packageManager ifNil:[ |
|
127 |
self error: 'Error during fileIn'. |
|
128 |
^ self. |
|
129 |
]. |
|
130 |
||
131 |
package := (self getInitialPackageFromChunk:aStream nextChunk). |
|
132 |
package ifNil:[ |
|
133 |
self error: 'Error during fileIn'. |
|
134 |
^ self. |
|
135 |
]. |
|
136 |
||
137 |
self package:package. |
|
138 |
self |
|
139 |
basicInstallPackage:package |
|
140 |
fromStream:aStream |
|
141 |
in:self class smalltalkPackageManager. |
|
142 |
||
143 |
packageManager addPackage:package. |
|
144 |
! |
|
145 |
||
146 |
installPackageIn:aPackageManager |
|
147 |
(self checkOkToInstall:package). "/ may produce errors |
|
148 |
self basicInstallPackage:package in:aPackageManager. |
|
149 |
^ package |
|
150 |
! |
|
151 |
||
152 |
loadPackageIn:aPackageManager |
|
153 |
||
154 |
|aStream aPackage| |
|
155 |
self canReadFilename:filename. |
|
156 |
||
157 |
[ |
|
158 |
aStream := filename readStream. |
|
159 |
aStream nextChunk. |
|
160 |
aStream nextChunk. |
|
161 |
aPackage := self getInitialPackageFromChunk:aStream nextChunk. |
|
162 |
] ensure:[aStream close]. |
|
163 |
||
164 |
self filename:filename. |
|
165 |
aPackageManager addPackage:aPackage. |
|
166 |
self package:aPackage. |
|
167 |
aPackage packageHandler:self. |
|
168 |
aPackage initializeLoaded. |
|
169 |
^ aPackage |
|
170 |
! ! |
|
171 |
||
172 |
!StxPackageFileReader::Version1 methodsFor:'checks'! |
|
173 |
||
174 |
canReadFilename:aFilename |
|
175 |
||
176 |
aFilename isFilename ifFalse:[ |
|
177 |
^ self error:aFilename printString, ' is not a filename so cannot be written to.'. |
|
178 |
]. |
|
179 |
||
180 |
aFilename directory exists ifFalse:[ |
|
181 |
^ self error:aFilename directory printString, ' directory does not exist.'. |
|
182 |
]. |
|
183 |
||
184 |
aFilename exists ifFalse:[ |
|
185 |
^ self error:aFilename printString, ' file does not exist'. |
|
186 |
]. |
|
187 |
||
188 |
(aFilename isDirectory not) ifFalse:[ |
|
189 |
^ self error:aFilename printString, ' is a directory and cannot be read'. |
|
190 |
]. |
|
191 |
! |
|
192 |
||
193 |
checkOkToInstall:aPackage |
|
194 |
"check that aPackage is ok to install. Look for incompatibilities" |
|
195 |
||
196 |
self canReadFilename:filename |
|
197 |
! ! |
|
198 |
||
199 |
!StxPackageFileReader::Version1 methodsFor:'helpers'! |
|
200 |
||
201 |
applyChange:aChange fromPackage:aPackage |
|
202 |
"apply change and make sure created objects are associated |
|
203 |
with package" |
|
204 |
||
205 |
| aMethod | |
|
206 |
aChange isMethodChange ifTrue:[ |
|
207 |
aChange apply. |
|
208 |
"/ aMethod := ChangesHelper getCurrentMethodFromMethodChange:aChange. |
|
209 |
aMethod := aChange changeMethod. |
|
210 |
aMethod ifNil:[ |
|
211 |
self error:'Error during fileIn'. |
|
212 |
^ self. |
|
213 |
]. |
|
214 |
||
215 |
aMethod setPackage:aPackage name. |
|
216 |
^ self |
|
217 |
]. |
|
218 |
||
219 |
aChange apply |
|
220 |
! |
|
221 |
||
222 |
createPackagePath |
|
223 |
" create the path name for the filename if it does not already exist" |
|
224 |
^ self createPathFor:package filename |
|
225 |
! |
|
226 |
||
227 |
createPathFor:aFilename |
|
228 |
" create the path name for the filename if it does not already exist" |
|
229 |
^ aFilename directory makeDirectory. |
|
230 |
! |
|
231 |
||
232 |
openReadStreamStreamOn:aFilename andDo:aOneArgBlockWithAnExpectedStream |
|
233 |
| aStream | |
|
234 |
[ |
|
235 |
aStream := aFilename readStream. |
|
236 |
aOneArgBlockWithAnExpectedStream value:aStream |
|
237 |
] ensure:[ |
|
238 |
aStream close |
|
239 |
] |
|
240 |
||
241 |
! ! |
|
242 |
||
243 |
!StxPackageFileReader::Version1 methodsFor:'installation / uninstallation'! |
|
244 |
||
245 |
basicInstallPackage:aPackage fromStream:aStream in:aPackageManager |
|
246 |
"install a package" |
|
247 |
| changeSet | |
|
248 |
aPackage prerequisites evaluate. |
|
249 |
aPackage preInstallScript evaluate. |
|
250 |
||
251 |
changeSet := ChangeSet fromStream:aStream. |
|
252 |
changeSet do:[:aChange | |
|
253 |
self applyChange:aChange fromPackage:aPackage. |
|
254 |
]. |
|
255 |
self validateInstallation. "/ may produce errors |
|
256 |
aPackage initializeInstalled. |
|
257 |
||
258 |
"/ aPackage isInstalled:true. |
|
259 |
aPackage postInstallScript evaluate. |
|
260 |
! |
|
261 |
||
262 |
basicInstallPackage:aPackage in:aPackageManager |
|
263 |
"install a package" |
|
264 |
||
265 |
self openReadStreamStreamOn:aPackage filename andDo:[:aStream | |
|
266 |
self skipPackageHeaderFrom:aStream. |
|
267 |
"/ aStream nextChunk |
|
268 |
self basicInstallPackage:aPackage fromStream:aStream in:aPackageManager |
|
269 |
]. |
|
270 |
! |
|
271 |
||
272 |
skipPackageHeaderFrom:aReadStream |
|
273 |
aReadStream nextChunk. "/ nothing |
|
274 |
aReadStream nextChunk. "/ script for creating the receiver |
|
275 |
aReadStream nextChunk. "/ the package header |
|
276 |
! ! |
|
277 |
||
278 |
!StxPackageFileReader::Version1 methodsFor:'loading'! |
|
279 |
||
280 |
loadFromStream:aStream |
|
281 |
aStream nextChunk. |
|
282 |
aStream nextChunk. "/ anEmpty string |
|
283 |
package := self getInitialPackageFromChunk:aStream nextChunk. "/ the receiver representation |
|
284 |
package filename:filename. |
|
285 |
^ package |
|
286 |
! ! |
|
287 |
||
288 |
!StxPackageFileReader::Version1 methodsFor:'stream messages'! |
|
289 |
||
290 |
getChangeSetFrom:aStream |
|
291 |
^ ChangeSet fromStream:aStream |
|
292 |
! |
|
293 |
||
294 |
getInitialPackageFrom:aStream |
|
295 |
|nextChunk| |
|
296 |
||
297 |
nextChunk := aStream nextChunk. |
|
298 |
Class nameSpaceQuerySignal |
|
299 |
answer:Packages |
|
300 |
do:[ |
|
301 |
^ (Compiler evaluate:nextChunk) |
|
302 |
] |
|
303 |
! |
|
304 |
||
305 |
getInitialPackageFromChangeSet:aChangeSet |
|
306 |
|nextChunk| |
|
307 |
||
308 |
nextChunk := aChangeSet first source. |
|
309 |
Class nameSpaceQuerySignal |
|
310 |
answer:Packages |
|
311 |
do:[ |
|
312 |
^ (Compiler evaluate:nextChunk) |
|
313 |
] |
|
314 |
! |
|
315 |
||
316 |
getInitialPackageFromChunk:aChunk |
|
317 |
||
318 |
Class nameSpaceQuerySignal |
|
319 |
answer:Packages |
|
320 |
do:[ |
|
321 |
^ (Compiler evaluate:aChunk) |
|
322 |
] |
|
323 |
! ! |
|
324 |
||
325 |
!StxPackageFileReader::Version1 methodsFor:'validation'! |
|
326 |
||
327 |
validateAllClassesAreInImage |
|
328 |
||
329 |
#toDo |
|
330 |
! |
|
331 |
||
332 |
validateAllMethodsAreInImage |
|
333 |
#toDo |
|
334 |
! |
|
335 |
||
336 |
validateInstallation |
|
337 |
self validateAllClassesAreInImage. |
|
338 |
self validateAllMethodsAreInImage. |
|
339 |
! ! |
|
340 |
||
341 |
!StxPackageFileReader class methodsFor:'documentation'! |
|
342 |
||
343 |
version |
|
3011
1997ff6e7e55
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1445
diff
changeset
|
344 |
^ '$Header: /var/local/cvs/stx/libbasic3/packages/StxPackageFileReader.st,v 1.2 2006-01-10 09:32:03 cg Exp $' |
1230 | 345 |
! ! |