diff -r da0840b7798c -r e898eaeff091 Java.st --- a/Java.st Thu Sep 23 13:52:13 2010 +0000 +++ b/Java.st Fri Aug 19 08:58:19 2011 +0000 @@ -1,6 +1,10 @@ " - COPYRIGHT (c) 1997 by eXept Software AG - All Rights Reserved + COPYRIGHT (c) 1996-2011 by Claus Gittinger + COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko + SWING Research Group, Czech Technical University in Prague + + Parts of the code written by Claus Gittinger are under following + license: This software is furnished under a license and may be used only in accordance with the terms of that license and with the @@ -8,14 +12,42 @@ be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred. + + Parts of the code written at SWING Reasearch Group [1] are MIT licensed: + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the 'Software'), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + [1] Code written at SWING Research Group contain a signature + of one of the above copright owners. " "{ Package: 'stx:libjava' }" Object subclass:#Java instanceVariableNames:'' - classVariableNames:'Classes UnresolvedClassRefs ClassPath SourceDirectories JavaHome - InternedStrings Java_lang_String Java_lang_Class PrettyPrintStyle - LastArgumentString Threads ExcludedClassPath FailedToLoadClasses' + classVariableNames:'Classes UnresolvedClassRefs Release ClassPath SourceDirectories + CacheDirectory JavaHome InternedStrings Java_lang_String + Java_lang_Class PrettyPrintStyle LastArgumentString Threads + ExcludedClassPath FailedToLoadClasses SourceCache + SourceArchiveCache' poolDictionaries:'' category:'Languages-Java-Support' ! @@ -24,8 +56,12 @@ copyright " - COPYRIGHT (c) 1997 by eXept Software AG - All Rights Reserved + COPYRIGHT (c) 1996-2011 by Claus Gittinger + COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko + SWING Research Group, Czech Technical University in Prague + + Parts of the code written by Claus Gittinger are under following + license: This software is furnished under a license and may be used only in accordance with the terms of that license and with the @@ -33,9 +69,43 @@ be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred. -" + + Parts of the code written at SWING Reasearch Group [1] are MIT licensed: + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the 'Software'), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + [1] Code written at SWING Research Group contain a signature + of one of the above copright owners. + +" +! + +documentation +"Java class is main entry point or - you might say - +facade to the Java world inside Smalltalk. It also +serves as configuration entity - e.g. controlling +classpath, source paths, etc. Java class is responsible +for correct initialization and glueing other classes. +" ! ! !Java class methodsFor:'accessing'! @@ -43,7 +113,7 @@ classForName:aString "return a javaClass - either existing or loaded" - |cls loader classURL| + |cls loader| cls := self at:aString. cls isNil ifTrue:[ @@ -54,7 +124,7 @@ ] ]. - ('JAVA [info]: late class loading: ' , aString) infoPrintCR. + "/('JAVA [info]: late class loading: ' , aString) infoPrintCR. loader := JavaClassReader classLoaderQuerySignal query. loader isNil ifTrue:[ "/ load using default (ST/X) loader @@ -77,8 +147,9 @@ ]. ^ cls - "Created: / 18.3.1997 / 16:45:57 / cg" - "Modified: / 27.4.1998 / 15:00:52 / cg" + "Created: / 18-03-1997 / 16:45:57 / cg" + "Modified: / 27-04-1998 / 15:00:52 / cg" + "Modified: / 18-08-2011 / 19:30:50 / jv" ! classNamed:aString @@ -123,6 +194,27 @@ "Created: 1.8.1997 / 10:37:57 / cg" ! +release + + ^Release + + "Created: / 22-11-2010 / 12:38:23 / Jan Vrany " +! + +release: aJavaRelease + + Release := aJavaRelease. + + " + Java release: JavaRelease openJDK6. + Java release: JavaRelease sunJDK6. + + " + + "Created: / 22-11-2010 / 12:38:04 / Jan Vrany " + "Modified: / 30-11-2010 / 11:54:33 / Jan Vrany " +! + systemPropertyAt:key put:something JavaVM systemProperties at:key put:something @@ -142,29 +234,109 @@ !Java class methodsFor:'accessing paths'! addToClassPath:aPath - (ClassPath includes:aPath) ifFalse:[ - ClassPath add:aPath. - FailedToLoadClasses := nil + + | path | + path := aPath asFilename. + + (aPath asString includes: $*) ifTrue:[ + self addToClassPathFilesMatching: path baseName + in: path directoryName. + ] ifFalse:[ + (ClassPath includes:aPath asString) ifFalse:[ + ClassPath add:aPath asString. + self addToClassPathInRuntime:aPath. + FailedToLoadClasses := nil + ] ] - "Created: / 1.8.1997 / 21:10:07 / cg" - "Modified: / 17.9.1998 / 20:43:55 / cg" + "Created: / 01-08-1997 / 21:10:07 / cg" + "Modified: / 17-09-1998 / 20:43:55 / cg" + "Modified: / 07-08-2011 / 14:06:46 / Jan Vrany " +! + +addToClassPathFilesMatching: pattern in: path + + | dir | + dir := path asFilename. + dir directoryContents do: + [:fname| + (fname matches: pattern) ifTrue: + [| p | + p := (dir / fname) pathName. + (ClassPath includes:p) ifFalse: + [ClassPath add:p. + self addToClassPathInRuntime:p. + FailedToLoadClasses := nil]]]. + + "Created: / 20-12-2010 / 17:26:18 / Jan Vrany " +! + +addToClassPathInRuntime:aPath + + | path file url scl | + "Java might not be loaded/or initialized, in this case + there is no no need to inform java about new entry in classpath" + + JavaVM booted ifFalse:[^self]. + scl := (Java classForName:'java.lang.ClassLoader') instVarNamed: #scl. + scl ifNil:[ + scl := (Java classForName:'java.lang.ClassLoader') perform: #'getSystemClassLoader()Ljava/lang/ClassLoader;'. + ]. + path := Java as_String: aPath asString. + file := (Java at:'java.io.File') new perform: #'(Ljava/lang/String;)V' with: path; yourself. + url := file perform: #'toURL()Ljava/net/URL;'. + scl perform: #'addURL(Ljava/net/URL;)V' with: url. + + "Created: / 01-08-1997 / 21:10:07 / cg" + "Modified: / 17-09-1998 / 20:43:55 / cg" + "Created: / 07-08-2011 / 14:01:48 / Jan Vrany " ! addToSourcePath:aPath + SourceDirectories ifNil:[SourceDirectories := OrderedCollection new]. (SourceDirectories includes:aPath) ifFalse:[ SourceDirectories add:aPath ] - "Modified: 7.2.1997 / 19:23:55 / cg" - "Created: 2.8.1997 / 14:12:31 / cg" + "Created: / 02-08-1997 / 14:12:31 / cg" + "Modified: / 06-02-2011 / 22:51:26 / Jan Vrany " +! + +cacheDirectory + + CacheDirectory ifNil:[ + CacheDirectory := Filename homeDirectory / '.smalltalk' / 'libjava' / 'caches' / + (((Smalltalk at:#stx_libjava) svnRepositoryUrlBase copyReplaceAll:$/ with:$_) replaceAll:$: with:$_) + ]. + ^CacheDirectory + + "Created: / 08-04-2011 / 15:02:18 / Jan Vrany " + "Modified: / 08-04-2011 / 16:58:52 / Jan Vrany " ! classPath - ^ ClassPath + + | CLASSPATH | + CLASSPATH := ((OperatingSystem getEnvironment: 'CLASSPATH') ? '') + tokensBasedOn: OperatingSystem pathSeparator. - "Created: 7.2.1997 / 19:23:45 / cg" - "Modified: 7.2.1997 / 19:23:55 / cg" + ^ + "for testing only" + "/Release classPath, + (Array + with: ((Smalltalk packageDirectoryForPackageId:'stx:libjava') / 'java' / 'libjava-projects' / 'Conversion' / 'bin' ) pathName + with: ((Smalltalk packageDirectoryForPackageId:'stx:libjava') / 'java' / 'libjava-support' / 'bin' ) pathName + ), + + (ClassPath ? #()), + CLASSPATH + + " + Java classPath + " + + "Created: / 07-02-1997 / 19:23:45 / cg" + "Modified: / 12-08-2011 / 08:57:01 / Jan Vrany " ! classPath:aCollectionOfPaths @@ -175,6 +347,31 @@ "Modified: / 17.9.1998 / 20:44:09 / cg" ! +effectiveClassPath + + ^self release classPath , self classPath + + " + Java effectiveClassPath + " + + "Created: / 22-11-2010 / 13:03:54 / Jan Vrany " + "Modified: / 17-01-2011 / 09:44:16 / kursjan " + "Modified: / 12-08-2011 / 08:57:32 / Jan Vrany " +! + +effectiveSourceDirectories + + ^Release sourcePath , + (SourceDirectories ? #()) + + " + Java effectiveSourceDirectories + " + + "Created: / 30-11-2010 / 11:53:42 / Jan Vrany " +! + excludedClassPath ^ ExcludedClassPath @@ -195,15 +392,22 @@ ! javaHome - ^ JavaHome + ^ JavaHome ifNil:[Release javaHome] - "Created: 6.8.1997 / 00:53:19 / cg" + "Created: / 06-08-1997 / 00:53:19 / cg" + "Modified: / 22-11-2010 / 12:39:19 / Jan Vrany " ! javaHome:aPath + + + + self obsoleteMethodWarning: 'javaHome is now controlled by java release'. + JavaHome := aPath - "Created: 6.8.1997 / 00:53:23 / cg" + "Created: / 06-08-1997 / 00:53:23 / cg" + "Modified: / 22-11-2010 / 12:40:00 / Jan Vrany " ! newJavaHome:newJavaHome @@ -252,6 +456,17 @@ "Created: / 16.1.1998 / 13:26:55 / cg" ! ! +!Java class methodsFor:'change & update'! + +update: what with: param from: sender + + what == #restarted ifTrue:[ + self reinitialize. + ] + + "Created: / 14-12-2010 / 21:00:09 / Jan Vrany " +! ! + !Java class methodsFor:'class initialization'! initAllClasses @@ -316,305 +531,22 @@ ! initialize - |tryJDK1_22 tryJDK1_21 tryJDK1_2 tryJDK1_2beta tryJDK1_18 tryJDK1_17 tryJDK1_16 tryJDK1_15 tryJDK1_13 tryJDK1_11 tryJDK1_03 - tryJDK1_02 directoriesToSearch possibleJavaDirs - jHome jClasses jSources mozillaHome tryNetscape4_0 - tryMS tryBorland tryVA tryJRE1_1 fn d classPath tryJRE6| - JavaNativeMethod flushAllCachedNativeMethods. InternedStrings := Dictionary new. FailedToLoadClasses := nil. - classPath := OperatingSystem getEnvironment:'CLASSPATH'. - "/ those dirs are tried to search for a java system ... - OperatingSystem isUNIXlike ifTrue:[ - possibleJavaDirs := #( - '/opt' - '/opt/java' - '/home/java' - '/home2/java' - '/phys/exept/home/java' - '/phys/exept/home2/java' - '/usr/local/java' - '/usr/local/lib' - '/usr/local' - '/usr/lib' - '/usr/java' - '/usr' - ). - classPath notNil ifTrue:[ - classPath := classPath asCollectionOfSubstringsSeparatedBy:$:. - ]. - ]. - OperatingSystem isMSWINDOWSlike ifTrue:[ - possibleJavaDirs := #( - 'c:\' - 'c:\java\' - 'c:\Programs\' - 'c:\Programme\' - 'c:\Program Files\' - 'c:\Program Files\JavaSoft\' - 'c:\Program Files\JavaSoft\JRE\' - 'd:\' - 'd:\java\' - 'd:\Programs\' - 'd:\Programme\' - 'd:\Program Files\' - 'd:\Program Files\JavaSoft\' - 'd:\Program Files\JavaSoft\JRE\' - 'C:\Program Files\Java\' - '\\exept\home\java\' - '\\exept\home2\java\' - '\\exept\cg\home\java\' - '\\exept\cg\home2\java\' - ). - "/ TODO: look in the registry ... - classPath notNil ifTrue:[ - classPath := classPath asCollectionOfSubstringsSeparatedBy:$;. - ]. - ]. - - possibleJavaDirs := possibleJavaDirs collect:[:dirName | dirName asFilename]. - possibleJavaDirs := possibleJavaDirs select:[:dir | dir exists]. - possibleJavaDirs := possibleJavaDirs select:[:dir | dir isDirectory]. - - classPath notNil ifTrue:[ - classPath := classPath collect:[:dirName | dirName asFilename]. - classPath := classPath select:[:dir | dir exists]. - possibleJavaDirs := classPath , possibleJavaDirs. - ]. - - FailedToLoadClasses := nil. - - "/ cannot use JDK1.2 yet (they made so many changes ...) -"/ tryJDK1_22 := true. -"/ tryJDK1_21 := true. -"/ tryJDK1_2 := true. -"/ tryJDK1_2beta := true. - - "/ cannot use those yet (they also made changes ...) -"/ tryVA := true. "/ visualAge-java -"/ tryNetscape4_0 := true. "/ netscape-java - -"/ tryMS := true. "/ MS-java; not really working -"/ tryBorland := true. "/ borland jbuilder-java; not really working - - tryJDK1_18 := true. "/ standard sun jdk's - work more or less - tryJDK1_17 := true. - tryJDK1_16 := true. - tryJDK1_15 := true. - tryJDK1_13 := true. - tryJDK1_11 := true. -"/ tryJDK1_03 := true. -"/ tryJDK1_02 := true. - - tryJRE1_1 := true. - tryJRE6 := true. - + ClassPath := OrderedCollection new. ExcludedClassPath := OrderedCollection new. - directoriesToSearch := OrderedCollection new. - - tryJRE1_1 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'JRE\1.1'). - directoriesToSearch add:(d construct:'JRE/1.1'). - ] - ]. - tryJRE6 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jre6\'). - directoriesToSearch add:(d construct:'jre6\lib'). - directoriesToSearch add:(d construct:'jre6\lib\rt.jar'). - ] - ]. - tryVA == true ifTrue:[ - directoriesToSearch add:('C:\IBMVJava\EAB\jdk' asFilename). - ]. - tryBorland == true ifTrue:[ - directoriesToSearch add:('c:\jbuilder2\java' asFilename). - ]. - - tryMS == true ifTrue:[ -"/ (fn := 'c:\windows\java\classes' asFilename) exists ifTrue:[ -"/ directoriesToSearch add:('c:\windows\java\classes' asFilename). -"/ fn directoryContents do:[:f | -"/ (f asFilename hasSuffix:'zip') ifTrue:[ -"/ directoriesToSearch add:(fn construct:f) -"/ ] -"/ ] -"/ ]. - - (fn := 'c:\windows\java\packages' asFilename) exists ifTrue:[ - fn directoryContents do:[:f | - (f asFilename hasSuffix:'zip') ifTrue:[ - directoriesToSearch add:(fn construct:f) - ] - ] - ]. - (fn := 'c:\windows\java\trustlib' asFilename) exists ifTrue:[ - fn directoryContents do:[:f | - (f asFilename hasSuffix:'zip') ifTrue:[ - directoriesToSearch add:(fn construct:f) - ] - ] - ] - ]. - - tryJDK1_22 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk1.2.2'). - directoriesToSearch add:(d construct:'jdk122'). - ] - ]. - - tryJDK1_21 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk1.2.1_win'). - directoriesToSearch add:(d construct:'jdk1.2.1'). - directoriesToSearch add:(d construct:'jdk121'). - ] - ]. - - tryJDK1_2 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk1.2.0'). - directoriesToSearch add:(d construct:'jdk120'). - directoriesToSearch add:(d construct:'jdk1.2'). - directoriesToSearch add:(d construct:'jdk12'). - ] - ]. - - tryJDK1_2beta == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk12beta2'). - directoriesToSearch add:(d construct:'jdk1.2beta2'). - ] - ]. - - tryJDK1_18 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk118'). - directoriesToSearch add:(d construct:'jdk1.1.8'). - ] - ]. - - tryJDK1_17 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk117'). - directoriesToSearch add:(d construct:'jdk1.1.7'). - ] - ]. - - tryJDK1_16 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk116'). - directoriesToSearch add:(d construct:'jdk1.1.6'). - ] - ]. + SourceCache := CacheDictionary new: 32. + SourceArchiveCache := CacheDictionary new: 32. - tryJDK1_15 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk115'). - directoriesToSearch add:(d construct:'jdk1.1.5'). - ] - ]. - - tryJDK1_13 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk113'). - directoriesToSearch add:(d construct:'jdk1.1.3'). - ] - ]. - - tryJDK1_11 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk111'). - directoriesToSearch add:(d construct:'jdk1.1.1'). - ] - ]. - - tryJDK1_03 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk103'). - directoriesToSearch add:(d construct:'jdk1.0.3'). - ] - ]. - - tryJDK1_02 == true ifTrue:[ - possibleJavaDirs do:[:d | - directoriesToSearch add:(d construct:'jdk102'). - directoriesToSearch add:(d construct:'jdk1.0.2'). - ] - ]. - directoriesToSearch := directoriesToSearch collect:[:dirName | dirName asFilename]. - directoriesToSearch := directoriesToSearch select:[:dir | dir exists]. - directoriesToSearch := directoriesToSearch select:[:dir | - ((dir hasSuffix:'jar') - or:[(dir hasSuffix:'zip') - or:[dir isDirectory]]). - ]. - - self initializeForNewClassPath:directoriesToSearch. - - - "/ kludge - add individual jar files ... + self initializeRelease. "lazy initialization of Release" - directoriesToSearch := OrderedCollection new. - directoriesToSearch add:'/usr/local/java/moz3_0/lib_unix'. - directoriesToSearch add:'..\..\..\cg\java\java\ns30_unix.zip'. - d := Smalltalk projectDirectoryForClass:self. - d notNil ifTrue:[ - directoriesToSearch add:((d asFilename construct:'java') constructString:'ns30_unix.zip'). - ]. - - tryVA == true ifTrue:[ - directoriesToSearch add:'C:\IBMVJava\EAB\bdk'. - ]. - tryNetscape4_0 == true ifTrue:[ - directoriesToSearch add:'C:\Programme\Netscape\Communicator\Program\Java\Classes\java40.jar'. - ]. - tryBorland == true ifTrue:[ - directoriesToSearch addAll:#( - 'C:\jbuilder2\lib\jbuilder.zip' - 'C:\jbuilder2\lib\jbcl2.0.jar' - 'C:\jbuilder2\lib\jbcl2.0-res.jar' - 'C:\jbuilder2\lib\swingall.jar' - 'C:\jbuilder2\lib\jgl3.1.0.jar' - 'C:\jbuilder2\lib\jctable.jar' - 'C:\jbuilder2\lib\jcchart.jar' - 'C:\jbuilder2\lib\jcbwt.jar' - ) - ]. + self initializePrettyPrintStyle. - directoriesToSearch do:[:aPath | - |dir classDir| - - dir := aPath asFilename. - (dir exists) ifTrue:[ - ((dir hasSuffix:'jar') - or:[dir hasSuffix:'zip']) ifTrue:[ - Transcript showCR:'Adding to classPath: ' , dir pathName. - Java addToClassPath:aPath. - ] ifFalse:[ - mozillaHome := dir. - classDir := (dir construct:'classes'). - classDir exists ifTrue:[ - Transcript showCR:'Adding to classPath: ' , classDir pathName. - Java addToClassPath:classDir pathName. - ]. - - "/ - "/ care to only load mozilla classes from there ... - "/ i.e. ignore the java/sun stuff found there. - "/ - ExcludedClassPath add:(classDir construct:'java') pathName. - ExcludedClassPath add:(classDir construct:'sun') pathName. - ] - ] - ]. - self initializePrettyPrintStyle. + ObjectMemory addDependent: self. " Java flushAllJavaResources. @@ -623,7 +555,10 @@ Java classPath inspect " - "Modified: / 6.11.2001 / 09:24:12 / cg" + "Modified: / 06-11-2001 / 09:24:12 / cg" + "Created: / 03-10-2010 / 15:54:02 / Jan Kurs " + "Modified: / 15-10-2010 / 17:37:20 / Jan Kurs " + "Modified: / 10-02-2011 / 23:08:40 / Jan Vrany " ! initializeForNewClassPath:directoriesToSearch @@ -653,6 +588,10 @@ jHome := aPath. toAdd := (libDir constructString:'classes.zip'). ] ifFalse:[ + (libDir construct:'rt.jar') exists ifTrue:[ + jHome := aPath. + toAdd := (libDir constructString:'rt.jar'). + ]. (libDir construct:'rt.zip') exists ifTrue:[ jHome := aPath. toAdd := (libDir constructString:'rt.zip'). @@ -686,7 +625,6 @@ self javaHome:jHome. self classPath:(jClasses collect:[:f | f asFilename name]). - jHome isNil ifTrue:[ Transcript showCR:'no java home directory found'. ] ifFalse:[ @@ -715,6 +653,9 @@ self initializeForNewClassPath:(Java classPath) self initializeForNewClassPath:(Array with:'/home/java/jdk113') " + + "Modified: / 03-10-2010 / 15:49:02 / Jan Kurs " + "Modified: / 19-10-2010 / 10:49:23 / Jan Vrany " ! initializePrettyPrintStyle @@ -733,6 +674,19 @@ "Modified: 1.8.1997 / 11:09:58 / cg" ! +initializeRelease + + Release ifNil:[Release := JavaRelease any]. + + " + Release := nil. + self initializeRelease. + Release + " + + "Created: / 22-11-2010 / 13:41:34 / Jan Vrany " +! + reinitAllClasses self markAllClassesUninitialized. self initAllClasses @@ -750,12 +704,21 @@ FailedToLoadClasses := nil. Threads := nil. + "Kludge" + JavaMethod reinitialize. + JavaMethodWithException reinitialize. + JavaMethodWithHandler reinitialize. + JavaNativeMethod reinitialize. + JavaNativeMethod flushAllCachedNativeMethods. + + " Java reinitialize " - "Created: / 26.8.1997 / 20:07:00 / cg" - "Modified: / 27.4.1998 / 14:57:23 / cg" + "Created: / 26-08-1997 / 20:07:00 / cg" + "Modified: / 27-04-1998 / 14:57:23 / cg" + "Modified: / 14-12-2010 / 21:30:10 / Jan Vrany " ! startupJavaSystem @@ -958,37 +921,46 @@ "Modified: 7.8.1997 / 21:20:07 / cg" ! -as_ST_String:aJavaString +as_ST_String: aJavaString "hard-coding internas of java.lang.String here is bad ..." - - |str count offs start stop| - - aJavaString isNil ifTrue:[^ nil]. - - "/ count := aJavaString instVarNamed:'count'. - count := aJavaString instVarAt:3. "/ (JavaSlotIndexCache string_slot_count). - - "/ str := aJavaString instVarNamed:'value' - str := aJavaString instVarAt:1. "/ (JavaSlotIndexCache string_slot_value). + + | str count offs start stop | - str size == count ifTrue:[ - ^ str asOneByteString - ]. - + aJavaString isNil ifTrue: [ ^ nil ]. + + "/ count := aJavaString instVarNamed:'count'. + + count := aJavaString instVarAt: 3. + + "/ str := aJavaString instVarNamed:'value' + + str := aJavaString instVarAt: 1. + str size == count + ifTrue: + [ "cos I don't see any reason to do this" + "/ ^ str asOneByteString. + ^ str ]. + "/ offs := (aJavaString instVarNamed:'offset'). - offs := aJavaString instVarAt:2. "/ (JavaSlotIndexCache string_slot_offset). - + + offs := aJavaString instVarAt: 2. + "/ start := offs + 1. + start := offs + 1. - + "/ stop := start + (aJavaString instVarNamed:'count') - 1. + stop := start + count - 1. - + "/ ^ ((aJavaString instVarNamed:'value') copyFrom:start to:stop) asString - ^ (str copyFrom:start to:stop) asOneByteString + + ^ (str copyFrom: start to: stop) asOneByteString - "Created: / 8.8.1997 / 12:02:55 / cg" - "Modified: / 4.1.1999 / 23:55:08 / cg" + "Created: / 08-08-1997 / 12:02:55 / cg" + "Modified: / 04-01-1999 / 23:55:08 / cg" + "Modified: / 22-03-2011 / 17:21:19 / Marcel Hlopko " + "Modified: / 10-08-2011 / 23:32:32 / Jan Vrany " ! as_String:aString @@ -1002,14 +974,15 @@ s instVarNamed:'value' put: aString. s instVarNamed:'offset' put: 0. s instVarNamed:'count' put: aString size. + s instVarNamed:'hash' put: 0. ^ s " Java as_String:'hello world' " - "Created: 7.8.1997 / 21:15:49 / cg" - "Modified: 7.8.1997 / 21:19:37 / cg" + "Created: / 07-08-1997 / 21:15:49 / cg" + "Modified: / 03-02-2011 / 23:33:47 / Jan Vrany " ! as_URL:aString @@ -1154,6 +1127,9 @@ flushAllJavaResources self flushClasses. + SourceCache := CacheDictionary new: 32. + SourceArchiveCache := CacheDictionary new: 32. + ObjectMemory allObjectsDo:[:someObject | someObject isBehavior ifTrue:[ someObject isJavaClass ifTrue:[ @@ -1163,13 +1139,6 @@ 'JAVA [info]: flushing ' print. someObject fullName printCR. ] ]. -"/ (someObject isKindOf:JavaMethod) ifTrue:[ -"/ someObject setJavaClass:nil. -"/ someObject setExceptionTable:nil. -"/ ]. - (someObject isMemberOf:JavaUnresolvedClassConstant) ifTrue:[ - someObject constantPool:nil - ]. ]. JavaClass flushClassesInitOrder. @@ -1179,7 +1148,8 @@ Java flushAllJavaResources " - "Modified: / 6.11.2001 / 09:49:37 / cg" + "Modified: / 06-11-2001 / 09:49:37 / cg" + "Modified: / 26-07-2011 / 17:59:06 / Jan Vrany " ! flushClasses @@ -1187,12 +1157,12 @@ Smalltalk keys copy do:[:aKey | (aKey startsWith:'JAVA::') ifTrue:[ Smalltalk removeKey:aKey ] ]. - Smalltalk removeKey:'JAVA'. + Smalltalk removeKey:#'JAVA'. Java_lang_String := Java_lang_Class := nil. JavaVM releaseAllJavaResources. JavaUnresolvedConstant flushPatchLists. - Debugger newDebugger. + Debugger == DebugView ifTrue:[Debugger newDebugger]. ObjectMemory flushCaches. " @@ -1301,13 +1271,68 @@ !Java class methodsFor:'source management'! +classSource:filename package:package in:dirOrZipFile + |fn zar f | + + fn := dirOrZipFile asFilename. + fn isDirectory + ifTrue: + [ package notNil + ifTrue:[ (f:= fn / package / filename) exists ifTrue:[ ^ f contents asString ]. ]. + (f := fn / filename) exists ifTrue:[ ^ f contents asString ]. ] + ifFalse: + [ (dirOrZipFile last == $p and: [fn hasSuffix:'zip']) + ifTrue: + [ zar := SourceArchiveCache + at: dirOrZipFile + ifAbsentPut:[ZipArchive oldFileNamed:fn pathName]. + zar notNil + ifTrue: + [ package notNil + ifTrue:[ + OperatingSystem fileSeparator ~~ $/ ifTrue: [ + f := (package copyReplaceAll: OperatingSystem fileSeparator with: $/) , '/' , filename + ] ifFalse:[ + f := package , '/' , filename. + ]] + ifFalse:[ f := filename]. + (zar findMember: f) ifNotNil: + [ + "Kludge because of broken ZipArchive" + | cache | + cache := Java cacheDirectory / Release name / 'src'. + cache exists ifFalse:[cache recursiveMakeDirectory]. + (cache / f) exists ifTrue:[^(cache / f) contents asString]. + OperatingSystem + executeCommand:('unzip "%1" "%2"' bindWith: fn asAbsoluteFilename asString + with: f asString) + inDirectory: cache asString. + (f := cache / f) exists ifTrue:[^f contents asString] + ] + ]]]. + + ^ nil + + " + Java classSource: 'Object.java' package:'java/lang' in:'/home/jv/Projects/JavaX/java-6-openjdk/src' + Java classSource: 'Object.java' package:'java/lang' in:'/usr/lib/jvm/java-6-openjdk/src.zip' + + " + + "Modified: / 29-03-1998 / 21:46:40 / cg" + "Created: / 30-11-2010 / 12:32:36 / Jan Vrany " + "Modified: / 08-04-2011 / 15:01:59 / Jan Vrany " +! + classSourceOf:aClass - |package dirName binary sourceFileName sourceFile dirHolder fileName path - loader codeBaseURL protocol dir file codeBaseURLIdx zar src| + |package dirName binary sourceFileName sourceFile loader codeBaseURL protocol codeBaseURLIdx src| aClass isNil ifTrue:[ ^ nil ]. + "/ look at the cache" + SourceCache at: aClass ifPresent: [:src|^src]. + "/ first, look in the directory, where the binary "/ was loaded from. @@ -1376,105 +1401,24 @@ "/ if that fails, look in standard places (sourceFile isNil or:[sourceFile exists not]) ifTrue:[ - package := aClass package. - - sourceFileName := aClass sourceFile. - sourceFileName isNil ifTrue:[^nil]. - - sourceFile := sourceFileName asFilename. - sourceFile exists ifFalse:[ - "/ - "/ mhmh - look for its directory - "/ - dirName := sourceFile directory. - fileName := sourceFile baseName. - - (dirName exists - and:[(dirName construct:(package , '/' , fileName)) exists]) - ifFalse:[ - (dirName exists - and:[(dirName construct:(fileName)) exists]) - ifFalse:[ - dirName := self findSourceDirOf:fileName inPackage:package. - - "/ [dirName isNil] whileTrue:[ - "/ dirName := Dialog requestDirectoryName:'top directory for ' , package , '/' , fileName. - "/ (dirName isNil or:[dirName isEmpty]) ifTrue:[^ self]. - "/ ]. - ]. - ]. + sourceFile := aClass sourceFile. + package := aClass javaPackageAsDirname. + self effectiveSourceDirectories do:[:dir| + src := self classSource: sourceFile package: package in: dir. + src ifNotNil:[^src] + ] - (dirName notNil and:[dirName exists]) ifTrue:[ - dirName isDirectory ifTrue:[ - path := dirName construct:(package , '/' , fileName). - path exists ifFalse:[ - path := dirName construct:(fileName). - ]. - ] ifFalse:[ - "/ a zip-file ? - (dirName hasSuffix:'zip') ifTrue:[ - zar := ZipArchive oldFileNamed:dirName pathName. - src := zar extract:(package , '/' , fileName). - src isNil ifTrue:[ - src := zar extract:fileName. - ]. - src notNil ifTrue:[ - ^ src asString. - ] - ] - ] - ]. - (path notNil and:[path exists]) ifFalse:[ - ^ nil - ]. - - sourceFile := path. - ]. ]. + sourceFile isFilename ifFalse:[^nil]. ^ (sourceFile contentsOfEntireFile). - "Modified: / 27.1.1999 / 20:40:30 / cg" -! - -findSourceDirOf:fileName inPackage:aPackage - "return a directory-fileName, a zip-file fileName or nil" - - SourceDirectories notNil ifTrue:[ - SourceDirectories do:[:aDirOrZipFile | - |fn zar| + " + Java classSourceOf: JAVA::java::lang::Object + " - fn := aDirOrZipFile asFilename. - fn isDirectory ifTrue:[ - aPackage notNil ifTrue:[ - (fn construct:('/' , aPackage , '/' , fileName)) exists ifTrue:[ - ^ fn - ]. - ]. - (fn construct:('/' , fileName)) exists ifTrue:[ - ^ fn - ]. - ] ifFalse:[ - (fn hasSuffix:'zip') ifTrue:[ - zar := ZipArchive oldFileNamed:fn pathName. - zar notNil ifTrue:[ - aPackage notNil ifTrue:[ - (zar findMember:(aPackage , '/' , fileName)) notNil ifTrue:[ - ^ fn - ] - ] ifFalse:[ - (zar findMember:fileName) notNil ifTrue:[ - ^ fn - ] - ] - ] - ] - ] - ] - ]. - ^ nil - - "Modified: / 29.3.1998 / 21:46:40 / cg" + "Modified: / 27-01-1999 / 20:40:30 / cg" + "Modified: / 10-02-2011 / 23:10:58 / Jan Vrany " ! ! !Java class methodsFor:'starting apps'! @@ -1552,7 +1496,11 @@ !Java class methodsFor:'documentation'! version - ^ '$Id$' + ^ '$Id: Java.st,v 1.134 2011/08/18 18:42:48 vrany Exp $' +! + +version_SVN + ^ '$Id: Java.st,v 1.134 2011/08/18 18:42:48 vrany Exp $' ! ! -Java initialize! +Java initialize! \ No newline at end of file