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