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