author | cg |
Mon, 05 Oct 1998 11:47:26 +0000 | |
changeset 372 | 1c7da8a0e6ab |
parent 369 | 3d0628c9b63e |
child 381 | b8348aa2d1b2 |
permissions | -rw-r--r-- |
17 | 1 |
Object subclass:#Java |
2 |
instanceVariableNames:'' |
|
201 | 3 |
classVariableNames:'Classes UnresolvedClassRefs ClassPath SourceDirectories JavaHome |
224 | 4 |
Java_lang_String Java_lang_Class PrettyPrintStyle |
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
5 |
LastArgumentString Threads ExcludedClassPath FailedToLoadClasses' |
17 | 6 |
poolDictionaries:'' |
7 |
category:'Java-Support' |
|
8 |
! |
|
9 |
||
10 |
||
135 | 11 |
!Java class methodsFor:'accessing'! |
24 | 12 |
|
147 | 13 |
classForName:aString |
14 |
"return a javaClass - either existing or loaded" |
|
15 |
||
255 | 16 |
|cls loader classURL| |
147 | 17 |
|
18 |
cls := self at:aString. |
|
19 |
cls isNil ifTrue:[ |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
20 |
FailedToLoadClasses notNil ifTrue:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
21 |
(FailedToLoadClasses includes:aString) ifTrue:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
22 |
"/ ('JAVA [info]: class loading already failed: ' , aString) infoPrintCR. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
23 |
^ nil |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
24 |
] |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
25 |
]. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
26 |
|
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
27 |
('JAVA [info]: late class loading: ' , aString) infoPrintCR. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
28 |
loader := JavaClassReader classLoaderQuerySignal raise. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
29 |
loader isNil ifTrue:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
30 |
"/ load using default (ST/X) loader |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
31 |
cls := JavaClassReader loadClass:aString. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
32 |
] ifFalse:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
33 |
"/ load using a Java class loader |
255 | 34 |
"/ classURL := Java as_URL:('file:' , aString , '.class'). |
35 |
"/ loader loadClass:classURL. |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
36 |
loader perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
37 |
with:(Java as_String:aString). |
255 | 38 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
39 |
cls := self at:aString. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
40 |
]. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
41 |
cls isNil ifTrue:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
42 |
FailedToLoadClasses isNil ifTrue:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
43 |
FailedToLoadClasses := Set new. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
44 |
]. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
45 |
FailedToLoadClasses add:aString |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
46 |
] |
147 | 47 |
]. |
48 |
^ cls |
|
49 |
||
255 | 50 |
"Created: / 18.3.1997 / 16:45:57 / cg" |
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
51 |
"Modified: / 27.4.1998 / 15:00:52 / cg" |
147 | 52 |
! |
53 |
||
90 | 54 |
classNamed:aString |
55 |
^ self at:aString |
|
32 | 56 |
! |
57 |
||
167 | 58 |
java_lang_Class |
59 |
Java_lang_Class isNil ifTrue:[ |
|
248 | 60 |
Java_lang_Class := self at:'java.lang.Class' |
167 | 61 |
]. |
62 |
^ Java_lang_Class |
|
63 |
||
64 |
"Created: 26.3.1997 / 13:42:59 / cg" |
|
65 |
"Modified: 26.3.1997 / 13:46:24 / cg" |
|
66 |
! |
|
67 |
||
68 |
java_lang_String |
|
69 |
Java_lang_String isNil ifTrue:[ |
|
248 | 70 |
Java_lang_String := self at:'java.lang.String' |
167 | 71 |
]. |
72 |
^ Java_lang_String |
|
73 |
||
74 |
"Created: 26.3.1997 / 13:43:17 / cg" |
|
75 |
"Modified: 26.3.1997 / 13:50:21 / cg" |
|
76 | 76 |
! |
77 |
||
188 | 78 |
prettyPrintStyle |
79 |
^ PrettyPrintStyle |
|
80 |
||
81 |
"Created: 1.8.1997 / 10:37:57 / cg" |
|
248 | 82 |
! |
83 |
||
84 |
threads |
|
85 |
Threads isNil ifTrue:[ |
|
261 | 86 |
Threads := WeakIdentityDictionary new. |
248 | 87 |
]. |
88 |
^ Threads |
|
89 |
||
90 |
"Created: 26.8.1997 / 19:53:57 / cg" |
|
91 |
"Modified: 26.8.1997 / 19:55:27 / cg" |
|
192 | 92 |
! ! |
93 |
||
94 |
!Java class methodsFor:'accessing paths'! |
|
95 |
||
96 |
addToClassPath:aPath |
|
97 |
(ClassPath includes:aPath) ifFalse:[ |
|
369 | 98 |
ClassPath add:aPath. |
99 |
FailedToLoadClasses := nil |
|
192 | 100 |
] |
101 |
||
369 | 102 |
"Created: / 1.8.1997 / 21:10:07 / cg" |
103 |
"Modified: / 17.9.1998 / 20:43:55 / cg" |
|
192 | 104 |
! |
105 |
||
198 | 106 |
addToSourcePath:aPath |
107 |
(SourceDirectories includes:aPath) ifFalse:[ |
|
248 | 108 |
SourceDirectories add:aPath |
198 | 109 |
] |
110 |
||
111 |
"Modified: 7.2.1997 / 19:23:55 / cg" |
|
112 |
"Created: 2.8.1997 / 14:12:31 / cg" |
|
113 |
! |
|
114 |
||
192 | 115 |
classPath |
116 |
^ ClassPath |
|
117 |
||
118 |
"Created: 7.2.1997 / 19:23:45 / cg" |
|
119 |
"Modified: 7.2.1997 / 19:23:55 / cg" |
|
120 |
! |
|
121 |
||
122 |
classPath:aCollectionOfPaths |
|
369 | 123 |
ClassPath := aCollectionOfPaths asOrderedCollection. |
124 |
FailedToLoadClasses := nil |
|
192 | 125 |
|
369 | 126 |
"Created: / 7.2.1997 / 19:23:45 / cg" |
127 |
"Modified: / 17.9.1998 / 20:44:09 / cg" |
|
192 | 128 |
! |
129 |
||
276 | 130 |
excludedClassPath |
131 |
^ ExcludedClassPath |
|
132 |
||
133 |
"Modified: / 7.2.1997 / 19:23:55 / cg" |
|
134 |
"Created: / 27.1.1998 / 21:57:13 / cg" |
|
135 |
! |
|
136 |
||
137 |
isExcludedFromClassPath:fileName |
|
138 |
|nm| |
|
139 |
||
140 |
nm := fileName asFilename pathName. |
|
141 |
ExcludedClassPath do:[:excludedPath | |
|
142 |
(nm startsWith:excludedPath) ifTrue:[^ true]. |
|
143 |
]. |
|
144 |
^ false |
|
145 |
||
146 |
"Created: / 27.1.1998 / 22:00:40 / cg" |
|
147 |
! |
|
148 |
||
201 | 149 |
javaHome |
150 |
^ JavaHome |
|
151 |
||
152 |
"Created: 6.8.1997 / 00:53:19 / cg" |
|
153 |
! |
|
154 |
||
155 |
javaHome:aPath |
|
156 |
JavaHome := aPath |
|
157 |
||
158 |
"Created: 6.8.1997 / 00:53:23 / cg" |
|
159 |
! |
|
160 |
||
192 | 161 |
removeFromClassPath:aPath |
162 |
(ClassPath includes:aPath) ifTrue:[ |
|
248 | 163 |
ClassPath remove:aPath |
192 | 164 |
] |
165 |
||
166 |
"Modified: 7.2.1997 / 19:23:55 / cg" |
|
167 |
"Created: 1.8.1997 / 21:10:21 / cg" |
|
188 | 168 |
! |
169 |
||
198 | 170 |
removeFromSourcePath:aPath |
171 |
(SourceDirectories includes:aPath) ifTrue:[ |
|
248 | 172 |
SourceDirectories remove:aPath |
198 | 173 |
] |
174 |
||
175 |
"Modified: 7.2.1997 / 19:23:55 / cg" |
|
176 |
"Created: 2.8.1997 / 14:13:01 / cg" |
|
177 |
! |
|
178 |
||
76 | 179 |
sourceDirectories |
180 |
^ SourceDirectories |
|
181 |
! |
|
182 |
||
183 |
sourceDirectories:aCollectionOfPaths |
|
184 |
SourceDirectories := aCollectionOfPaths asOrderedCollection |
|
185 |
||
186 |
" |
|
187 |
Java |
|
248 | 188 |
sourceDirectories:#( |
189 |
'/phys/ibm3/java/src' |
|
190 |
) |
|
76 | 191 |
" |
192 |
||
193 |
||
261 | 194 |
! |
195 |
||
196 |
sourcePath |
|
197 |
^ SourceDirectories |
|
198 |
||
199 |
"Created: / 16.1.1998 / 13:26:55 / cg" |
|
24 | 200 |
! ! |
201 |
||
135 | 202 |
!Java class methodsFor:'class initialization'! |
47 | 203 |
|
204 |
initAllClasses |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
205 |
|system| |
147 | 206 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
207 |
FailedToLoadClasses := nil. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
208 |
self initAllStaticFields. |
147 | 209 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
210 |
system := self classForName:'java.lang.System'. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
211 |
system isInitialized ifFalse:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
212 |
system classInit. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
213 |
self initSystemClass. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
214 |
]. |
147 | 215 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
216 |
self allClassesDo:[:cls | |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
217 |
cls isInitialized ifFalse:[ |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
218 |
cls classInit |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
219 |
] |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
220 |
] |
47 | 221 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
222 |
"Modified: / 27.4.1998 / 14:58:02 / cg" |
47 | 223 |
! |
224 |
||
102 | 225 |
initAllStaticFields |
226 |
self allClassesDo:[:cls | |
|
248 | 227 |
cls initializeStaticFields |
102 | 228 |
] |
229 |
||
230 |
! |
|
231 |
||
146 | 232 |
initSystemClass |
198 | 233 |
|system| |
234 |
||
235 |
system := Java at:'java.lang.System'. |
|
255 | 236 |
system isNil ifTrue:[ |
237 |
JavaVM initializeVM. |
|
238 |
system := Java at:'java.lang.System'. |
|
261 | 239 |
system isNil ifTrue:[ |
240 |
self error:'no ''java.lang.System'' class'. |
|
241 |
^ self |
|
242 |
]. |
|
255 | 243 |
]. |
200 | 244 |
(system implements:#'initializeSystemClass()V') ifTrue:[ |
255 | 245 |
system invokeStatic:#'initializeSystemClass()V'. |
198 | 246 |
]. |
146 | 247 |
|
147 | 248 |
" |
249 |
Java initSystemClass |
|
215 | 250 |
|
251 |
(Java at:'java.lang.System') |
|
261 | 252 |
perform:#'getProperty(Ljava/lang/String;)Ljava/lang/String;' |
255 | 253 |
with:(Java as_String:'java.home') |
147 | 254 |
" |
255 |
||
261 | 256 |
"Modified: / 15.1.1998 / 00:29:37 / cg" |
146 | 257 |
! |
258 |
||
76 | 259 |
initialize |
372 | 260 |
|tryJDK1_2 tryJDK1_16 tryJDK1_15 tryJDK1_13 tryJDK1_11 tryJDK1_103 directoriesToSearch |
364 | 261 |
jHome jClasses jSources mozillaHome| |
262 |
||
263 |
FailedToLoadClasses := nil. |
|
283 | 264 |
|
265 |
"/ cannot use JDK1.2 yet (they made so many changes ...) |
|
266 |
tryJDK1_2 := false. |
|
372 | 267 |
tryJDK1_16 := true. |
364 | 268 |
tryJDK1_15 := true. |
269 |
tryJDK1_13 := true. |
|
372 | 270 |
tryJDK1_11 := true. |
271 |
tryJDK1_103 := false. |
|
116 | 272 |
|
276 | 273 |
ExcludedClassPath := OrderedCollection new. |
274 |
||
364 | 275 |
directoriesToSearch := OrderedCollection new. |
283 | 276 |
tryJDK1_2 ifTrue:[ |
364 | 277 |
directoriesToSearch add:'/phys/idefix/home2/java/jdk1.2'. |
278 |
directoriesToSearch add:'/usr/local/java/jdk1.2'. |
|
279 |
directoriesToSearch add:'/usr/local/jdk1.2'. |
|
280 |
directoriesToSearch add:'/usr/java/jdk1.2'. |
|
281 |
directoriesToSearch add:'/usr/jdk1.2'. |
|
282 |
directoriesToSearch add:'c:\jdk1.2'. |
|
367 | 283 |
directoriesToSearch add:'c:\java\jdk1.2'. |
364 | 284 |
]. |
372 | 285 |
tryJDK1_16 ifTrue:[ |
286 |
directoriesToSearch add:'/phys/idefix/home2/java/jdk116'. |
|
287 |
directoriesToSearch add:'/usr/local/java/jdk116'. |
|
288 |
directoriesToSearch add:'/usr/local/java/jdk1.1.6'. |
|
289 |
directoriesToSearch add:'/usr/local/jdk116'. |
|
290 |
directoriesToSearch add:'/usr/local/jdk1.1.6'. |
|
291 |
directoriesToSearch add:'/usr/java/jdk116'. |
|
292 |
directoriesToSearch add:'/usr/java/jdk1.1.6'. |
|
293 |
directoriesToSearch add:'/usr/jdk116'. |
|
294 |
directoriesToSearch add:'/usr/jdk1.1.6'. |
|
295 |
directoriesToSearch add:'c:\jdk116'. |
|
296 |
directoriesToSearch add:'c:\jdk1.1.6'. |
|
297 |
directoriesToSearch add:'c:\java\jdk1.1.6'. |
|
298 |
]. |
|
364 | 299 |
tryJDK1_15 ifTrue:[ |
372 | 300 |
directoriesToSearch add:'/phys/idefix/home2/java/jdk115'. |
364 | 301 |
directoriesToSearch add:'/usr/local/java/jdk115'. |
302 |
directoriesToSearch add:'/usr/local/java/jdk1.1.5'. |
|
303 |
directoriesToSearch add:'/usr/local/jdk115'. |
|
304 |
directoriesToSearch add:'/usr/local/jdk1.1.5'. |
|
305 |
directoriesToSearch add:'/usr/java/jdk115'. |
|
306 |
directoriesToSearch add:'/usr/java/jdk1.1.5'. |
|
307 |
directoriesToSearch add:'/usr/jdk115'. |
|
308 |
directoriesToSearch add:'/usr/jdk1.1.5'. |
|
309 |
directoriesToSearch add:'c:\jdk115'. |
|
310 |
directoriesToSearch add:'c:\jdk1.1.5'. |
|
367 | 311 |
directoriesToSearch add:'c:\java\jdk1.1.5'. |
283 | 312 |
]. |
364 | 313 |
tryJDK1_13 ifTrue:[ |
372 | 314 |
directoriesToSearch add:'/phys/idefix/home2/java/jdk113'. |
364 | 315 |
directoriesToSearch add:'/usr/local/java/jdk113'. |
316 |
directoriesToSearch add:'/usr/local/java/jdk1.1.3'. |
|
317 |
directoriesToSearch add:'/usr/local/jdk113'. |
|
318 |
directoriesToSearch add:'/usr/local/jdk1.1.3'. |
|
319 |
directoriesToSearch add:'/usr/java/jdk113'. |
|
320 |
directoriesToSearch add:'/usr/java/jdk1.1.3'. |
|
321 |
directoriesToSearch add:'/usr/jdk113'. |
|
322 |
directoriesToSearch add:'/usr/jdk1.1.3'. |
|
323 |
directoriesToSearch add:'c:\jdk113'. |
|
324 |
directoriesToSearch add:'c:\jdk1.1.3'. |
|
367 | 325 |
directoriesToSearch add:'c:\java\jdk1.1.3'. |
364 | 326 |
]. |
372 | 327 |
tryJDK1_11 ifTrue:[ |
328 |
directoriesToSearch add:'/phys/idefix/home2/java/jdk111'. |
|
329 |
directoriesToSearch add:'/usr/local/java/jdk111'. |
|
330 |
directoriesToSearch add:'/usr/local/java/jdk1.1.1'. |
|
331 |
directoriesToSearch add:'/usr/local/jdk111'. |
|
332 |
directoriesToSearch add:'/usr/local/jdk1.1.1'. |
|
333 |
directoriesToSearch add:'/usr/java/jdk111'. |
|
334 |
directoriesToSearch add:'/usr/java/jdk1.1.1'. |
|
335 |
directoriesToSearch add:'/usr/jdk111'. |
|
336 |
directoriesToSearch add:'/usr/jdk1.1.1'. |
|
337 |
directoriesToSearch add:'c:\jdk111'. |
|
338 |
directoriesToSearch add:'c:\jdk1.1.1'. |
|
339 |
directoriesToSearch add:'c:\java\jdk1.1.1'. |
|
340 |
]. |
|
341 |
tryJDK1_103 ifTrue:[ |
|
342 |
directoriesToSearch add:'/phys/idefix/home2/java/jdk103'. |
|
343 |
directoriesToSearch add:'/usr/local/java/jdk103'. |
|
344 |
directoriesToSearch add:'/usr/local/java/jdk1.0.3'. |
|
345 |
directoriesToSearch add:'/usr/local/jdk103'. |
|
346 |
directoriesToSearch add:'/usr/local/jdk1.0.3'. |
|
347 |
directoriesToSearch add:'/usr/java/jdk103'. |
|
348 |
directoriesToSearch add:'/usr/java/jdk1.0.3'. |
|
349 |
directoriesToSearch add:'/usr/jdk103'. |
|
350 |
directoriesToSearch add:'/usr/jdk1.0.3'. |
|
351 |
directoriesToSearch add:'c:\jdk103'. |
|
352 |
directoriesToSearch add:'c:\jdk1.0.3'. |
|
353 |
directoriesToSearch add:'c:\java\jdk1.0.3'. |
|
354 |
]. |
|
364 | 355 |
|
356 |
directoriesToSearch do:[:aPath | |
|
357 |
|dir libDir| |
|
358 |
||
359 |
dir := aPath asFilename. |
|
360 |
(jHome isNil and:[dir exists]) ifTrue:[ |
|
361 |
"/ there must be either a classes directory, |
|
362 |
"/ or a classes.zip file ... |
|
363 |
(libDir := dir construct:'lib') exists ifTrue:[ |
|
364 |
(libDir construct:'classes.zip') exists ifTrue:[ |
|
365 |
jHome := aPath. |
|
366 |
jClasses := libDir construct:'classes.zip'. |
|
367 |
] ifFalse:[ |
|
368 |
(libDir construct:'classes') exists ifTrue:[ |
|
369 |
(libDir construct:'classes') isDirectory ifTrue:[ |
|
370 |
jHome := aPath. |
|
371 |
jClasses := libDir construct:'classes'. |
|
372 |
] |
|
373 |
] |
|
374 |
] |
|
358 | 375 |
]. |
274 | 376 |
]. |
239 | 377 |
]. |
364 | 378 |
jHome isNil ifTrue:[ |
379 |
Transcript showCR:'no java home directory found'. |
|
380 |
^ self |
|
381 |
]. |
|
382 |
Transcript showCR:'Found javaHome in: ' , jHome. |
|
188 | 383 |
|
239 | 384 |
self javaHome:jHome. |
364 | 385 |
self classPath:(Array with:jClasses pathName). |
386 |
||
387 |
(jSources := jHome asFilename construct:'source') exists ifFalse:[ |
|
388 |
(jSources := jHome asFilename construct:'src') exists ifFalse:[ |
|
389 |
(jSources := jHome asFilename construct:'sources') exists ifFalse:[ |
|
390 |
jSources := nil. |
|
391 |
] |
|
392 |
] |
|
393 |
]. |
|
394 |
||
395 |
jSources isNil ifTrue:[ |
|
396 |
Transcript showCR:'no java source directory found'. |
|
397 |
] ifFalse:[ |
|
398 |
Transcript showCR:'Found javaSources in: ' , jSources pathName. |
|
399 |
self sourceDirectories:(Array with:jSources pathName). |
|
400 |
]. |
|
188 | 401 |
|
367 | 402 |
directoriesToSearch := OrderedCollection new. |
403 |
directoriesToSearch add:'/usr/local/java/moz3_0/lib_unix'. |
|
404 |
||
405 |
directoriesToSearch do:[:aPath | |
|
406 |
|dir classDir| |
|
407 |
||
408 |
dir := aPath asFilename. |
|
409 |
(mozillaHome isNil and:[dir exists]) ifTrue:[ |
|
410 |
mozillaHome := dir. |
|
411 |
classDir := (dir construct:'classes'). |
|
412 |
Java addToClassPath:classDir pathName. |
|
413 |
"/ |
|
414 |
"/ care to only load mozilla classes from there ... |
|
415 |
"/ i.e. ignore the java/sun stuff found there. |
|
416 |
"/ |
|
417 |
ExcludedClassPath add:(classDir construct:'java') pathName. |
|
418 |
ExcludedClassPath add:(classDir construct:'sun') pathName. |
|
419 |
] |
|
241 | 420 |
]. |
188 | 421 |
self initializePrettyPrintStyle. |
422 |
||
274 | 423 |
" |
364 | 424 |
Java initialize. |
274 | 425 |
JavaVM initializeVM |
426 |
" |
|
76 | 427 |
|
367 | 428 |
"Modified: / 12.9.1998 / 16:44:48 / cg" |
188 | 429 |
! |
430 |
||
431 |
initializePrettyPrintStyle |
|
432 |
PrettyPrintStyle := IdentityDictionary new. |
|
433 |
PrettyPrintStyle at:#accessAttribute put:(#color -> (Color red:0 green:0 blue:25)). |
|
434 |
PrettyPrintStyle at:#className put:(Array with:(#color -> Color black) with:#bold). |
|
435 |
PrettyPrintStyle at:#methodName put:(Array with:(#color -> Color black) with:#bold). |
|
436 |
PrettyPrintStyle at:#code put:(#color -> Color black). |
|
437 |
||
438 |
||
439 |
" |
|
440 |
Java initializePrettyPrintStyle |
|
441 |
" |
|
442 |
||
443 |
"Created: 1.8.1997 / 11:08:43 / cg" |
|
444 |
"Modified: 1.8.1997 / 11:09:58 / cg" |
|
76 | 445 |
! |
446 |
||
47 | 447 |
reinitAllClasses |
448 |
self markAllClassesUninitialized. |
|
449 |
self initAllClasses |
|
252 | 450 |
|
451 |
" |
|
452 |
Java reinitAllClasses |
|
453 |
" |
|
454 |
||
455 |
"Modified: / 4.1.1998 / 00:34:29 / cg" |
|
248 | 456 |
! |
457 |
||
458 |
reinitialize |
|
459 |
"/ all JavaThreads are lost on a restart (for now) |
|
460 |
||
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
461 |
FailedToLoadClasses := nil. |
248 | 462 |
Threads := nil. |
463 |
||
285 | 464 |
" |
465 |
Java reinitialize |
|
466 |
" |
|
248 | 467 |
|
285 | 468 |
"Created: / 26.8.1997 / 20:07:00 / cg" |
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
469 |
"Modified: / 27.4.1998 / 14:57:23 / cg" |
248 | 470 |
! |
471 |
||
472 |
startupJavaSystem |
|
301
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
473 |
|haveEventThread haveScreenUpdater| |
285 | 474 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
475 |
FailedToLoadClasses := nil. |
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
476 |
|
248 | 477 |
"/ |
478 |
"/ check if already running |
|
479 |
"/ |
|
301
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
480 |
|
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
481 |
haveEventThread := true. |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
482 |
(JavaEventThread isNil or:[JavaEventThread isDead]) ifTrue:[ |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
483 |
haveEventThread := false |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
484 |
]. |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
485 |
|
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
486 |
haveScreenUpdater := false. |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
487 |
haveEventThread ifTrue:[ |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
488 |
self threads do:[:aJavaThread | |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
489 |
aJavaThread name = 'JAVA-Screen Updater' ifTrue:[ |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
490 |
aJavaThread isDead ifFalse:[ |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
491 |
"/ already running |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
492 |
haveScreenUpdater := true |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
493 |
] |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
494 |
] |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
495 |
]. |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
496 |
]. |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
497 |
|
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
498 |
(haveEventThread and:[haveScreenUpdater]) ifTrue:[ |
2945ec2eee92
better reinit (look for both event-thread AND screenUpdater thread)
cg
parents:
285
diff
changeset
|
499 |
^ self |
248 | 500 |
]. |
501 |
||
502 |
'JAVA [info]: (re)initializing JAVA environment completely ...' infoPrintCR. |
|
285 | 503 |
|
255 | 504 |
JavaVM initializeVM. |
285 | 505 |
|
248 | 506 |
'JAVA [info]: done JAVA initialization.' infoPrintCR. |
507 |
||
285 | 508 |
" |
509 |
Java startupJavaSystem |
|
510 |
" |
|
248 | 511 |
|
340
79f09bb1ac21
remember classes which failed to load - dont try those again.
cg
parents:
324
diff
changeset
|
512 |
"Modified: / 27.4.1998 / 14:57:35 / cg" |
248 | 513 |
! |
514 |
||
515 |
terminateAllThreads |
|
305 | 516 |
|myself threadsToKill| |
248 | 517 |
|
518 |
Threads isNil ifTrue:[ |
|
270 | 519 |
^ self |
248 | 520 |
]. |
521 |
||
522 |
myself := Processor activeProcess. |
|
523 |
||
305 | 524 |
threadsToKill := IdentitySet new. |
248 | 525 |
Threads do:[:aJavaThread | |
270 | 526 |
aJavaThread ~~ myself ifTrue:[ |
527 |
(aJavaThread isNil or:[aJavaThread == 0]) ifFalse:[ |
|
528 |
(aJavaThread isMemberOf:JavaProcess) ifTrue:[ |
|
529 |
aJavaThread isDead ifFalse:[ |
|
305 | 530 |
threadsToKill add:aJavaThread |
270 | 531 |
] |
532 |
] |
|
533 |
] |
|
534 |
] |
|
248 | 535 |
]. |
305 | 536 |
threadsToKill do:[:aThread | |
537 |
aThread terminate |
|
538 |
]. |
|
248 | 539 |
Threads := nil. |
540 |
||
541 |
" |
|
542 |
Java terminateAllThreads |
|
543 |
" |
|
544 |
||
270 | 545 |
"Created: / 26.8.1997 / 19:57:40 / cg" |
305 | 546 |
"Modified: / 1.2.1998 / 20:11:56 / cg" |
47 | 547 |
! ! |
548 |
||
135 | 549 |
!Java class methodsFor:'enumerating'! |
43 | 550 |
|
90 | 551 |
allClasses |
208 | 552 |
^ Classes ? #() |
553 |
||
280 | 554 |
" |
555 |
|if| |
|
556 |
||
557 |
if := Java at:'java.awt.GraphicsEnvironment'. |
|
558 |
Java allClasses select:[:aClass | |
|
559 |
aClass hasInterface:if |
|
560 |
] |
|
561 |
" |
|
562 |
||
563 |
"Modified: / 28.1.1998 / 01:42:04 / cg" |
|
90 | 564 |
! |
565 |
||
43 | 566 |
allClassesDo:aBlock |
567 |
Classes notNil ifTrue:[ |
|
248 | 568 |
Classes do:aBlock |
43 | 569 |
] |
570 |
! ! |
|
571 |
||
205 | 572 |
!Java class methodsFor:'object conversions'! |
573 |
||
574 |
as_Float:aNumber |
|
575 |
"convert an ST-float into a Java Float" |
|
576 |
||
577 |
|i| |
|
578 |
||
579 |
i := (Java at:'java.lang.Float') new. |
|
261 | 580 |
i perform:#'<init>(F)V' with:(aNumber asShortFloat). |
205 | 581 |
^ i |
582 |
||
583 |
" |
|
584 |
Java as_Float:1 |
|
585 |
Java as_Float:3.14159 |
|
586 |
" |
|
587 |
||
588 |
"Created: 7.8.1997 / 21:21:13 / cg" |
|
589 |
"Modified: 7.8.1997 / 21:22:05 / cg" |
|
590 |
! |
|
591 |
||
592 |
as_Hashtable:aDictionary |
|
261 | 593 |
"given a smalltalk dictionary, create and return |
594 |
a Java hashTable for it" |
|
595 |
||
205 | 596 |
|hashTable| |
597 |
||
598 |
hashTable := (self classForName:'java.util.Hashtable') new. |
|
599 |
aDictionary keysAndValuesDo:[:k :v | |
|
261 | 600 |
|sk sv jk jv| |
205 | 601 |
|
261 | 602 |
(sk := k) isSymbol ifTrue:[ |
603 |
sk := sk asString |
|
604 |
]. |
|
605 |
(sv := v) isSymbol ifTrue:[ |
|
606 |
sv := sv asString |
|
607 |
]. |
|
608 |
jk := self as_Object:sk. |
|
609 |
jv := self as_Object:sv. |
|
255 | 610 |
|
261 | 611 |
hashTable |
612 |
perform:#'put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;' |
|
613 |
with:jk |
|
614 |
with:jv. |
|
205 | 615 |
]. |
616 |
^ hashTable |
|
617 |
||
618 |
" |
|
619 |
Java as_Hashtable:(Dictionary new |
|
261 | 620 |
at:'hello' put:'Hallo'; |
621 |
at:'world' put:'Welt'; |
|
622 |
yourself) |
|
205 | 623 |
" |
624 |
||
261 | 625 |
"Modified: / 14.1.1998 / 17:02:13 / cg" |
205 | 626 |
! |
627 |
||
628 |
as_Integer:anInteger |
|
629 |
"convert an ST-integer into a Java Integer" |
|
630 |
||
631 |
|i| |
|
632 |
||
633 |
i := (Java at:'java.lang.Integer') new. |
|
261 | 634 |
i perform:#'<init>(I)V' with:anInteger. |
205 | 635 |
^ i |
636 |
||
637 |
" |
|
638 |
Java as_Integer:1 |
|
639 |
" |
|
640 |
||
641 |
"Modified: 7.8.1997 / 21:19:37 / cg" |
|
642 |
"Created: 7.8.1997 / 21:21:13 / cg" |
|
643 |
! |
|
644 |
||
645 |
as_Object:anObject |
|
646 |
"convert an ST-Object into a Java Object" |
|
647 |
||
648 |
anObject isString ifTrue:[ |
|
248 | 649 |
^ self as_String:anObject |
205 | 650 |
]. |
651 |
anObject isInteger ifTrue:[ |
|
248 | 652 |
^ self as_Integer:anObject |
205 | 653 |
]. |
654 |
||
655 |
self halt. |
|
656 |
||
657 |
" |
|
658 |
Java as_Object:'hello world' |
|
659 |
" |
|
660 |
||
661 |
"Created: 7.8.1997 / 21:15:38 / cg" |
|
662 |
"Modified: 7.8.1997 / 21:20:07 / cg" |
|
663 |
! |
|
664 |
||
665 |
as_ST_String:aJavaString |
|
666 |
"hard-coding internas of java.lang.String here is bad ..." |
|
667 |
||
255 | 668 |
|str count start stop| |
669 |
||
670 |
"/ count := aJavaString instVarNamed:'count'. |
|
671 |
count := aJavaString instVarAt:(JavaSlotIndexCache string_slot_count). |
|
672 |
||
673 |
"/ str := aJavaString instVarNamed:'value' |
|
674 |
str := aJavaString instVarAt:(JavaSlotIndexCache string_slot_value). |
|
675 |
||
676 |
str size == count ifTrue:[ |
|
261 | 677 |
^ str |
255 | 678 |
]. |
205 | 679 |
|
680 |
"/ start := (aJavaString instVarNamed:'offset') + 1. |
|
681 |
start := (aJavaString instVarAt:(JavaSlotIndexCache string_slot_offset)) + 1. |
|
682 |
||
683 |
"/ stop := start + (aJavaString instVarNamed:'count') - 1. |
|
684 |
stop := start + (aJavaString instVarAt:(JavaSlotIndexCache string_slot_count)) - 1. |
|
685 |
||
686 |
"/ ^ ((aJavaString instVarNamed:'value') copyFrom:start to:stop) asString |
|
687 |
^ ((aJavaString instVarAt:(JavaSlotIndexCache string_slot_value)) |
|
261 | 688 |
copyFrom:start to:stop) asString |
205 | 689 |
|
255 | 690 |
"Created: / 8.8.1997 / 12:02:55 / cg" |
691 |
"Modified: / 9.1.1998 / 23:55:39 / cg" |
|
205 | 692 |
! |
693 |
||
694 |
as_String:aString |
|
695 |
"convert an ST-String into a Java String" |
|
696 |
||
697 |
"hard-coding internas of java.lang.String here is bad ..." |
|
698 |
||
699 |
|s| |
|
700 |
||
701 |
s := Java_lang_String basicNew. |
|
702 |
s instVarNamed:'value' put: aString. |
|
703 |
s instVarNamed:'offset' put: 0. |
|
704 |
s instVarNamed:'count' put: aString size. |
|
705 |
^ s |
|
706 |
||
707 |
" |
|
708 |
Java as_String:'hello world' |
|
709 |
" |
|
710 |
||
711 |
"Created: 7.8.1997 / 21:15:49 / cg" |
|
712 |
"Modified: 7.8.1997 / 21:19:37 / cg" |
|
713 |
! |
|
714 |
||
715 |
as_URL:aString |
|
716 |
"convert an ST-String into a Java String" |
|
717 |
||
718 |
"hard-coding internas of java.lang.String here is bad ..." |
|
719 |
||
720 |
|u| |
|
721 |
||
722 |
u := (self at:'java.net.URL') basicNew. |
|
261 | 723 |
u perform:#'<init>(Ljava/lang/String;)V' with:(self as_String:aString). |
205 | 724 |
^ u |
725 |
||
726 |
" |
|
727 |
Java as_URL:'http://www.altavista.com' |
|
728 |
Java as_URL:'file:/foo/bar' |
|
729 |
" |
|
730 |
||
731 |
"Created: 7.8.1997 / 21:15:49 / cg" |
|
732 |
"Modified: 7.8.1997 / 21:26:42 / cg" |
|
733 |
! ! |
|
734 |
||
168 | 735 |
!Java class methodsFor:'queries'! |
736 |
||
737 |
smalltalkClassFor:typeRef |
|
738 |
self halt. |
|
739 |
"/ (typeString startsWith:'[[') ifTrue:[ |
|
740 |
"/ ^ Array |
|
741 |
"/ ]. |
|
742 |
"/ (typeString startsWith:'[F') ifTrue:[ |
|
743 |
"/ ^ FloatArray |
|
744 |
"/ ]. |
|
745 |
self halt. |
|
746 |
||
747 |
"Modified: 7.4.1997 / 13:33:46 / cg" |
|
748 |
! |
|
749 |
||
750 |
smalltalkDerefType:typeString |
|
751 |
(typeString startsWith:'[') ifTrue:[ |
|
248 | 752 |
^ typeString copyFrom:2 |
168 | 753 |
]. |
754 |
self halt. |
|
755 |
||
756 |
"Modified: 7.4.1997 / 13:13:24 / cg" |
|
757 |
! ! |
|
758 |
||
135 | 759 |
!Java class methodsFor:'registering java classes'! |
17 | 760 |
|
761 |
at:aJavaName |
|
43 | 762 |
"search & return for a class by name; |
763 |
if there is no such class, return nil. |
|
764 |
The argument, aJavaName may be either an internal name |
|
765 |
(sep'd by slashes) or an external name (sep'd by periods). |
|
766 |
The 'java/lang' standard packages prefix may be ommitted." |
|
767 |
||
768 |
|sym nm cls| |
|
769 |
||
17 | 770 |
Classes isNil ifTrue:[^ nil]. |
43 | 771 |
|
772 |
sym := aJavaName asSymbolIfInterned. |
|
773 |
sym notNil ifTrue:[ |
|
360 | 774 |
cls := Classes at:sym ifAbsent:nil. |
775 |
cls notNil ifTrue:[^ cls]. |
|
43 | 776 |
]. |
17 | 777 |
|
43 | 778 |
nm := aJavaName. |
779 |
(nm includes:$.) ifTrue:[ |
|
360 | 780 |
nm := (nm asString copyReplaceAll:$. with:$/). |
781 |
sym := nm asSymbolIfInterned. |
|
782 |
sym notNil ifTrue:[ |
|
783 |
cls := Classes at:sym ifAbsent:nil. |
|
784 |
cls notNil ifTrue:[^ cls]. |
|
785 |
]. |
|
43 | 786 |
]. |
787 |
||
788 |
(nm includes:$/) ifFalse:[ |
|
360 | 789 |
"/ |
790 |
"/ try java.lang.Foo |
|
791 |
"/ |
|
792 |
nm := 'java/lang/' , nm. |
|
793 |
sym := nm asSymbolIfInterned. |
|
794 |
sym notNil ifTrue:[ |
|
795 |
cls := Classes at:sym ifAbsent:nil. |
|
796 |
cls notNil ifTrue:[^ cls]. |
|
797 |
]. |
|
43 | 798 |
]. |
799 |
||
800 |
^ nil |
|
801 |
||
802 |
" |
|
803 |
Java at:'java/lang/String' |
|
804 |
Java at:'java.lang.String' |
|
805 |
Java at:'String' |
|
806 |
Java at:'System' |
|
807 |
Java at:'Foo' |
|
808 |
" |
|
360 | 809 |
|
810 |
"Modified: / 18.7.1998 / 22:55:16 / cg" |
|
17 | 811 |
! |
812 |
||
813 |
at:aJavaName put:aJavaClass |
|
90 | 814 |
|nameSymbol| |
815 |
||
17 | 816 |
Classes isNil ifTrue:[ |
248 | 817 |
Classes := IdentityDictionary new. |
17 | 818 |
]. |
90 | 819 |
|
820 |
nameSymbol := aJavaName asSymbol. |
|
821 |
(Classes includesKey:nameSymbol) ifTrue:[ |
|
248 | 822 |
('JAVA: class ' , aJavaName , ' is already loaded') infoPrintCR. |
823 |
self updateClassRefsFrom:(Classes at:nameSymbol) to:aJavaClass. |
|
65 | 824 |
]. |
54 | 825 |
|
90 | 826 |
Classes at:nameSymbol put:aJavaClass. |
827 |
nameSymbol == #'java/lang/String' ifTrue:[ |
|
248 | 828 |
Java_lang_String := aJavaClass |
90 | 829 |
]. |
21 | 830 |
|
43 | 831 |
"/ UnresolvedClassRefs notNil ifTrue:[ |
832 |
"/ UnresolvedClassRefs do:[:toResolve | |
|
833 |
"/ ] |
|
834 |
"/ ]. |
|
835 |
||
27 | 836 |
self changed:#classes |
17 | 837 |
|
838 |
"Created: 17.4.1996 / 23:29:31 / cg" |
|
205 | 839 |
"Modified: 7.8.1997 / 19:15:58 / cg" |
21 | 840 |
! |
841 |
||
168 | 842 |
flushAllJavaResources |
843 |
self flushClasses. |
|
844 |
||
845 |
ObjectMemory allObjectsDo:[:someObject | |
|
318 | 846 |
someObject isBehavior ifTrue:[ |
847 |
someObject isJavaClass ifTrue:[ |
|
848 |
someObject setConstantPool:nil. |
|
849 |
someObject setInterfaces:nil. |
|
850 |
someObject setMethodDictionary:(MethodDictionary new). |
|
851 |
'JAVA [info]: flushing ' print. someObject fullName printCR. |
|
852 |
] |
|
853 |
]. |
|
854 |
(someObject isMemberOf:JavaMethod) ifTrue:[ |
|
855 |
someObject setJavaClass:nil. |
|
856 |
someObject setExceptionTable:nil. |
|
857 |
]. |
|
858 |
(someObject isMemberOf:JavaUnresolvedClassConstant) ifTrue:[ |
|
859 |
someObject constantPool:nil |
|
860 |
]. |
|
168 | 861 |
]. |
862 |
self flushClasses |
|
863 |
||
864 |
" |
|
865 |
Java flushAllJavaResources |
|
866 |
" |
|
867 |
||
318 | 868 |
"Modified: / 6.2.1998 / 02:25:16 / cg" |
168 | 869 |
! |
870 |
||
21 | 871 |
flushClasses |
167 | 872 |
Classes := UnresolvedClassRefs := nil. |
168 | 873 |
Smalltalk keys copy do:[:aKey | |
248 | 874 |
(aKey startsWith:'JAVA::') ifTrue:[ Smalltalk removeKey:aKey ] |
168 | 875 |
]. |
167 | 876 |
Java_lang_String := Java_lang_Class := nil. |
261 | 877 |
JavaVM releaseAllJavaResources. |
90 | 878 |
JavaUnresolvedConstant flushPatchLists. |
21 | 879 |
|
880 |
" |
|
881 |
Java flushClasses |
|
882 |
" |
|
883 |
||
168 | 884 |
"Modified: 7.4.1997 / 15:25:46 / cg" |
21 | 885 |
! |
886 |
||
43 | 887 |
markAllClassesUninitialized |
888 |
self allClassesDo:[:aJavaClass | |
|
248 | 889 |
aJavaClass markUninitialized |
43 | 890 |
]. |
891 |
||
892 |
" |
|
893 |
Java markAllClassesUninitialized |
|
894 |
" |
|
895 |
! |
|
896 |
||
21 | 897 |
rememberUnresolved:anUnresolvedClassRef |
90 | 898 |
('JAVA: remember unresolved class: ' , anUnresolvedClassRef fullName) infoPrintCR. |
899 |
||
900 |
UnresolvedClassRefs isNil ifTrue:[ |
|
248 | 901 |
UnresolvedClassRefs := Set new. |
90 | 902 |
]. |
903 |
UnresolvedClassRefs add:anUnresolvedClassRef |
|
21 | 904 |
|
905 |
"Created: 18.4.1996 / 00:05:31 / cg" |
|
906 |
"Modified: 18.4.1996 / 00:05:41 / cg" |
|
90 | 907 |
! |
908 |
||
162 | 909 |
removeClass:aJavaClass |
910 |
"/ remove it from myself |
|
911 |
||
912 |
|javaName sym nm cls | |
|
913 |
||
914 |
javaName := aJavaClass fullName. |
|
915 |
||
916 |
sym := javaName asSymbolIfInterned. |
|
917 |
sym notNil ifTrue:[ |
|
360 | 918 |
cls := Classes at:sym ifAbsent:nil. |
162 | 919 |
]. |
920 |
cls isNil ifTrue:[ |
|
360 | 921 |
nm := javaName. |
922 |
(nm includes:$.) ifTrue:[ |
|
923 |
"/ |
|
924 |
"/ try pckg/.../name |
|
925 |
"/ |
|
926 |
nm := (nm asString copyReplaceAll:$. with:$/). |
|
927 |
sym := nm asSymbolIfInterned. |
|
928 |
sym notNil ifTrue:[ |
|
929 |
cls := Classes at:sym ifAbsent:nil. |
|
930 |
]. |
|
931 |
]. |
|
162 | 932 |
]. |
212 | 933 |
(cls notNil and:[cls == aJavaClass]) ifTrue:[ |
360 | 934 |
Classes removeKey:sym. |
935 |
self updateClassRefsFrom:aJavaClass to:nil. |
|
162 | 936 |
]. |
212 | 937 |
Smalltalk removeKey:('JAVA::' , aJavaClass fullName) asSymbol. |
162 | 938 |
|
212 | 939 |
"Modified: 12.8.1997 / 02:54:34 / cg" |
162 | 940 |
! |
941 |
||
90 | 942 |
unresolvedClassRefFor:aClassName |
943 |
UnresolvedClassRefs isNil ifTrue:[^ nil]. |
|
944 |
^ UnresolvedClassRefs at:aClassName ifAbsent:nil. |
|
167 | 945 |
! |
946 |
||
947 |
updateClassRefsFrom:oldClass to:newClass |
|
948 |
"update all references to oldClass to now refer to newClass. |
|
949 |
sent, when a class is reloaded" |
|
950 |
||
214 | 951 |
newClass notNil ifTrue:[ |
248 | 952 |
"/ |
953 |
"/ kludge: the new class might have been resolved with the oldClass ... |
|
954 |
"/ |
|
955 |
newClass constantPool |
|
956 |
updateClassRefsFrom:oldClass to:newClass. |
|
214 | 957 |
]. |
205 | 958 |
|
203 | 959 |
self allClassesDo:[:aJavaClass | |
248 | 960 |
aJavaClass updateClassRefsFrom:oldClass to:newClass |
203 | 961 |
]. |
167 | 962 |
|
963 |
"Created: 26.3.1997 / 13:49:20 / cg" |
|
214 | 964 |
"Modified: 12.8.1997 / 03:04:44 / cg" |
17 | 965 |
! ! |
966 |
||
135 | 967 |
!Java class methodsFor:'source management'! |
76 | 968 |
|
969 |
classSourceOf:aClass |
|
261 | 970 |
|package dirName binary sourceFileName sourceFile dirHolder fileName path |
971 |
loader codeBaseURL protocol dir file| |
|
76 | 972 |
|
973 |
aClass isNil ifTrue:[ |
|
267 | 974 |
^ nil |
76 | 975 |
]. |
976 |
||
977 |
"/ first, look in the directory, where the binary |
|
978 |
"/ was loaded from. |
|
979 |
||
198 | 980 |
binary := aClass binaryFile. |
981 |
binary notNil ifTrue:[ |
|
267 | 982 |
binary := binary asFilename. |
324 | 983 |
aClass sourceFile notNil ifTrue:[ |
984 |
sourceFileName := binary directory constructString:(aClass sourceFile). |
|
985 |
sourceFileName asFilename exists ifFalse:[ |
|
986 |
sourceFileName := nil. |
|
987 |
] |
|
988 |
]. |
|
989 |
sourceFileName isNil ifTrue:[ |
|
990 |
sourceFileName := binary withSuffix:'java'. |
|
991 |
]. |
|
267 | 992 |
sourceFile := sourceFileName asFilename. |
261 | 993 |
] ifFalse:[ |
267 | 994 |
"/ maybe it was loaded by a java classLoader ... |
995 |
(loader := aClass classLoader) notNil ifTrue:[ |
|
996 |
(codeBaseURL := loader instVarNamed:'codeBaseURL') notNil ifTrue:[ |
|
997 |
(protocol := codeBaseURL instVarNamed:'protocol') notNil ifTrue:[ |
|
998 |
(Java as_ST_String:protocol) = 'file' ifTrue:[ |
|
999 |
dirName := Java as_ST_String:(codeBaseURL instVarNamed:'file'). |
|
1000 |
dirName asFilename exists ifTrue:[ |
|
1001 |
aClass sourceFile notNil ifTrue:[ |
|
1002 |
sourceFileName := dirName asFilename construct:aClass sourceFile. |
|
1003 |
sourceFile := sourceFileName asFilename. |
|
1004 |
] |
|
1005 |
] |
|
1006 |
] |
|
1007 |
] |
|
1008 |
] |
|
1009 |
] |
|
198 | 1010 |
]. |
1011 |
sourceFile notNil ifTrue:[ |
|
267 | 1012 |
sourceFile exists ifFalse:[ |
1013 |
binary notNil ifTrue:[ |
|
1014 |
sourceFileName := binary withSuffix:'jav'. |
|
1015 |
sourceFile := sourceFileName asFilename. |
|
1016 |
sourceFile exists ifFalse:[ |
|
1017 |
sourceFileName := binary withSuffix:'JAV'. |
|
1018 |
sourceFile := sourceFileName asFilename. |
|
1019 |
sourceFile exists ifFalse:[ |
|
1020 |
sourceFileName := binary withSuffix:'JAVA'. |
|
1021 |
sourceFile := sourceFileName asFilename. |
|
1022 |
]. |
|
1023 |
]. |
|
1024 |
] |
|
1025 |
]. |
|
76 | 1026 |
]. |
1027 |
||
176 | 1028 |
"/ special case: there were multiple classes in a single |
76 | 1029 |
"/ source file. |
1030 |
||
198 | 1031 |
binary notNil ifTrue:[ |
267 | 1032 |
binary withoutSuffix baseName ~= aClass sourceFile asFilename withoutSuffix baseName ifTrue:[ |
1033 |
'JAVA: trouble extracting fileName: ' print. |
|
1034 |
binary withoutSuffix baseName print. ' vs. ' print. |
|
1035 |
aClass sourceFile asFilename withoutSuffix baseName printCR. |
|
1036 |
]. |
|
76 | 1037 |
]. |
1038 |
||
1039 |
"/ if that fails, look in standard places |
|
1040 |
||
198 | 1041 |
(sourceFile isNil or:[sourceFile exists not]) ifTrue:[ |
324 | 1042 |
package := aClass package. |
1043 |
||
267 | 1044 |
sourceFileName := aClass sourceFile. |
1045 |
sourceFile := sourceFileName asFilename. |
|
1046 |
sourceFile exists ifFalse:[ |
|
1047 |
"/ |
|
1048 |
"/ mhmh - look for its directory |
|
1049 |
"/ |
|
1050 |
dirName := sourceFile directoryName. |
|
1051 |
fileName := sourceFile baseName. |
|
76 | 1052 |
|
267 | 1053 |
(dirName asFilename exists |
1054 |
and:[(dirName asFilename construct:(package , '/' , fileName)) exists]) |
|
1055 |
ifFalse:[ |
|
1056 |
(dirName asFilename exists |
|
1057 |
and:[(dirName asFilename construct:(fileName)) exists]) |
|
1058 |
ifFalse:[ |
|
1059 |
dirName := self findSourceDirOf:fileName inPackage:package. |
|
76 | 1060 |
|
1061 |
"/ [dirName isNil] whileTrue:[ |
|
1062 |
"/ dirName := Dialog requestDirectoryName:'top directory for ' , package , '/' , fileName. |
|
1063 |
"/ (dirName isNil or:[dirName isEmpty]) ifTrue:[^ self]. |
|
1064 |
"/ ]. |
|
267 | 1065 |
]. |
1066 |
]. |
|
76 | 1067 |
|
267 | 1068 |
(dirName notNil and:[dirName asFilename exists]) ifTrue:[ |
1069 |
path := (dirName asFilename construct:(package , '/' , fileName)) asFilename. |
|
1070 |
path exists ifFalse:[ |
|
1071 |
path := (dirName asFilename construct:(fileName)) asFilename. |
|
1072 |
]. |
|
1073 |
]. |
|
76 | 1074 |
|
267 | 1075 |
(path notNil and:[path exists]) ifFalse:[ |
1076 |
^ nil |
|
1077 |
]. |
|
76 | 1078 |
|
267 | 1079 |
sourceFile := path asFilename. |
1080 |
]. |
|
76 | 1081 |
]. |
1082 |
^ (sourceFile contentsOfEntireFile). |
|
1083 |
||
324 | 1084 |
"Modified: / 29.3.1998 / 11:55:46 / cg" |
76 | 1085 |
! |
1086 |
||
1087 |
findSourceDirOf:fileName inPackage:aPackage |
|
1088 |
SourceDirectories notNil ifTrue:[ |
|
324 | 1089 |
SourceDirectories do:[:aDir | |
1090 |
aPackage notNil ifTrue:[ |
|
1091 |
(aDir asFilename construct:('/' , aPackage , '/' , fileName)) |
|
1092 |
asFilename exists ifTrue:[ |
|
1093 |
^ aDir |
|
1094 |
]. |
|
1095 |
]. |
|
1096 |
(aDir asFilename construct:('/' , fileName)) |
|
1097 |
asFilename exists ifTrue:[ |
|
1098 |
^ aDir |
|
1099 |
]. |
|
1100 |
] |
|
76 | 1101 |
]. |
1102 |
^ nil |
|
1103 |
||
324 | 1104 |
"Modified: / 29.3.1998 / 21:46:40 / cg" |
76 | 1105 |
! ! |
1106 |
||
224 | 1107 |
!Java class methodsFor:'starting apps'! |
1108 |
||
261 | 1109 |
executeMainOf:aClass |
1110 |
"execute main of aClass in a separate thread and wait until that thread |
|
1111 |
has terminated." |
|
1112 |
||
1113 |
|p| |
|
1114 |
||
1115 |
p := self javaProcessForMainOf:aClass. |
|
1116 |
p notNil ifTrue:[ |
|
1117 |
p resume. |
|
1118 |
Object abortSignal handle:[:ex | |
|
1119 |
p terminate. |
|
1120 |
ex reject. |
|
1121 |
] do:[ |
|
1122 |
p waitUntilTerminated |
|
1123 |
]. |
|
1124 |
] |
|
1125 |
||
1126 |
"Modified: / 15.1.1998 / 02:15:13 / cg" |
|
1127 |
"Created: / 15.1.1998 / 17:14:55 / cg" |
|
1128 |
! |
|
1129 |
||
313 | 1130 |
executeMainOf:aClass withArgumentString:commandLineString |
1131 |
"execute main of aClass in a separate thread and wait until that thread |
|
1132 |
has terminated." |
|
1133 |
||
1134 |
|p| |
|
1135 |
||
1136 |
p := self javaProcessForMainOf:aClass argumentString:commandLineString. |
|
1137 |
p notNil ifTrue:[ |
|
1138 |
p resume. |
|
1139 |
Object abortSignal handle:[:ex | |
|
1140 |
p terminate. |
|
1141 |
ex reject. |
|
1142 |
] do:[ |
|
1143 |
p waitUntilTerminated |
|
1144 |
]. |
|
1145 |
] |
|
1146 |
||
1147 |
"Modified: / 5.2.1998 / 00:38:22 / cg" |
|
1148 |
"Created: / 5.2.1998 / 00:40:38 / cg" |
|
1149 |
! |
|
1150 |
||
224 | 1151 |
javaProcessForMainOf:aJavaClass |
1152 |
"ask for a commandLine, create a java process to invoke |
|
1153 |
its main and return it. The process is not scheduled for |
|
1154 |
execution." |
|
1155 |
||
1156 |
|args| |
|
1157 |
||
1158 |
args := Dialog |
|
261 | 1159 |
request:'argument string:' |
1160 |
initialAnswer:LastArgumentString ? '' |
|
1161 |
onCancel:nil. |
|
228 | 1162 |
args isNil ifTrue:[^ nil]. |
224 | 1163 |
|
1164 |
LastArgumentString := args. |
|
1165 |
||
1166 |
^ self javaProcessForMainOf:aJavaClass argumentString:args. |
|
1167 |
||
255 | 1168 |
"Created: / 15.8.1997 / 04:51:46 / cg" |
1169 |
"Modified: / 9.1.1998 / 18:01:47 / cg" |
|
224 | 1170 |
! |
1171 |
||
1172 |
javaProcessForMainOf:aJavaClass argumentString:argString |
|
1173 |
"create a java process, ready to invoke the classes main |
|
1174 |
method. Returns the process - ready to run but not yet resumed" |
|
1175 |
||
1176 |
|p argStringArray t| |
|
1177 |
||
261 | 1178 |
JavaVM initializeVMIfNoEventThreadRunning. |
1179 |
(Java at:'java.lang.System') instVarNamed:'security' put:nil. |
|
1180 |
||
224 | 1181 |
argString isEmpty ifTrue:[ |
252 | 1182 |
argStringArray := #() |
224 | 1183 |
] ifFalse:[ |
252 | 1184 |
argStringArray := argString asCollectionOfWords asArray |
1185 |
collect:[:s | Java as_String:s]. |
|
224 | 1186 |
]. |
1187 |
||
1188 |
p := JavaProcess |
|
252 | 1189 |
for:[ |
1190 |
aJavaClass |
|
1191 |
invoke:#'main' |
|
1192 |
signature:#'([Ljava/lang/String;)V' |
|
1193 |
with:argStringArray |
|
1194 |
] |
|
1195 |
priority:(Processor activePriority - 1). |
|
224 | 1196 |
|
1197 |
p name:(aJavaClass fullName , '::main()'). |
|
1198 |
^ p |
|
1199 |
||
252 | 1200 |
"Created: / 15.8.1997 / 04:41:20 / cg" |
261 | 1201 |
"Modified: / 15.1.1998 / 17:33:18 / cg" |
224 | 1202 |
! ! |
1203 |
||
135 | 1204 |
!Java class methodsFor:'documentation'! |
17 | 1205 |
|
1206 |
version |
|
372 | 1207 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/Java.st,v 1.69 1998/10/05 11:47:26 cg Exp $' |
17 | 1208 |
! ! |
76 | 1209 |
Java initialize! |