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