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