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