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