752
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 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 |
"{ Package: 'stx:libjava' }"
|
|
13 |
|
|
14 |
Object subclass:#Java
|
|
15 |
instanceVariableNames:''
|
|
16 |
classVariableNames:'Classes UnresolvedClassRefs Release ClassPath SourceDirectories
|
|
17 |
JavaHome InternedStrings Java_lang_String Java_lang_Class
|
|
18 |
PrettyPrintStyle LastArgumentString Threads ExcludedClassPath
|
|
19 |
FailedToLoadClasses SourceCache SourceArchiveCache'
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Languages-Java-Support'
|
|
22 |
!
|
|
23 |
|
|
24 |
!Java class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
This software is furnished under a license and may be used
|
|
32 |
only in accordance with the terms of that license and with the
|
|
33 |
inclusion of the above copyright notice. This software may not
|
|
34 |
be provided or otherwise made available to, or used by, any
|
|
35 |
other person. No title to or ownership of the software is
|
|
36 |
hereby transferred.
|
|
37 |
"
|
|
38 |
|
|
39 |
|
|
40 |
!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"Java class is main entry point or - you might say -
|
|
44 |
facade to the Java world inside Smalltalk. It also
|
|
45 |
serves as configuration entity - e.g. controlling
|
|
46 |
classpath, source paths, etc. Java class is responsible
|
|
47 |
for correct initialization and glueing other classes.
|
|
48 |
"
|
|
49 |
! !
|
|
50 |
|
|
51 |
!Java class methodsFor:'accessing'!
|
|
52 |
|
|
53 |
classForName:aString
|
|
54 |
"return a javaClass - either existing or loaded"
|
|
55 |
|
|
56 |
|cls loader classURL|
|
|
57 |
|
|
58 |
cls := self at:aString.
|
|
59 |
cls isNil ifTrue:[
|
|
60 |
FailedToLoadClasses notNil ifTrue:[
|
|
61 |
(FailedToLoadClasses includes:aString) ifTrue:[
|
|
62 |
"/ ('JAVA [info]: class loading already failed: ' , aString) infoPrintCR.
|
|
63 |
^ nil
|
|
64 |
]
|
|
65 |
].
|
|
66 |
|
|
67 |
('JAVA [info]: late class loading: ' , aString) infoPrintCR.
|
|
68 |
loader := JavaClassReader classLoaderQuerySignal query.
|
|
69 |
loader isNil ifTrue:[
|
|
70 |
"/ load using default (ST/X) loader
|
|
71 |
cls := JavaClassReader loadClass:aString.
|
|
72 |
] ifFalse:[
|
|
73 |
"/ load using a Java class loader
|
|
74 |
"/ classURL := Java as_URL:('file:' , aString , '.class').
|
|
75 |
"/ loader loadClass:classURL.
|
|
76 |
loader perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;'
|
|
77 |
with:(Java as_String:aString).
|
|
78 |
|
|
79 |
cls := self at:aString.
|
|
80 |
].
|
|
81 |
cls isNil ifTrue:[
|
|
82 |
FailedToLoadClasses isNil ifTrue:[
|
|
83 |
FailedToLoadClasses := Set new.
|
|
84 |
].
|
|
85 |
FailedToLoadClasses add:aString
|
|
86 |
]
|
|
87 |
].
|
|
88 |
^ cls
|
|
89 |
|
|
90 |
"Created: / 18.3.1997 / 16:45:57 / cg"
|
|
91 |
"Modified: / 27.4.1998 / 15:00:52 / cg"
|
|
92 |
!
|
|
93 |
|
|
94 |
classNamed:aString
|
|
95 |
^ self at:aString
|
|
96 |
!
|
|
97 |
|
|
98 |
intern:aJavaString
|
|
99 |
|stString internedString|
|
|
100 |
|
|
101 |
stString := self as_ST_String:aJavaString.
|
|
102 |
internedString := InternedStrings at:stString ifAbsent:nil.
|
|
103 |
internedString isNil ifTrue:[
|
|
104 |
InternedStrings at:stString put:aJavaString.
|
|
105 |
internedString := aJavaString
|
|
106 |
].
|
|
107 |
^ internedString
|
|
108 |
!
|
|
109 |
|
|
110 |
java_lang_Class
|
|
111 |
Java_lang_Class isNil ifTrue:[
|
|
112 |
Java_lang_Class := self at:'java.lang.Class'
|
|
113 |
].
|
|
114 |
^ Java_lang_Class
|
|
115 |
|
|
116 |
"Created: 26.3.1997 / 13:42:59 / cg"
|
|
117 |
"Modified: 26.3.1997 / 13:46:24 / cg"
|
|
118 |
!
|
|
119 |
|
|
120 |
java_lang_String
|
|
121 |
Java_lang_String isNil ifTrue:[
|
|
122 |
Java_lang_String := self at:'java.lang.String'
|
|
123 |
].
|
|
124 |
^ Java_lang_String
|
|
125 |
|
|
126 |
"Created: 26.3.1997 / 13:43:17 / cg"
|
|
127 |
"Modified: 26.3.1997 / 13:50:21 / cg"
|
|
128 |
!
|
|
129 |
|
|
130 |
prettyPrintStyle
|
|
131 |
^ PrettyPrintStyle
|
|
132 |
|
|
133 |
"Created: 1.8.1997 / 10:37:57 / cg"
|
|
134 |
!
|
|
135 |
|
|
136 |
release
|
|
137 |
|
|
138 |
^Release
|
|
139 |
|
|
140 |
"Created: / 22-11-2010 / 12:38:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
141 |
!
|
|
142 |
|
|
143 |
release: aJavaRelease
|
|
144 |
|
|
145 |
Release := aJavaRelease.
|
|
146 |
|
|
147 |
"
|
|
148 |
Java release: JavaRelease openJDK6.
|
|
149 |
Java release: JavaRelease sunJDK6.
|
|
150 |
|
|
151 |
"
|
|
152 |
|
|
153 |
"Created: / 22-11-2010 / 12:38:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
154 |
"Modified: / 30-11-2010 / 11:54:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
155 |
!
|
|
156 |
|
|
157 |
systemPropertyAt:key put:something
|
|
158 |
JavaVM systemProperties at:key put:something
|
|
159 |
|
|
160 |
"Created: / 9.1.1999 / 14:49:35 / cg"
|
|
161 |
!
|
|
162 |
|
|
163 |
threads
|
|
164 |
Threads isNil ifTrue:[
|
|
165 |
Threads := WeakIdentityDictionary new.
|
|
166 |
].
|
|
167 |
^ Threads
|
|
168 |
|
|
169 |
"Created: 26.8.1997 / 19:53:57 / cg"
|
|
170 |
"Modified: 26.8.1997 / 19:55:27 / cg"
|
|
171 |
! !
|
|
172 |
|
|
173 |
!Java class methodsFor:'accessing paths'!
|
|
174 |
|
|
175 |
addToClassPath:aPath
|
|
176 |
|
|
177 |
| path |
|
|
178 |
path := aPath asFilename.
|
|
179 |
|
|
180 |
(aPath asString includes: $*) ifTrue:[
|
|
181 |
self addToClassPathFilesMatching: path baseName
|
|
182 |
in: path directoryName.
|
|
183 |
] ifFalse:[
|
|
184 |
(ClassPath includes:aPath asString) ifFalse:[
|
|
185 |
ClassPath add:aPath asString.
|
|
186 |
FailedToLoadClasses := nil
|
|
187 |
]
|
|
188 |
]
|
|
189 |
|
|
190 |
"Created: / 01-08-1997 / 21:10:07 / cg"
|
|
191 |
"Modified: / 17-09-1998 / 20:43:55 / cg"
|
|
192 |
"Modified: / 20-12-2010 / 17:37:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
193 |
!
|
|
194 |
|
|
195 |
addToClassPathFilesMatching: pattern in: path
|
|
196 |
|
|
197 |
| dir |
|
|
198 |
dir := path asFilename.
|
|
199 |
dir directoryContents do:
|
|
200 |
[:fname|
|
|
201 |
(fname matches: pattern) ifTrue:
|
|
202 |
[| p |
|
|
203 |
p := (dir / fname) pathName.
|
|
204 |
(ClassPath includes:p) ifFalse:
|
|
205 |
[ClassPath add:p.
|
|
206 |
FailedToLoadClasses := nil]]].
|
|
207 |
|
|
208 |
"Created: / 20-12-2010 / 17:26:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
209 |
!
|
|
210 |
|
|
211 |
addToSourcePath:aPath
|
|
212 |
SourceDirectories ifNil:[SourceDirectories := OrderedCollection new].
|
|
213 |
(SourceDirectories includes:aPath) ifFalse:[
|
|
214 |
SourceDirectories add:aPath
|
|
215 |
]
|
|
216 |
|
|
217 |
"Created: / 02-08-1997 / 14:12:31 / cg"
|
|
218 |
"Modified: / 06-02-2011 / 22:51:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
219 |
!
|
|
220 |
|
754
|
221 |
cacheDirectory
|
|
222 |
|
|
223 |
^Filename homeDirectory / '.smalltalk' / 'libjava'
|
|
224 |
|
|
225 |
"Created: / 08-04-2011 / 15:02:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
226 |
!
|
|
227 |
|
752
|
228 |
classPath
|
|
229 |
^ ClassPath
|
|
230 |
|
|
231 |
"Created: 7.2.1997 / 19:23:45 / cg"
|
|
232 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
233 |
!
|
|
234 |
|
|
235 |
classPath:aCollectionOfPaths
|
|
236 |
ClassPath := aCollectionOfPaths asOrderedCollection.
|
|
237 |
FailedToLoadClasses := nil
|
|
238 |
|
|
239 |
"Created: / 7.2.1997 / 19:23:45 / cg"
|
|
240 |
"Modified: / 17.9.1998 / 20:44:09 / cg"
|
|
241 |
!
|
|
242 |
|
|
243 |
effectiveClassPath
|
|
244 |
|
|
245 |
| CLASSPATH |
|
|
246 |
CLASSPATH := ((OperatingSystem getEnvironment: 'CLASSPATH') ? '')
|
|
247 |
tokensBasedOn: OperatingSystem pathSeparator.
|
|
248 |
|
|
249 |
^
|
|
250 |
"for testing only"
|
|
251 |
Release classPath,
|
|
252 |
(Array
|
|
253 |
with: ((Smalltalk packageDirectoryForPackageId:'stx:libjava') / 'java' / 'libjava-projects' / 'Conversion' / 'bin' ) pathName
|
|
254 |
with: ((Smalltalk packageDirectoryForPackageId:'stx:libjava') / 'java' / 'libjava-support' / 'bin' ) pathName
|
|
255 |
),
|
|
256 |
|
|
257 |
(ClassPath ? #()),
|
|
258 |
CLASSPATH
|
|
259 |
|
|
260 |
"
|
|
261 |
Java effectiveClassPath
|
|
262 |
"
|
|
263 |
|
|
264 |
"Created: / 22-11-2010 / 13:03:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
265 |
"Modified: / 17-01-2011 / 09:44:16 / kursjan <kursjan@fit.cvut.cz>"
|
|
266 |
"Modified: / 17-03-2011 / 13:33:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
267 |
!
|
|
268 |
|
|
269 |
effectiveSourceDirectories
|
|
270 |
|
|
271 |
^Release sourcePath ,
|
|
272 |
(SourceDirectories ? #())
|
|
273 |
|
|
274 |
"
|
|
275 |
Java effectiveSourceDirectories
|
|
276 |
"
|
|
277 |
|
|
278 |
"Created: / 30-11-2010 / 11:53:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
279 |
!
|
|
280 |
|
|
281 |
excludedClassPath
|
|
282 |
^ ExcludedClassPath
|
|
283 |
|
|
284 |
"Modified: / 7.2.1997 / 19:23:55 / cg"
|
|
285 |
"Created: / 27.1.1998 / 21:57:13 / cg"
|
|
286 |
!
|
|
287 |
|
|
288 |
isExcludedFromClassPath:fileName
|
|
289 |
|nm|
|
|
290 |
|
|
291 |
nm := fileName asFilename pathName.
|
|
292 |
ExcludedClassPath do:[:excludedPath |
|
|
293 |
(nm startsWith:excludedPath) ifTrue:[^ true].
|
|
294 |
].
|
|
295 |
^ false
|
|
296 |
|
|
297 |
"Created: / 27.1.1998 / 22:00:40 / cg"
|
|
298 |
!
|
|
299 |
|
|
300 |
javaHome
|
|
301 |
^ JavaHome ifNil:[Release javaHome]
|
|
302 |
|
|
303 |
"Created: / 06-08-1997 / 00:53:19 / cg"
|
|
304 |
"Modified: / 22-11-2010 / 12:39:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
305 |
!
|
|
306 |
|
|
307 |
javaHome:aPath
|
|
308 |
|
|
309 |
<resource: #obsolete>
|
|
310 |
|
|
311 |
self obsoleteMethodWarning: 'javaHome is now controlled by java release'.
|
|
312 |
|
|
313 |
JavaHome := aPath
|
|
314 |
|
|
315 |
"Created: / 06-08-1997 / 00:53:23 / cg"
|
|
316 |
"Modified: / 22-11-2010 / 12:40:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
317 |
!
|
|
318 |
|
|
319 |
newJavaHome:newJavaHome
|
|
320 |
self javaHome:newJavaHome.
|
|
321 |
|
|
322 |
!
|
|
323 |
|
|
324 |
removeFromClassPath:aPath
|
|
325 |
(ClassPath includes:aPath) ifTrue:[
|
|
326 |
ClassPath remove:aPath
|
|
327 |
]
|
|
328 |
|
|
329 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
330 |
"Created: 1.8.1997 / 21:10:21 / cg"
|
|
331 |
!
|
|
332 |
|
|
333 |
removeFromSourcePath:aPath
|
|
334 |
(SourceDirectories includes:aPath) ifTrue:[
|
|
335 |
SourceDirectories remove:aPath
|
|
336 |
]
|
|
337 |
|
|
338 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
339 |
"Created: 2.8.1997 / 14:13:01 / cg"
|
|
340 |
!
|
|
341 |
|
|
342 |
sourceDirectories
|
|
343 |
^ SourceDirectories
|
|
344 |
!
|
|
345 |
|
|
346 |
sourceDirectories:aCollectionOfPaths
|
|
347 |
SourceDirectories := aCollectionOfPaths asOrderedCollection
|
|
348 |
|
|
349 |
"
|
|
350 |
Java
|
|
351 |
sourceDirectories:#(
|
|
352 |
'/phys/ibm3/java/src'
|
|
353 |
)
|
|
354 |
"
|
|
355 |
|
|
356 |
|
|
357 |
!
|
|
358 |
|
|
359 |
sourcePath
|
|
360 |
^ SourceDirectories
|
|
361 |
|
|
362 |
"Created: / 16.1.1998 / 13:26:55 / cg"
|
|
363 |
! !
|
|
364 |
|
|
365 |
!Java class methodsFor:'change & update'!
|
|
366 |
|
|
367 |
update: what with: param from: sender
|
|
368 |
|
|
369 |
what == #restarted ifTrue:[
|
|
370 |
self reinitialize.
|
|
371 |
]
|
|
372 |
|
|
373 |
"Created: / 14-12-2010 / 21:00:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
374 |
! !
|
|
375 |
|
|
376 |
!Java class methodsFor:'class initialization'!
|
|
377 |
|
|
378 |
initAllClasses
|
|
379 |
|system|
|
|
380 |
|
|
381 |
FailedToLoadClasses := nil.
|
|
382 |
self initAllStaticFields.
|
|
383 |
|
|
384 |
system := self classForName:'java.lang.System'.
|
|
385 |
system isInitialized ifFalse:[
|
|
386 |
self initSystemClass.
|
|
387 |
].
|
|
388 |
|
|
389 |
self allClassesDo:[:cls |
|
|
390 |
cls isInitialized ifFalse:[
|
|
391 |
cls classInit
|
|
392 |
]
|
|
393 |
]
|
|
394 |
|
|
395 |
"
|
|
396 |
Java initAllClasses
|
|
397 |
"
|
|
398 |
|
|
399 |
"Modified: / 27.11.1998 / 00:33:05 / cg"
|
|
400 |
!
|
|
401 |
|
|
402 |
initAllStaticFields
|
|
403 |
self allClassesDo:[:cls |
|
|
404 |
cls initializeStaticFields
|
|
405 |
]
|
|
406 |
|
|
407 |
!
|
|
408 |
|
|
409 |
initSystemClass
|
|
410 |
|system|
|
|
411 |
|
|
412 |
system := Java at:'java.lang.System'.
|
|
413 |
system isNil ifTrue:[
|
|
414 |
"/ JavaVM initializeVM.
|
|
415 |
"/ system := Java at:'java.lang.System'.
|
|
416 |
"/ system isNil ifTrue:[
|
|
417 |
self warn:'JavaVM: no ''' , 'java.lang.System' allBold , ''' class.'.
|
|
418 |
"/ self error:'no ''java.lang.System'' class'.
|
|
419 |
^ self
|
|
420 |
"/ ].
|
|
421 |
].
|
|
422 |
|
|
423 |
system classInit.
|
|
424 |
(system implements:#'initializeSystemClass()V') ifTrue:[
|
|
425 |
system perform: "invokeStatic:" #'initializeSystemClass()V'.
|
|
426 |
].
|
|
427 |
|
|
428 |
"
|
|
429 |
Java initSystemClass
|
|
430 |
|
|
431 |
(Java at:'java.lang.System')
|
|
432 |
perform:#'getProperty(Ljava/lang/String;)Ljava/lang/String;'
|
|
433 |
with:(Java as_String:'java.home')
|
|
434 |
"
|
|
435 |
|
|
436 |
"Modified: / 10.11.1998 / 12:39:58 / cg"
|
|
437 |
!
|
|
438 |
|
|
439 |
initialize
|
|
440 |
JavaNativeMethod flushAllCachedNativeMethods.
|
|
441 |
|
|
442 |
InternedStrings := Dictionary new.
|
|
443 |
FailedToLoadClasses := nil.
|
|
444 |
|
|
445 |
ClassPath := OrderedCollection new.
|
|
446 |
ExcludedClassPath := OrderedCollection new.
|
|
447 |
|
|
448 |
SourceCache := CacheDictionary new: 32.
|
|
449 |
SourceArchiveCache := CacheDictionary new: 32.
|
|
450 |
|
|
451 |
self initializeRelease. "lazy initialization of Release"
|
|
452 |
|
|
453 |
self initializePrettyPrintStyle.
|
|
454 |
|
|
455 |
ObjectMemory addDependent: self.
|
|
456 |
|
|
457 |
"
|
|
458 |
Java flushAllJavaResources.
|
|
459 |
Java initialize.
|
|
460 |
JavaVM initializeVM
|
|
461 |
Java classPath inspect
|
|
462 |
"
|
|
463 |
|
|
464 |
"Modified: / 06-11-2001 / 09:24:12 / cg"
|
|
465 |
"Created: / 03-10-2010 / 15:54:02 / Jan Kurs <kurs.jan@post.cz>"
|
|
466 |
"Modified: / 15-10-2010 / 17:37:20 / Jan Kurs <kurs.jan@post.cz>"
|
|
467 |
"Modified: / 10-02-2011 / 23:08:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
468 |
!
|
|
469 |
|
|
470 |
initializeForNewClassPath:directoriesToSearch
|
|
471 |
|jClasses jHome jSources|
|
|
472 |
|
|
473 |
jClasses := OrderedCollection new.
|
|
474 |
|
|
475 |
directoriesToSearch do:[:aPath |
|
|
476 |
|dir libDir toAdd|
|
|
477 |
|
|
478 |
dir := aPath asFilename.
|
|
479 |
(jHome isNil and:[dir exists]) ifTrue:[
|
|
480 |
((dir hasSuffix:'jar')
|
|
481 |
or:[dir hasSuffix:'zip']) ifTrue:[
|
|
482 |
toAdd := dir pathName.
|
|
483 |
] ifFalse:[
|
|
484 |
|
|
485 |
"/ there must be either a classes directory,
|
|
486 |
"/ or a classes.zip file ...
|
|
487 |
(libDir := dir construct:'lib') exists ifTrue:[
|
|
488 |
((libDir construct:'classes') exists
|
|
489 |
and:[(libDir construct:'classes') isDirectory]) ifTrue:[
|
|
490 |
jHome := aPath.
|
|
491 |
toAdd := (libDir constructString:'classes').
|
|
492 |
] ifFalse:[
|
|
493 |
(libDir construct:'classes.zip') exists ifTrue:[
|
|
494 |
jHome := aPath.
|
|
495 |
toAdd := (libDir constructString:'classes.zip').
|
|
496 |
] ifFalse:[
|
|
497 |
(libDir construct:'rt.jar') exists ifTrue:[
|
|
498 |
jHome := aPath.
|
|
499 |
toAdd := (libDir constructString:'rt.jar').
|
|
500 |
].
|
|
501 |
(libDir construct:'rt.zip') exists ifTrue:[
|
|
502 |
jHome := aPath.
|
|
503 |
toAdd := (libDir constructString:'rt.zip').
|
|
504 |
]
|
|
505 |
]
|
|
506 |
]
|
|
507 |
] ifFalse:[
|
|
508 |
((dir construct:'classes') exists
|
|
509 |
and:[(dir construct:'classes') isDirectory]) ifTrue:[
|
|
510 |
jHome := aPath.
|
|
511 |
toAdd := (dir constructString:'classes').
|
|
512 |
] ifFalse:[
|
|
513 |
(dir construct:'classes.zip') exists ifTrue:[
|
|
514 |
jHome := aPath.
|
|
515 |
toAdd := (dir constructString:'classes.zip').
|
|
516 |
] ifFalse:[
|
|
517 |
(dir construct:'rt.zip') exists ifTrue:[
|
|
518 |
jHome := aPath.
|
|
519 |
toAdd := (dir constructString:'rt.zip').
|
|
520 |
]
|
|
521 |
]
|
|
522 |
]
|
|
523 |
].
|
|
524 |
].
|
|
525 |
].
|
|
526 |
toAdd notNil ifTrue:[
|
|
527 |
Transcript showCR:'Adding to classPath: ' , toAdd.
|
|
528 |
jClasses add:toAdd.
|
|
529 |
].
|
|
530 |
].
|
|
531 |
|
|
532 |
self javaHome:jHome.
|
|
533 |
self classPath:(jClasses collect:[:f | f asFilename name]).
|
|
534 |
jHome isNil ifTrue:[
|
|
535 |
Transcript showCR:'no java home directory found'.
|
|
536 |
] ifFalse:[
|
|
537 |
jHome := jHome asFilename.
|
|
538 |
Transcript showCR:'Found javaHome in: ' , jHome pathName.
|
|
539 |
|
|
540 |
(jSources := jHome construct:'source') exists ifFalse:[
|
|
541 |
(jSources := jHome construct:'src') exists ifFalse:[
|
|
542 |
(jSources := jHome construct:'sources') exists ifFalse:[
|
|
543 |
(jSources := jHome construct:'src.zip') exists ifFalse:[
|
|
544 |
jSources := nil.
|
|
545 |
]
|
|
546 |
]
|
|
547 |
]
|
|
548 |
].
|
|
549 |
|
|
550 |
jSources isNil ifTrue:[
|
|
551 |
Transcript showCR:'no java source directory found'.
|
|
552 |
] ifFalse:[
|
|
553 |
Transcript showCR:'Found javaSources in: ' , jSources pathName.
|
|
554 |
self sourceDirectories:(Array with:jSources pathName).
|
|
555 |
].
|
|
556 |
].
|
|
557 |
|
|
558 |
"
|
|
559 |
self initializeForNewClassPath:(Java classPath)
|
|
560 |
self initializeForNewClassPath:(Array with:'/home/java/jdk113')
|
|
561 |
"
|
|
562 |
|
|
563 |
"Modified: / 03-10-2010 / 15:49:02 / Jan Kurs <kurs.jan@post.cz>"
|
|
564 |
"Modified: / 19-10-2010 / 10:49:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
565 |
!
|
|
566 |
|
|
567 |
initializePrettyPrintStyle
|
|
568 |
PrettyPrintStyle := IdentityDictionary new.
|
|
569 |
PrettyPrintStyle at:#accessAttribute put:(#color -> (Color red:0 green:0 blue:25)).
|
|
570 |
PrettyPrintStyle at:#className put:(Array with:(#color -> Color black) with:#bold).
|
|
571 |
PrettyPrintStyle at:#methodName put:(Array with:(#color -> Color black) with:#bold).
|
|
572 |
PrettyPrintStyle at:#code put:(#color -> Color black).
|
|
573 |
|
|
574 |
|
|
575 |
"
|
|
576 |
Java initializePrettyPrintStyle
|
|
577 |
"
|
|
578 |
|
|
579 |
"Created: 1.8.1997 / 11:08:43 / cg"
|
|
580 |
"Modified: 1.8.1997 / 11:09:58 / cg"
|
|
581 |
!
|
|
582 |
|
|
583 |
initializeRelease
|
|
584 |
|
|
585 |
Release ifNil:[Release := JavaRelease any].
|
|
586 |
|
|
587 |
"
|
|
588 |
Release := nil.
|
|
589 |
self initializeRelease.
|
|
590 |
Release
|
|
591 |
"
|
|
592 |
|
|
593 |
"Created: / 22-11-2010 / 13:41:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
594 |
!
|
|
595 |
|
|
596 |
reinitAllClasses
|
|
597 |
self markAllClassesUninitialized.
|
|
598 |
self initAllClasses
|
|
599 |
|
|
600 |
"
|
|
601 |
Java reinitAllClasses
|
|
602 |
"
|
|
603 |
|
|
604 |
"Modified: / 4.1.1998 / 00:34:29 / cg"
|
|
605 |
!
|
|
606 |
|
|
607 |
reinitialize
|
|
608 |
"/ all JavaThreads are lost on a restart (for now)
|
|
609 |
|
|
610 |
FailedToLoadClasses := nil.
|
|
611 |
Threads := nil.
|
|
612 |
|
|
613 |
"Kludge"
|
|
614 |
JavaMethod reinitialize.
|
|
615 |
JavaMethodWithException reinitialize.
|
|
616 |
JavaMethodWithHandler reinitialize.
|
|
617 |
JavaNativeMethod reinitialize.
|
|
618 |
JavaNativeMethod flushAllCachedNativeMethods.
|
|
619 |
|
|
620 |
|
|
621 |
"
|
|
622 |
Java reinitialize
|
|
623 |
"
|
|
624 |
|
|
625 |
"Created: / 26-08-1997 / 20:07:00 / cg"
|
|
626 |
"Modified: / 27-04-1998 / 14:57:23 / cg"
|
|
627 |
"Modified: / 14-12-2010 / 21:30:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
628 |
!
|
|
629 |
|
|
630 |
startupJavaSystem
|
|
631 |
|javaEventThread haveEventThread haveScreenUpdater|
|
|
632 |
|
|
633 |
FailedToLoadClasses := nil.
|
|
634 |
|
|
635 |
"/
|
|
636 |
"/ check if already running
|
|
637 |
"/
|
|
638 |
|
|
639 |
haveEventThread := true.
|
|
640 |
javaEventThread := JavaVM javaEventThread.
|
|
641 |
(javaEventThread isNil or:[javaEventThread isDead]) ifTrue:[
|
|
642 |
haveEventThread := false
|
|
643 |
].
|
|
644 |
|
|
645 |
haveScreenUpdater := false.
|
|
646 |
haveEventThread ifTrue:[
|
|
647 |
self threads do:[:aJavaThread |
|
|
648 |
aJavaThread name = 'JAVA-Screen Updater' ifTrue:[
|
|
649 |
aJavaThread isDead ifFalse:[
|
|
650 |
"/ already running
|
|
651 |
haveScreenUpdater := true
|
|
652 |
]
|
|
653 |
]
|
|
654 |
].
|
|
655 |
].
|
|
656 |
|
|
657 |
(haveEventThread and:[haveScreenUpdater]) ifTrue:[
|
|
658 |
^ self
|
|
659 |
].
|
|
660 |
|
|
661 |
JavaClass orderOfClassInits isNil ifTrue:[
|
|
662 |
"/ the very first start ...
|
|
663 |
'JAVA [info]: (re)initializing JAVA environment completely ...' infoPrintCR.
|
|
664 |
|
|
665 |
JavaVM initializeVM.
|
|
666 |
] ifFalse:[
|
|
667 |
JavaVM initializeVMIfNoEventThreadRunning
|
|
668 |
].
|
|
669 |
'JAVA [info]: done JAVA initialization.' infoPrintCR.
|
|
670 |
|
|
671 |
"
|
|
672 |
Java startupJavaSystem
|
|
673 |
"
|
|
674 |
|
|
675 |
"Modified: / 24.12.1999 / 01:37:49 / cg"
|
|
676 |
!
|
|
677 |
|
|
678 |
terminateAllThreads
|
|
679 |
|myself threadsToKill|
|
|
680 |
|
|
681 |
Threads isNil ifTrue:[
|
|
682 |
^ self
|
|
683 |
].
|
|
684 |
|
|
685 |
myself := Processor activeProcess.
|
|
686 |
|
|
687 |
threadsToKill := IdentitySet new.
|
|
688 |
Threads do:[:aJavaThread |
|
|
689 |
aJavaThread ~~ myself ifTrue:[
|
|
690 |
(aJavaThread isNil or:[aJavaThread == 0]) ifFalse:[
|
|
691 |
(aJavaThread isMemberOf:JavaProcess) ifTrue:[
|
|
692 |
aJavaThread isDead ifFalse:[
|
|
693 |
threadsToKill add:aJavaThread
|
|
694 |
]
|
|
695 |
]
|
|
696 |
]
|
|
697 |
]
|
|
698 |
].
|
|
699 |
threadsToKill do:[:aThread |
|
|
700 |
aThread == JavaVM javaScreenUpdaterThread ifTrue:[self halt].
|
|
701 |
aThread == JavaVM javaEventQueueThread ifTrue:[self halt].
|
|
702 |
aThread terminate
|
|
703 |
].
|
|
704 |
Threads := nil.
|
|
705 |
|
|
706 |
"
|
|
707 |
Java terminateAllThreads
|
|
708 |
"
|
|
709 |
|
|
710 |
"Created: / 26.8.1997 / 19:57:40 / cg"
|
|
711 |
"Modified: / 24.12.1999 / 02:34:53 / cg"
|
|
712 |
! !
|
|
713 |
|
|
714 |
!Java class methodsFor:'enumerating'!
|
|
715 |
|
|
716 |
allClasses
|
|
717 |
^ Classes ? #()
|
|
718 |
|
|
719 |
"
|
|
720 |
|if|
|
|
721 |
|
|
722 |
if := Java at:'java.awt.GraphicsEnvironment'.
|
|
723 |
Java allClasses select:[:aClass |
|
|
724 |
aClass hasInterface:if
|
|
725 |
]
|
|
726 |
"
|
|
727 |
|
|
728 |
"Modified: / 28.1.1998 / 01:42:04 / cg"
|
|
729 |
!
|
|
730 |
|
|
731 |
allClassesDo:aBlock
|
|
732 |
Classes notNil ifTrue:[
|
|
733 |
Classes do:aBlock
|
|
734 |
]
|
|
735 |
! !
|
|
736 |
|
|
737 |
!Java class methodsFor:'object conversions'!
|
|
738 |
|
|
739 |
as_Float:aNumber
|
|
740 |
"convert an ST-float into a Java Float"
|
|
741 |
|
|
742 |
|i|
|
|
743 |
|
|
744 |
i := (Java at:'java.lang.Float') new.
|
|
745 |
i perform:#'<init>(F)V' with:(aNumber asShortFloat).
|
|
746 |
^ i
|
|
747 |
|
|
748 |
"
|
|
749 |
Java as_Float:1
|
|
750 |
Java as_Float:3.14159
|
|
751 |
"
|
|
752 |
|
|
753 |
"Created: 7.8.1997 / 21:21:13 / cg"
|
|
754 |
"Modified: 7.8.1997 / 21:22:05 / cg"
|
|
755 |
!
|
|
756 |
|
|
757 |
as_Hashtable:aDictionary
|
|
758 |
"given a smalltalk dictionary, create and return
|
|
759 |
a Java hashTable for it"
|
|
760 |
|
|
761 |
|hashTable|
|
|
762 |
|
|
763 |
hashTable := (self classForName:'java.util.Hashtable') new.
|
|
764 |
aDictionary keysAndValuesDo:[:k :v |
|
|
765 |
|sk sv jk jv|
|
|
766 |
|
|
767 |
(sk := k) isSymbol ifTrue:[
|
|
768 |
sk := sk asString
|
|
769 |
].
|
|
770 |
(sv := v) isSymbol ifTrue:[
|
|
771 |
sv := sv asString
|
|
772 |
].
|
|
773 |
jk := self as_Object:sk.
|
|
774 |
jv := self as_Object:sv.
|
|
775 |
|
|
776 |
hashTable
|
|
777 |
perform:#'put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;'
|
|
778 |
with:jk
|
|
779 |
with:jv.
|
|
780 |
].
|
|
781 |
^ hashTable
|
|
782 |
|
|
783 |
"
|
|
784 |
Java as_Hashtable:(Dictionary new
|
|
785 |
at:'hello' put:'Hallo';
|
|
786 |
at:'world' put:'Welt';
|
|
787 |
yourself)
|
|
788 |
"
|
|
789 |
|
|
790 |
"Modified: / 14.1.1998 / 17:02:13 / cg"
|
|
791 |
!
|
|
792 |
|
|
793 |
as_Integer:anInteger
|
|
794 |
"convert an ST-integer into a Java Integer"
|
|
795 |
|
|
796 |
|i|
|
|
797 |
|
|
798 |
i := (Java at:'java.lang.Integer') new.
|
|
799 |
i perform:#'<init>(I)V' with:anInteger.
|
|
800 |
^ i
|
|
801 |
|
|
802 |
"
|
|
803 |
Java as_Integer:1
|
|
804 |
"
|
|
805 |
|
|
806 |
"Modified: 7.8.1997 / 21:19:37 / cg"
|
|
807 |
"Created: 7.8.1997 / 21:21:13 / cg"
|
|
808 |
!
|
|
809 |
|
|
810 |
as_Object:anObject
|
|
811 |
"convert an ST-Object into a Java Object"
|
|
812 |
|
|
813 |
anObject isString ifTrue:[
|
|
814 |
^ self as_String:anObject
|
|
815 |
].
|
|
816 |
anObject isInteger ifTrue:[
|
|
817 |
^ self as_Integer:anObject
|
|
818 |
].
|
|
819 |
|
|
820 |
self halt.
|
|
821 |
|
|
822 |
"
|
|
823 |
Java as_Object:'hello world'
|
|
824 |
"
|
|
825 |
|
|
826 |
"Created: 7.8.1997 / 21:15:38 / cg"
|
|
827 |
"Modified: 7.8.1997 / 21:20:07 / cg"
|
|
828 |
!
|
|
829 |
|
|
830 |
as_ST_String: aJavaString
|
|
831 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
832 |
|
|
833 |
| str count offs start stop |
|
|
834 |
|
|
835 |
aJavaString isNil ifTrue: [ ^ nil ].
|
|
836 |
|
|
837 |
"/ count := aJavaString instVarNamed:'count'.
|
|
838 |
|
|
839 |
count := aJavaString instVarAt: 3.
|
|
840 |
|
|
841 |
"/ str := aJavaString instVarNamed:'value'
|
|
842 |
|
|
843 |
str := aJavaString instVarAt: 1.
|
|
844 |
str size == count
|
|
845 |
ifTrue:
|
|
846 |
[ "cos I don't see any reason to do this"
|
|
847 |
"/ ^ str asOneByteString.
|
|
848 |
^ str asOneByteString. ].
|
|
849 |
|
|
850 |
"/ offs := (aJavaString instVarNamed:'offset').
|
|
851 |
|
|
852 |
offs := aJavaString instVarAt: 2.
|
|
853 |
|
|
854 |
"/ start := offs + 1.
|
|
855 |
|
|
856 |
start := offs + 1.
|
|
857 |
|
|
858 |
"/ stop := start + (aJavaString instVarNamed:'count') - 1.
|
|
859 |
|
|
860 |
stop := start + count - 1.
|
|
861 |
|
|
862 |
"/ ^ ((aJavaString instVarNamed:'value') copyFrom:start to:stop) asString
|
|
863 |
|
|
864 |
^ (str copyFrom: start to: stop) asOneByteString
|
|
865 |
|
|
866 |
"Created: / 08-08-1997 / 12:02:55 / cg"
|
|
867 |
"Modified: / 04-01-1999 / 23:55:08 / cg"
|
|
868 |
"Modified: / 22-03-2011 / 17:21:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
869 |
!
|
|
870 |
|
|
871 |
as_String:aString
|
|
872 |
"convert an ST-String into a Java String"
|
|
873 |
|
|
874 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
875 |
|
|
876 |
|s|
|
|
877 |
|
|
878 |
s := Java_lang_String basicNew.
|
|
879 |
s instVarNamed:'value' put: aString.
|
|
880 |
s instVarNamed:'offset' put: 0.
|
|
881 |
s instVarNamed:'count' put: aString size.
|
|
882 |
s instVarNamed:'hash' put: 0.
|
|
883 |
^ s
|
|
884 |
|
|
885 |
"
|
|
886 |
Java as_String:'hello world'
|
|
887 |
"
|
|
888 |
|
|
889 |
"Created: / 07-08-1997 / 21:15:49 / cg"
|
|
890 |
"Modified: / 03-02-2011 / 23:33:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
891 |
!
|
|
892 |
|
|
893 |
as_URL:aString
|
|
894 |
"convert an ST-String into a Java String"
|
|
895 |
|
|
896 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
897 |
|
|
898 |
|u s|
|
|
899 |
|
|
900 |
s := aString.
|
|
901 |
|
|
902 |
"/ kludge for volume
|
|
903 |
OperatingSystem isMSDOSlike ifTrue:[
|
|
904 |
((s size > 1) and:[(s at:2) == $:]) ifTrue:[
|
|
905 |
s := 'file:' , (s copy at:2 put:$|)
|
|
906 |
]
|
|
907 |
].
|
|
908 |
u := (self at:'java.net.URL') newCleared.
|
|
909 |
u perform:#'<init>(Ljava/lang/String;)V' with:(self as_String:s).
|
|
910 |
^ u
|
|
911 |
|
|
912 |
"
|
|
913 |
Java as_URL:'http://www.altavista.com'
|
|
914 |
Java as_URL:'file:/foo/bar'
|
|
915 |
"
|
|
916 |
|
|
917 |
"Created: / 7.8.1997 / 21:15:49 / cg"
|
|
918 |
"Modified: / 25.9.1999 / 22:22:21 / cg"
|
|
919 |
! !
|
|
920 |
|
|
921 |
!Java class methodsFor:'queries'!
|
|
922 |
|
|
923 |
smalltalkClassFor:typeRef
|
|
924 |
self halt.
|
|
925 |
"/ (typeString startsWith:'[[') ifTrue:[
|
|
926 |
"/ ^ Array
|
|
927 |
"/ ].
|
|
928 |
"/ (typeString startsWith:'[F') ifTrue:[
|
|
929 |
"/ ^ FloatArray
|
|
930 |
"/ ].
|
|
931 |
self halt.
|
|
932 |
|
|
933 |
"Modified: 7.4.1997 / 13:33:46 / cg"
|
|
934 |
!
|
|
935 |
|
|
936 |
smalltalkDerefType:typeString
|
|
937 |
(typeString startsWith:'[') ifTrue:[
|
|
938 |
^ typeString copyFrom:2
|
|
939 |
].
|
|
940 |
self halt.
|
|
941 |
|
|
942 |
"Modified: 7.4.1997 / 13:13:24 / cg"
|
|
943 |
! !
|
|
944 |
|
|
945 |
!Java class methodsFor:'registering java classes'!
|
|
946 |
|
|
947 |
at:aJavaName
|
|
948 |
"search & return for a class by name;
|
|
949 |
if there is no such class, return nil.
|
|
950 |
The argument, aJavaName may be either an internal name
|
|
951 |
(sep'd by slashes) or an external name (sep'd by periods).
|
|
952 |
The 'java/lang' standard packages prefix may be ommitted."
|
|
953 |
|
|
954 |
|sym nm cls|
|
|
955 |
|
|
956 |
Classes isNil ifTrue:[^ nil].
|
|
957 |
|
|
958 |
sym := aJavaName asSymbolIfInterned.
|
|
959 |
sym notNil ifTrue:[
|
|
960 |
cls := Classes at:sym ifAbsent:nil.
|
|
961 |
cls notNil ifTrue:[^ cls].
|
|
962 |
].
|
|
963 |
|
|
964 |
nm := aJavaName.
|
|
965 |
(nm includes:$.) ifTrue:[
|
|
966 |
nm := (nm asString copyReplaceAll:$. with:$/).
|
|
967 |
sym := nm asSymbolIfInterned.
|
|
968 |
sym notNil ifTrue:[
|
|
969 |
cls := Classes at:sym ifAbsent:nil.
|
|
970 |
cls notNil ifTrue:[^ cls].
|
|
971 |
].
|
|
972 |
].
|
|
973 |
|
|
974 |
(nm includes:$/) ifFalse:[
|
|
975 |
"/
|
|
976 |
"/ try java.lang.Foo
|
|
977 |
"/
|
|
978 |
nm := 'java/lang/' , nm.
|
|
979 |
sym := nm asSymbolIfInterned.
|
|
980 |
sym notNil ifTrue:[
|
|
981 |
cls := Classes at:sym ifAbsent:nil.
|
|
982 |
cls notNil ifTrue:[^ cls].
|
|
983 |
].
|
|
984 |
].
|
|
985 |
|
|
986 |
^ nil
|
|
987 |
|
|
988 |
"
|
|
989 |
Java at:'java/lang/String'
|
|
990 |
Java at:'java.lang.String'
|
|
991 |
Java at:'String'
|
|
992 |
Java at:'System'
|
|
993 |
Java at:'Foo'
|
|
994 |
"
|
|
995 |
|
|
996 |
"Modified: / 18.7.1998 / 22:55:16 / cg"
|
|
997 |
!
|
|
998 |
|
|
999 |
at:aJavaName put:aJavaClass
|
|
1000 |
|nameSymbol oldClass|
|
|
1001 |
|
|
1002 |
Classes isNil ifTrue:[
|
|
1003 |
Classes := IdentityDictionary new.
|
|
1004 |
].
|
|
1005 |
|
|
1006 |
nameSymbol := aJavaName asSymbol.
|
|
1007 |
(Classes includesKey:nameSymbol) ifTrue:[
|
|
1008 |
oldClass := Classes at:nameSymbol.
|
|
1009 |
oldClass == aJavaClass ifTrue:[
|
|
1010 |
^ self
|
|
1011 |
].
|
|
1012 |
('JAVA: class ' , aJavaName , ' is already loaded') infoPrintCR.
|
|
1013 |
self updateClassRefsFrom:oldClass to:aJavaClass.
|
|
1014 |
].
|
|
1015 |
|
|
1016 |
Classes at:nameSymbol put:aJavaClass.
|
|
1017 |
nameSymbol == #'java/lang/String' ifTrue:[
|
|
1018 |
Java_lang_String := aJavaClass
|
|
1019 |
].
|
|
1020 |
|
|
1021 |
"/ UnresolvedClassRefs notNil ifTrue:[
|
|
1022 |
"/ UnresolvedClassRefs do:[:toResolve |
|
|
1023 |
"/ ]
|
|
1024 |
"/ ].
|
|
1025 |
|
|
1026 |
self changed:#classes
|
|
1027 |
|
|
1028 |
"Created: 17.4.1996 / 23:29:31 / cg"
|
|
1029 |
"Modified: 7.8.1997 / 19:15:58 / cg"
|
|
1030 |
!
|
|
1031 |
|
|
1032 |
flushAllJavaResources
|
|
1033 |
self flushClasses.
|
|
1034 |
|
|
1035 |
SourceCache := CacheDictionary new: 32.
|
|
1036 |
SourceArchiveCache := CacheDictionary new: 32.
|
|
1037 |
|
|
1038 |
ObjectMemory allObjectsDo:[:someObject |
|
|
1039 |
someObject isBehavior ifTrue:[
|
|
1040 |
someObject isJavaClass ifTrue:[
|
|
1041 |
someObject setConstantPool:nil.
|
|
1042 |
someObject setInterfaces:nil.
|
|
1043 |
someObject setMethodDictionary:(MethodDictionary new).
|
|
1044 |
'JAVA [info]: flushing ' print. someObject fullName printCR.
|
|
1045 |
]
|
|
1046 |
].
|
|
1047 |
"/ (someObject isKindOf:JavaMethod) ifTrue:[
|
|
1048 |
"/ someObject setJavaClass:nil.
|
|
1049 |
"/ someObject setExceptionTable:nil.
|
|
1050 |
"/ ].
|
|
1051 |
(someObject isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
|
|
1052 |
someObject constantPool:nil
|
|
1053 |
].
|
|
1054 |
].
|
|
1055 |
JavaClass flushClassesInitOrder.
|
|
1056 |
|
|
1057 |
self flushClasses
|
|
1058 |
|
|
1059 |
"
|
|
1060 |
Java flushAllJavaResources
|
|
1061 |
"
|
|
1062 |
|
|
1063 |
"Modified: / 06-11-2001 / 09:49:37 / cg"
|
|
1064 |
"Modified: / 10-02-2011 / 23:08:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
1065 |
!
|
|
1066 |
|
|
1067 |
flushClasses
|
|
1068 |
Classes := UnresolvedClassRefs := nil.
|
|
1069 |
Smalltalk keys copy do:[:aKey |
|
|
1070 |
(aKey startsWith:'JAVA::') ifTrue:[ Smalltalk removeKey:aKey ]
|
|
1071 |
].
|
|
1072 |
Smalltalk removeKey:#'JAVA'.
|
|
1073 |
|
|
1074 |
Java_lang_String := Java_lang_Class := nil.
|
|
1075 |
JavaVM releaseAllJavaResources.
|
|
1076 |
JavaUnresolvedConstant flushPatchLists.
|
|
1077 |
Debugger == DebugView ifTrue:[Debugger newDebugger].
|
|
1078 |
ObjectMemory flushCaches.
|
|
1079 |
|
|
1080 |
"
|
|
1081 |
Java flushClasses
|
|
1082 |
"
|
|
1083 |
|
|
1084 |
"Modified: / 6.11.2001 / 09:47:49 / cg"
|
|
1085 |
!
|
|
1086 |
|
|
1087 |
markAllClassesUninitialized
|
|
1088 |
self allClassesDo:[:aJavaClass |
|
|
1089 |
aJavaClass markUninitialized
|
|
1090 |
].
|
|
1091 |
|
|
1092 |
"
|
|
1093 |
Java markAllClassesUninitialized
|
|
1094 |
"
|
|
1095 |
!
|
|
1096 |
|
|
1097 |
rememberUnresolved:anUnresolvedClassRef
|
|
1098 |
('JAVA: remember unresolved class: ' , anUnresolvedClassRef fullName) infoPrintCR.
|
|
1099 |
|
|
1100 |
UnresolvedClassRefs isNil ifTrue:[
|
|
1101 |
UnresolvedClassRefs := Dictionary new.
|
|
1102 |
].
|
|
1103 |
UnresolvedClassRefs
|
|
1104 |
at:anUnresolvedClassRef fullName
|
|
1105 |
put:anUnresolvedClassRef
|
|
1106 |
|
|
1107 |
"Created: / 18.4.1996 / 00:05:31 / cg"
|
|
1108 |
"Modified: / 19.10.1998 / 20:57:44 / cg"
|
|
1109 |
!
|
|
1110 |
|
|
1111 |
removeClass:aJavaClass
|
|
1112 |
"/ remove it from myself
|
|
1113 |
|
|
1114 |
|javaName sym nm cls p ns|
|
|
1115 |
|
|
1116 |
javaName := aJavaClass fullName.
|
|
1117 |
|
|
1118 |
sym := javaName asSymbolIfInterned.
|
|
1119 |
sym notNil ifTrue:[
|
|
1120 |
cls := Classes at:sym ifAbsent:nil.
|
|
1121 |
].
|
|
1122 |
cls isNil ifTrue:[
|
|
1123 |
nm := javaName.
|
|
1124 |
(nm includes:$.) ifTrue:[
|
|
1125 |
"/
|
|
1126 |
"/ try pckg/.../name
|
|
1127 |
"/
|
|
1128 |
nm := (nm asString copyReplaceAll:$. with:$/).
|
|
1129 |
sym := nm asSymbolIfInterned.
|
|
1130 |
sym notNil ifTrue:[
|
|
1131 |
cls := Classes at:sym ifAbsent:nil.
|
|
1132 |
].
|
|
1133 |
].
|
|
1134 |
].
|
|
1135 |
(cls notNil and:[cls == aJavaClass]) ifTrue:[
|
|
1136 |
Classes removeKey:sym.
|
|
1137 |
self updateClassRefsFrom:aJavaClass to:nil.
|
|
1138 |
].
|
|
1139 |
Smalltalk removeKey:('JAVA::' , javaName) asSymbol.
|
|
1140 |
Smalltalk removeKey:javaName asSymbol.
|
|
1141 |
Smalltalk removeKey:((javaName , '') copy replaceAll:$/ with:$.) asSymbol.
|
|
1142 |
|
|
1143 |
"/ remove myself from the JAVA::-::-:: namespace
|
|
1144 |
"/ (which exists for convenient smalltalk access only)
|
|
1145 |
|
|
1146 |
p := aJavaClass nameSpacePath.
|
|
1147 |
p knownAsSymbol ifTrue:[
|
|
1148 |
ns := Smalltalk at:p asSymbol.
|
|
1149 |
(ns notNil and:[ns isNameSpace]) ifTrue:[
|
|
1150 |
Smalltalk removeKey:(p , '::' , aJavaClass lastName) asSymbol
|
|
1151 |
]
|
|
1152 |
].
|
|
1153 |
|
|
1154 |
"Modified: / 19.10.1998 / 20:58:49 / cg"
|
|
1155 |
!
|
|
1156 |
|
|
1157 |
unresolvedClassRefFor:aClassName
|
|
1158 |
UnresolvedClassRefs isNil ifTrue:[^ nil].
|
|
1159 |
^ UnresolvedClassRefs at:aClassName ifAbsent:nil.
|
|
1160 |
|
|
1161 |
"Modified: / 19.10.1998 / 20:56:46 / cg"
|
|
1162 |
!
|
|
1163 |
|
|
1164 |
updateClassRefsFrom:oldClass to:newClass
|
|
1165 |
"update all references to oldClass to now refer to newClass.
|
|
1166 |
sent, when a class is reloaded"
|
|
1167 |
|
|
1168 |
newClass notNil ifTrue:[
|
|
1169 |
"/
|
|
1170 |
"/ kludge: the new class might have been resolved with the oldClass ...
|
|
1171 |
"/
|
|
1172 |
newClass constantPool
|
|
1173 |
updateClassRefsFrom:oldClass to:newClass.
|
|
1174 |
].
|
|
1175 |
|
|
1176 |
self allClassesDo:[:aJavaClass |
|
|
1177 |
aJavaClass updateClassRefsFrom:oldClass to:newClass
|
|
1178 |
].
|
|
1179 |
|
|
1180 |
"Created: 26.3.1997 / 13:49:20 / cg"
|
|
1181 |
"Modified: 12.8.1997 / 03:04:44 / cg"
|
|
1182 |
! !
|
|
1183 |
|
|
1184 |
!Java class methodsFor:'source management'!
|
|
1185 |
|
|
1186 |
classSource:filename package:package in:dirOrZipFile
|
|
1187 |
|fn zar f |
|
|
1188 |
|
|
1189 |
fn := dirOrZipFile asFilename.
|
|
1190 |
fn isDirectory
|
|
1191 |
ifTrue:
|
|
1192 |
[ package notNil
|
|
1193 |
ifTrue:[ (f:= fn / package / filename) exists ifTrue:[ ^ f contents asString ]. ].
|
|
1194 |
(f := fn / filename) exists ifTrue:[ ^ f contents asString ]. ]
|
|
1195 |
ifFalse:
|
|
1196 |
[ (dirOrZipFile last == $p and: [fn hasSuffix:'zip'])
|
|
1197 |
ifTrue:
|
|
1198 |
[ zar := SourceArchiveCache
|
|
1199 |
at: dirOrZipFile
|
|
1200 |
ifAbsentPut:[ZipArchive oldFileNamed:fn pathName].
|
|
1201 |
zar notNil
|
|
1202 |
ifTrue:
|
|
1203 |
[ package notNil
|
|
1204 |
ifTrue:[
|
|
1205 |
OperatingSystem fileSeparator ~~ $/ ifTrue: [
|
|
1206 |
f := (package copyReplaceAll: OperatingSystem fileSeparator with: $/) , '/' , filename
|
|
1207 |
] ifFalse:[
|
|
1208 |
f := package , '/' , filename.
|
|
1209 |
]]
|
|
1210 |
ifFalse:[ f := filename].
|
|
1211 |
(zar findMember: f) ifNotNil:
|
|
1212 |
[
|
|
1213 |
"Kludge because of broken ZipArchive"
|
|
1214 |
| cache |
|
754
|
1215 |
cache := Java cacheDirectory / Release name / 'src'.
|
752
|
1216 |
cache exists ifFalse:[cache recursiveMakeDirectory].
|
|
1217 |
(cache / f) exists ifTrue:[^(cache / f) contents asString].
|
|
1218 |
OperatingSystem
|
|
1219 |
executeCommand:('unzip "%1" "%2"' bindWith: fn asAbsoluteFilename asString
|
|
1220 |
with: f asString)
|
|
1221 |
inDirectory: cache asString.
|
|
1222 |
(f := cache / f) exists ifTrue:[^f contents asString]
|
|
1223 |
]
|
|
1224 |
]]].
|
|
1225 |
|
|
1226 |
^ nil
|
|
1227 |
|
|
1228 |
"
|
|
1229 |
Java classSource: 'Object.java' package:'java/lang' in:'/home/jv/Projects/JavaX/java-6-openjdk/src'
|
|
1230 |
Java classSource: 'Object.java' package:'java/lang' in:'/usr/lib/jvm/java-6-openjdk/src.zip'
|
|
1231 |
|
|
1232 |
"
|
|
1233 |
|
|
1234 |
"Modified: / 29-03-1998 / 21:46:40 / cg"
|
|
1235 |
"Created: / 30-11-2010 / 12:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
754
|
1236 |
"Modified: / 08-04-2011 / 15:01:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
1237 |
!
|
|
1238 |
|
|
1239 |
classSourceOf:aClass
|
|
1240 |
|package dirName binary sourceFileName sourceFile loader codeBaseURL protocol codeBaseURLIdx src|
|
|
1241 |
|
|
1242 |
aClass isNil ifTrue:[
|
|
1243 |
^ nil
|
|
1244 |
].
|
|
1245 |
"/ look at the cache"
|
|
1246 |
SourceCache at: aClass ifPresent: [:src|^src].
|
|
1247 |
|
|
1248 |
"/ first, look in the directory, where the binary
|
|
1249 |
"/ was loaded from.
|
|
1250 |
|
|
1251 |
binary := aClass binaryFile.
|
|
1252 |
binary notNil ifTrue:[
|
|
1253 |
binary := binary asFilename.
|
|
1254 |
aClass sourceFile notNil ifTrue:[
|
|
1255 |
sourceFileName := binary directory constructString:(aClass sourceFile).
|
|
1256 |
sourceFileName asFilename exists ifFalse:[
|
|
1257 |
sourceFileName := nil.
|
|
1258 |
]
|
|
1259 |
].
|
|
1260 |
sourceFileName isNil ifTrue:[
|
|
1261 |
sourceFileName := binary withSuffix:'java'.
|
|
1262 |
].
|
|
1263 |
sourceFile := sourceFileName asFilename.
|
|
1264 |
] ifFalse:[
|
|
1265 |
"/ maybe it was loaded by a java classLoader ...
|
|
1266 |
(loader := aClass classLoader) notNil ifTrue:[
|
|
1267 |
codeBaseURLIdx := loader class instVarOffsetOf:'codeBaseURL'.
|
|
1268 |
codeBaseURLIdx notNil ifTrue:[
|
|
1269 |
(codeBaseURL := loader instVarAt:codeBaseURLIdx) notNil ifTrue:[
|
|
1270 |
(protocol := codeBaseURL instVarNamed:'protocol') notNil ifTrue:[
|
|
1271 |
(Java as_ST_String:protocol) = 'file' ifTrue:[
|
|
1272 |
dirName := Java as_ST_String:(codeBaseURL instVarNamed:'file').
|
|
1273 |
dirName := dirName asFilename.
|
|
1274 |
dirName exists ifTrue:[
|
|
1275 |
aClass sourceFile notNil ifTrue:[
|
|
1276 |
sourceFile := sourceFileName := dirName construct:aClass sourceFile.
|
|
1277 |
]
|
|
1278 |
]
|
|
1279 |
]
|
|
1280 |
]
|
|
1281 |
]
|
|
1282 |
]
|
|
1283 |
]
|
|
1284 |
].
|
|
1285 |
sourceFile notNil ifTrue:[
|
|
1286 |
sourceFile exists ifFalse:[
|
|
1287 |
binary notNil ifTrue:[
|
|
1288 |
sourceFileName := binary withSuffix:'jav'.
|
|
1289 |
sourceFile := sourceFileName asFilename.
|
|
1290 |
sourceFile exists ifFalse:[
|
|
1291 |
sourceFileName := binary withSuffix:'JAV'.
|
|
1292 |
sourceFile := sourceFileName asFilename.
|
|
1293 |
sourceFile exists ifFalse:[
|
|
1294 |
sourceFileName := binary withSuffix:'JAVA'.
|
|
1295 |
sourceFile := sourceFileName asFilename.
|
|
1296 |
].
|
|
1297 |
].
|
|
1298 |
]
|
|
1299 |
].
|
|
1300 |
].
|
|
1301 |
|
|
1302 |
"/ special case: there were multiple classes in a single
|
|
1303 |
"/ source file.
|
|
1304 |
|
|
1305 |
(binary notNil and:[aClass sourceFile notNil]) ifTrue:[
|
|
1306 |
binary withoutSuffix baseName ~= aClass sourceFile asFilename withoutSuffix baseName ifTrue:[
|
|
1307 |
'JAVA: trouble extracting fileName: ' infoPrint.
|
|
1308 |
binary withoutSuffix baseName print. ' vs. ' infoPrint.
|
|
1309 |
aClass sourceFile asFilename withoutSuffix baseName infoPrintCR.
|
|
1310 |
].
|
|
1311 |
].
|
|
1312 |
|
|
1313 |
"/ if that fails, look in standard places
|
|
1314 |
|
|
1315 |
(sourceFile isNil or:[sourceFile exists not]) ifTrue:[
|
|
1316 |
sourceFile := aClass sourceFile.
|
|
1317 |
package := aClass javaPackageAsDirname.
|
|
1318 |
self effectiveSourceDirectories do:[:dir|
|
|
1319 |
src := self classSource: sourceFile package: package in: dir.
|
|
1320 |
src ifNotNil:[^src]
|
|
1321 |
]
|
|
1322 |
|
|
1323 |
|
|
1324 |
].
|
|
1325 |
sourceFile isFilename ifFalse:[^nil].
|
|
1326 |
^ (sourceFile contentsOfEntireFile).
|
|
1327 |
|
|
1328 |
"
|
|
1329 |
Java classSourceOf: JAVA::java::lang::Object
|
|
1330 |
"
|
|
1331 |
|
|
1332 |
"Modified: / 27-01-1999 / 20:40:30 / cg"
|
|
1333 |
"Modified: / 10-02-2011 / 23:10:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
1334 |
! !
|
|
1335 |
|
|
1336 |
!Java class methodsFor:'starting apps'!
|
|
1337 |
|
|
1338 |
javaProcessForMainOf:aJavaClass
|
|
1339 |
"ask for a commandLine, create a java process to invoke
|
|
1340 |
its main and return it. The process is not scheduled for
|
|
1341 |
execution."
|
|
1342 |
|
|
1343 |
^ self javaProcessForMainOf:aJavaClass argumentString:nil
|
|
1344 |
|
|
1345 |
"Modified: / 30.12.1998 / 20:24:25 / cg"
|
|
1346 |
!
|
|
1347 |
|
|
1348 |
javaProcessForMainOf:aJavaClass argumentString:argStringIn
|
|
1349 |
"create a java process, ready to invoke the classes main
|
|
1350 |
method. Returns the process - ready to run but not yet resumed"
|
|
1351 |
|
|
1352 |
|p argStringArray argString stdInReplacement alreadyAskedForStdin|
|
|
1353 |
|
|
1354 |
argString := argStringIn.
|
|
1355 |
argString isNil ifTrue:[
|
|
1356 |
argString := Dialog
|
|
1357 |
request:'argument string:'
|
|
1358 |
initialAnswer:LastArgumentString ? ''
|
|
1359 |
onCancel:nil.
|
|
1360 |
argString isNil ifTrue:[^ nil].
|
|
1361 |
|
|
1362 |
LastArgumentString := argString.
|
|
1363 |
].
|
|
1364 |
|
|
1365 |
JavaVM initializeVMIfNoEventThreadRunning.
|
|
1366 |
(Java at:'java.lang.System') instVarNamed:'security' put:nil.
|
|
1367 |
|
|
1368 |
argString isEmpty ifTrue:[
|
|
1369 |
argStringArray := #()
|
|
1370 |
] ifFalse:[
|
|
1371 |
argStringArray := argString asCollectionOfWords collect:[:s | Java as_String:s] as:Array.
|
|
1372 |
].
|
|
1373 |
|
|
1374 |
p := JavaProcess
|
|
1375 |
for:[
|
|
1376 |
"/ if the program reads from stdin, let user provide a file
|
|
1377 |
"/ for it.
|
|
1378 |
JavaVM stdinReplacementFileQuerySignal handle:[:ex |
|
|
1379 |
|fn|
|
|
1380 |
|
|
1381 |
alreadyAskedForStdin == true ifFalse:[
|
|
1382 |
fn := Dialog
|
|
1383 |
requestFileName:'Program reads from Stdin - give inputFile or cancel for EOF'
|
|
1384 |
default:nil
|
|
1385 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory).
|
|
1386 |
fn notNil ifTrue:[
|
|
1387 |
stdInReplacement := fn asFilename readStream.
|
|
1388 |
].
|
|
1389 |
alreadyAskedForStdin := true.
|
|
1390 |
].
|
|
1391 |
ex proceedWith:stdInReplacement
|
|
1392 |
] do:[
|
|
1393 |
aJavaClass
|
|
1394 |
performStatic:#'main([Ljava/lang/String;)V'
|
|
1395 |
with:argStringArray.
|
|
1396 |
]
|
|
1397 |
]
|
|
1398 |
priority:(Processor activePriority - 1).
|
|
1399 |
|
|
1400 |
p name:(aJavaClass fullName , '::main()').
|
|
1401 |
p restartable:true.
|
|
1402 |
^ p
|
|
1403 |
|
|
1404 |
"Created: / 15.8.1997 / 04:41:20 / cg"
|
|
1405 |
"Modified: / 24.12.1999 / 01:50:21 / cg"
|
|
1406 |
! !
|
|
1407 |
|
|
1408 |
!Java class methodsFor:'documentation'!
|
|
1409 |
|
|
1410 |
version
|
|
1411 |
^ '$Id$'
|
|
1412 |
!
|
|
1413 |
|
|
1414 |
version_SVN
|
|
1415 |
^ '$Id$'
|
|
1416 |
! !
|
|
1417 |
|
|
1418 |
Java initialize!
|