23 Object subclass:#JavaClassReader |
23 Object subclass:#JavaClassReader |
24 instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
24 instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
25 constSlot classBeingLoaded' |
25 constSlot classBeingLoaded' |
26 classVariableNames:'Verbose AnnotationsVerbose Silent AbsolutelySilent |
26 classVariableNames:'Verbose AnnotationsVerbose Silent AbsolutelySilent |
27 LazyClassLoading InvalidClassFormatSignal ClassLoaderQuerySignal |
27 LazyClassLoading InvalidClassFormatSignal ClassLoaderQuerySignal |
28 JavaArchiveCache MaxContextSize MaxContextSizeLimit' |
28 JavaArchiveCache LastJavaArchive MaxContextSize |
|
29 MaxContextSizeLimit' |
29 poolDictionaries:'JavaConstants' |
30 poolDictionaries:'JavaConstants' |
30 category:'Languages-Java-Support' |
31 category:'Languages-Java-Support' |
31 ! |
32 ! |
32 |
33 |
33 !JavaClassReader class methodsFor:'documentation'! |
34 !JavaClassReader class methodsFor:'documentation'! |
205 "Modified: / 20-10-1998 / 17:24:54 / cg" |
206 "Modified: / 20-10-1998 / 17:24:54 / cg" |
206 "Modified: / 08-09-2011 / 08:10:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
207 "Modified: / 08-09-2011 / 08:10:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
207 "Created: / 30-10-2011 / 12:27:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
208 "Created: / 30-10-2011 / 12:27:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
208 ! |
209 ! |
209 |
210 |
|
211 readClass: clsName from: path ignoring: classesBeingLoaded |
|
212 "load class named clsName from directory or .jar archive path. |
|
213 <clinit> is not called, class is not installed as global" |
|
214 |
|
215 | nm p zar entry zipFile read rslt | |
|
216 |
|
217 p := path asString. |
|
218 p asFilename isDirectory ifTrue: [ |
|
219 (p endsWith: Filename separator) ifFalse: [ |
|
220 p := p , (Filename separator asString) |
|
221 ]. |
|
222 (Array |
|
223 with: clsName |
|
224 with: clsName asLowercase |
|
225 with: clsName asUppercase) |
|
226 do: [:tryName | |
|
227 nm := p , tryName , '.class'. |
|
228 nm asFilename exists ifTrue: [ |
|
229 (Java isExcludedFromClassPath: nm) ifFalse: [ |
|
230 |
|
231 "means we are successfully going to read something :)" |
|
232 rslt := self readFile: nm ignoring: classesBeingLoaded. |
|
233 rslt notNil ifTrue: [ ^ rslt. ]. |
|
234 ] |
|
235 ]. |
|
236 ] |
|
237 ] ifFalse: [ |
|
238 ((zipFile := p asFilename withSuffix: 'jar') exists |
|
239 or: [ (zipFile := p asFilename withSuffix: 'zip') exists ]) |
|
240 ifTrue: [ |
|
241 "/ Do not use at:ifAbsentPut: here, JavaArchiveCache is a CacheDictionary!!!!!! |
|
242 zar := JavaArchiveCache at: zipFile ifAbsent: nil. |
|
243 zar isNil ifTrue:[ |
|
244 JavaVM commonOpenStreamUsing:[ zar := ZipArchive oldFileNamed: zipFile ]. |
|
245 JavaArchiveCache at: zipFile put: zar |
|
246 ]. |
|
247 read := [ |
|
248 nm := clsName , '.class'. |
|
249 |
|
250 (zar isValidPath: nm) ifTrue: [ |
|
251 (Java isExcludedFromClassPath: nm) ifFalse: [ |
|
252 zar reopenForReading. |
|
253 entry := zar extract: nm. |
|
254 zar closeFile. |
|
255 rslt := self readStream: (entry readStream) ignoring: classesBeingLoaded. |
|
256 rslt notNil ifTrue: [ ^ rslt ]. |
|
257 ] |
|
258 ] |
|
259 ]. |
|
260 JavaClassReader invalidClassFormatSignal |
|
261 handle: [ |
|
262 "Kludge, sometimes zar gets corrupted" |
|
263 zar := JavaArchiveCache at: zipFile put: (JavaVM commonOpenStreamUsing: [ZipArchive oldFileNamed: zipFile]). |
|
264 read value |
|
265 ] |
|
266 do: [ read value ]. |
|
267 ] |
|
268 ]. |
|
269 ^nil |
|
270 |
|
271 "Created: / 03-12-2012 / 22:47:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
272 ! |
|
273 |
210 readClass: className ignoring: classesBeingLoadedOrNil |
274 readClass: className ignoring: classesBeingLoadedOrNil |
211 |
275 |
212 "This method is bit hacky, as it tries to supply 'correct' |
276 "This method is bit hacky, as it tries to supply 'correct' |
213 classloader. |
277 classloader. |
214 |
278 |
258 ] ifFalse: [ |
322 ] ifFalse: [ |
259 classesBeingLoaded := classesBeingLoadedOrNil |
323 classesBeingLoaded := classesBeingLoadedOrNil |
260 add: clsName; |
324 add: clsName; |
261 yourself. |
325 yourself. |
262 ]. |
326 ]. |
|
327 |
263 classPath do: [:path | |
328 classPath do: [:path | |
264 | nm p zar entry zipFile read | |
329 rslt := self readClass: clsName from: path ignoring: classesBeingLoaded. |
265 |
330 rslt notNil ifTrue:[ ^rslt ]. |
266 p := path asString. |
331 ]. |
267 p asFilename isDirectory ifTrue: [ |
332 ^nil. |
268 (p endsWith: Filename separator) ifFalse: [ |
|
269 p := p , (Filename separator asString) |
|
270 ]. |
|
271 (Array |
|
272 with: clsName |
|
273 with: clsName asLowercase |
|
274 with: clsName asUppercase) |
|
275 do: [ |
|
276 :tryName | |
|
277 nm := p , tryName , '.class'. |
|
278 nm asFilename exists ifTrue: [ |
|
279 (Java isExcludedFromClassPath: nm) ifFalse: [ |
|
280 |
|
281 "means we are successfully going to read something :)" |
|
282 rslt := self readFile: nm ignoring: classesBeingLoaded. |
|
283 rslt notNil ifTrue: [ ^ rslt. ]. |
|
284 ] |
|
285 ]. |
|
286 ] |
|
287 ] ifFalse: [ |
|
288 ((zipFile := p asFilename withSuffix: 'jar') exists |
|
289 or: [ (zipFile := p asFilename withSuffix: 'zip') exists ]) |
|
290 ifTrue: [ |
|
291 "/ Do not use at:ifAbsentPut: here, JavaArchiveCache is a CacheDictionary!!!!!! |
|
292 zar := JavaArchiveCache at: zipFile ifAbsent: nil. |
|
293 zar isNil ifTrue:[ |
|
294 JavaVM commonOpenStreamUsing:[ zar := ZipArchive oldFileNamed: zipFile ]. |
|
295 JavaArchiveCache at: zipFile put: zar |
|
296 ]. |
|
297 read := [ |
|
298 nm := clsName , '.class'. |
|
299 entry := zar extract: nm. |
|
300 entry notNil ifTrue: [ |
|
301 (Java isExcludedFromClassPath: nm) ifFalse: [ |
|
302 rslt := self readStream: (entry readStream) ignoring: classesBeingLoaded. |
|
303 rslt notNil ifTrue: [ ^ rslt ]. |
|
304 ] |
|
305 ] |
|
306 ]. |
|
307 JavaClassReader invalidClassFormatSignal |
|
308 handle: [ |
|
309 "Kludge, sometimes zar gets corrupted" |
|
310 zar := JavaArchiveCache at: zipFile put: (JavaVM commonOpenStreamUsing: [ZipArchive oldFileNamed: zipFile]). |
|
311 read value |
|
312 ] |
|
313 do: [ read value ]. |
|
314 ] |
|
315 ] |
|
316 ]. |
|
317 ^nil |
|
318 |
333 |
319 "Created: / 15-04-1996 / 14:58:53 / cg" |
334 "Created: / 15-04-1996 / 14:58:53 / cg" |
320 "Modified: / 20-10-1998 / 17:24:54 / cg" |
335 "Modified: / 20-10-1998 / 17:24:54 / cg" |
321 "Created: / 23-10-2011 / 21:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
336 "Created: / 23-10-2011 / 21:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
322 "Modified: / 03-11-2011 / 18:14:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
337 "Modified: / 03-11-2011 / 18:14:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
323 "Modified: / 14-08-2012 / 02:17:59 / jv" |
338 "Modified: / 14-08-2012 / 02:17:59 / jv" |
324 "Modified: / 14-08-2012 / 21:44:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
339 "Modified: / 03-12-2012 / 22:50:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
325 ! |
340 ! |
326 |
341 |
327 readFile:aFilename ignoring:classesBeingLoaded |
342 readFile:aFilename ignoring:classesBeingLoaded |
328 "reads a class from aFilename and returns it. |
343 "reads a class from aFilename and returns it. |
329 The JavaClass is NOT installed as global and unresolved |
344 The JavaClass is NOT installed as global and unresolved |