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