JavaRelease.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 24 May 2013 17:55:42 +0100
branchbuiltin-class-support
changeset 2629 cedb88626902
parent 2566 f1cea8b752ba
child 2631 0208d0cf73a2
permissions -rw-r--r--
Closing branch.

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ Package: 'stx:libjava' }"

Object subclass:#JavaRelease
	instanceVariableNames:'javaHome sourcePath classes bootClassPathClasses extDirsClasses
		bundle bootClassPath'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Support'
!

JavaRelease class instanceVariableNames:'instance'

"
 No other class instance variables are inherited by this class.
"
!

JavaRelease subclass:#OpenJDK6
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:'JavaVMData'
	privateIn:JavaRelease
!

JavaRelease::OpenJDK6 subclass:#OpenJDK7
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:'JavaVMData'
	privateIn:JavaRelease
!

JavaRelease::OpenJDK6 subclass:#OracleJDK6
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:JavaRelease
!

JavaRelease::OpenJDK7 subclass:#OracleJDK7
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:JavaRelease
!

JavaRelease subclass:#SunJDK122
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:JavaRelease
!

!JavaRelease class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
!

documentation
"
    Sub-instance of me represent a particular Java release and provides and
    access to JDK/JRE files as well and native method implementation and other
    things that are release-dependent.

    There is a guessing mechanism trying to auto-detect path to JRE/JDK. If it fails,
    you may always set javaHome manually (see #javaHome:).

    NOTE: an instance of OpenJDKx and OracleJDKx represent provide access to both,
          plain JRE or full JDK.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!JavaRelease class methodsFor:'initialization'!

flush   
    Java release: nil.
    instance := nil.
    self subclasses do:[:e|e flush].

    "
        JavaRelease flush.
    "

    "Created: / 12-02-2013 / 03:20:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease class methodsFor:'instance creation'!

JDK6
    "Meta-release - return either OpenJDK or OracleJDK"
    ^self openJDK6 isAvailable 
        ifTrue:[self openJDK6]
        ifFalse:[self oracleJDK6].

    "Created: / 16-02-2013 / 09:21:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

JDK7
    "Meta-release - return either OpenJDK or OracleJDK"
    ^self openJDK7 isAvailable 
        ifTrue:[self openJDK7]
        ifFalse:[self oracleJDK7].

    "
        JavaRelease JDK6
        JavaRelease JDK7

    "

    "Created: / 16-02-2013 / 09:21:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

openJDK6
    ^ OpenJDK6 instance

    "Created: / 27-10-2010 / 21:41:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-11-2011 / 18:45:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 27-07-2012 / 00:22:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

openJDK7
    ^ OpenJDK7 instance.

    "Created: / 26-07-2012 / 23:51:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

oracleJDK6
    ^ OracleJDK6 instance

    "Created: / 12-02-2013 / 03:03:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

oracleJDK7
    ^ OracleJDK7 instance

    "Created: / 12-02-2013 / 03:03:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

oracleJRE7
    ^ OracleJRE7 instance
!

sunJDK122
    ^ SunJDK122 instance

    "Created: / 27-10-2010 / 21:41:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-11-2011 / 18:45:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 27-07-2012 / 00:22:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease class methodsFor:'accessing'!

all
    ^(self allSubclasses
                reject: [:rel | rel isAbstract ]
                thenCollect: [:rel | rel instance ])
                asSortedCollection: [:a :b | a priority > b priority ]


    "
        JavaRelease all
    "

    "Created: / 27-07-2012 / 00:10:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

any
    | releases |

    releases := self available.
    releases isEmptyOrNil ifTrue:[ ^ nil ].
    ^ releases first initialize


    "
        JavaRelease any
    "

    "Created: / 22-11-2010 / 13:11:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-11-2011 / 14:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 26-07-2012 / 23:42:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

available
    | releases out path |

    releases := self all select: [:rel | rel isAvailable ].
    releases isEmpty ifTrue: [
        "/ none of the releases seems to be installed in a way that it is found
        "/ out of the box. Try a 'java' command...
        (path := OperatingSystem pathOfCommand:'java') notNil ifTrue:[
            out := WriteStream on:(String new:100).
            (OperatingSystem executeCommand:'java -version' outputTo:out) ifTrue:[
                out := out contents.
                releases := self all select:[:rel | rel validateJavaVersionString:out].
                ('/System/Library/Java' asFilename) exists  
                releases do:[:each |
                    each javaHome:('/System/Library/Java/Home' asFilename).
                ].
            ].
        ].
        releases isEmpty ifTrue: [ 
            self error: 'No Java release found'. ^nil 
        ].
    ].
    ^releases

    "
        JavaRelease available
    "

    "Created: / 26-07-2012 / 23:41:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease class methodsFor:'instance creation-private'!

instance
    instance isNil ifTrue:[
        instance := self new initialize
    ].
    ^instance

    "Created: / 27-07-2012 / 00:22:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease class methodsFor:'others'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !

!JavaRelease class methodsFor:'queries'!

isAbstract

    ^self class == JavaRelease

    "Created: / 22-11-2010 / 13:33:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'accessing'!

bootClassPath
    "Returns a default value of sun.boot.class.path"

    bootClassPath isNil ifTrue:[
        | jreHome libs |

        jreHome := self jreHome.
        libs := jreHome / 'lib'.
        bootClassPath := OrderedCollection new.
        libs directoryContentsAsFilenames do:[:each|
            (each pathName endsWith:'.jar') ifTrue:[
                (each pathName endsWith: 'rt.jar') ifTrue:[
                    bootClassPath addFirst: each pathName
                ] ifFalse:[
                    bootClassPath addLast: each pathName
                ]
            ].
        ].
    ].
    ^bootClassPath.

    "
    Java release bootClassPath
    "

    "Created: / 02-11-2011 / 12:19:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified (format): / 31-07-2012 / 10:16:25 / jv"
    "Modified: / 23-01-2013 / 15:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 11-04-2013 / 14:30:16 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

bootClassPath:aCollectionOfPathes
    "Change the bootClassPath"                         

    bootClassPath := OrderedCollection withAll:aCollectionOfPathes.

    "
    Java release bootClassPath
    "
!

javaBundle
    "Returns bundle representing Java code (both core + extections)"

    bundle isNil ifTrue:[
        bundle := JavaCodeBundle new
                    name: self name;
                    add: self bootBundle;
                    add: self extBundle;
                    yourself.
    ].
    ^bundle

    "Created: / 12-02-2013 / 14:56:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaExtDirs

    "Returns a default value of java.ext.dirs property"

    OperatingSystem isUNIXlike ifTrue:[ ^ self javaExtDirsOnUNIX ].
    OperatingSystem isMSWINDOWSlike ifTrue:[ ^ self javaExtDirsOnWindows ].
    self error:'Unsupported platform'.
    ^ #()


    "
        JavaRelease openJDK6 classPath
    "

    "Modified: / 27-10-2010 / 21:48:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 31-08-2011 / 19:59:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaExtDirsOnUNIX

    ^#()

    "Created: / 31-08-2011 / 19:59:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaExtDirsOnWindows

    ^#()

    "Created: / 31-08-2011 / 19:59:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHome
    "Answer a Java home. This is either path to JRE (no JDK is found) or to
     full JDK (if JDK is installed)

     If you want path to either JRE or JDK, use
     #jreHome
     #jdkHome

     "

    javaHome isNil ifTrue:[
        javaHome := self searchForJavaHome.
    ].
    ^javaHome

    "
        JavaRelease openJDK6 javaHome
    "

    "Created: / 27-10-2010 / 18:59:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-07-2012 / 00:24:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 23-01-2013 / 12:19:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHome: aString
     javaHome := aString.
     self searchForSourcePath.

    "
        JavaRelease openJDK6 javaHome
    "

    "Created: / 26-07-2012 / 23:32:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 11-02-2013 / 02:58:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomeOrNil

    "Answer a Java home"

    | home |
    home := (javaHome
                ifNotNil:[javaHome]
                ifNil:[self searchForJavaHome]).
    ^home

    "
        JavaRelease openJDK6 javaHome
    "

    "Created: / 22-11-2010 / 13:17:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomes

    "Answer a set of possible java homes, those directories are searched"


    OperatingSystem isUNIXlike ifTrue:[ ^ self javaHomesOnUNIX ].
    OperatingSystem isMSWINDOWSlike ifTrue:[ ^ self javaHomesOnWindows ].
    self error:'Unsupported platform'.
    ^ #()

    "Modified: / 22-11-2010 / 13:28:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnUNIX
    "raise an error: must be redefined in concrete subclass(es)"

    ^ self subclassResponsibility
!

javaHomesOnWindows
    "raise an error: must be redefined in concrete subclass(es)"

    ^ self subclassResponsibility
!

javaNativeMethodsImplementation
    "Returns an object that imolements native methods."

    ^ self subclassResponsibility

    "Created: / 16-01-2013 / 19:58:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

jdkHome

    "Answers the directory where the JDK lives or nil, if no JDK is found"

    | jdkHome |

    self javaHome isNil ifTrue:[ ^ nil ].

    ^((jdkHome := self javaHome) asFilename / 'jre') exists
        ifTrue:[jdkHome]
        ifFalse:[nil].

    "
        Java release searchForJavaHome; jdkHome
    "

    "Created: / 23-01-2013 / 12:20:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

jreHome

    "Answers the directory where the JRE lives"

    | jreHome |

    OperatingSystem isOSXlike ifTrue:[
        ^ '/System/Library/Java/Home' asFilename
    ].

    self javaHome isNil ifTrue:[ ^ nil ].

    ^(jreHome := self javaHome asFilename / 'jre') exists
        ifTrue:[jreHome]
        ifFalse:[javaHome asFilename].

    "Created: / 27-10-2010 / 21:24:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name

    "Answer a human readable name of the Java release such as Sun JDK 1.2.2 or OpenJDK 6"

    ^self subclassResponsibility

    "Created: / 27-10-2010 / 18:53:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    ^50

    "Created: / 22-11-2010 / 13:34:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selector
    "Returns instance-creation selector to get the receiver.
     See JavaRelease class, protocol instance creation"

    ^self subclassResponsibility

    "Created: / 27-07-2012 / 10:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

sourcePath

    "Returns a paths where sources are located"

    sourcePath ifNil:[self searchForSourcePath].
    ^sourcePath

    "
        JavaRelease openJDK6 sourcePath
    "

    "Created: / 27-10-2010 / 19:20:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-11-2010 / 11:55:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'debugging'!

dumpConfigOn: stream

    | dumper |
    dumper := [:name :value :isfile|
        | values |

        '%-30s : ' printf:{ name } on: stream.
        value isString
            ifTrue:[values := { value asString }]
            ifFalse:[values := value].
        values do:[:v|
            stream nextPutAll: v asString.
            isfile ifTrue:[
                v asFilename exists ifFalse:[
                    stream nextPutAll:' (not found!!!!!!)'
                ].
            ]
        ] separatedBy:[stream cr; next: 30 + 3 put: Character space].
        stream cr.
    ].



    stream nextPutAll: '== Java release config =='; cr.
    dumper value: 'name' value: self name value: false.
    dumper value: 'JAVA home' value: self javaHome asString value: true.
    dumper value: 'JRE  home' value: self jreHome asString value: true.
    dumper value: 'JDK  home' value: self jdkHome asString value: true.
    dumper value: 'boot class path' value: self bootClassPath value: true.
    dumper value: 'ext dirs' value: self javaExtDirs value: true.


    "
        Java release dumpConfigOn: Transcript.
    "

    "Created: / 10-12-2011 / 12:55:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-02-2013 / 10:22:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'displaying'!

displayString
    ^self name

    "Created: / 27-07-2012 / 00:01:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'initialization'!

initializeBootClassPathIndex
    bootClassPathClasses := IdentitySet new.
    self bootClassPath do: [:file |
        | filename |

        filename := file asFilename.

        self assert: (filename suffix = 'jar').
        self assert: (filename exists).
        self selectAllClassNamesIn: file to: bootClassPathClasses.
    ].

    "Created: / 02-11-2011 / 12:12:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 19-07-2012 / 11:02:41 / jv"
    "Modified: / 23-01-2013 / 17:24:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

initializeClassIndex
    | jreHome |

    (jreHome := self jreHome) isNil ifTrue:[ ^ self ].
    classes := IdentitySet new.

    self jreHome recursiveDirectoryContents do: [
        :each |
        (each endsWith: '.class') ifTrue: [
            classes add: each asSymbol.
        ].
        (each endsWith: '.jar') ifTrue: [ self selectAllClassNamesIn: (self jreHome asFilename / each asFilename) to: classes. ]
    ].

    "Created: / 01-11-2011 / 14:09:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 27-07-2012 / 13:59:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

initializeExtDirsIndex
    extDirsClasses := IdentitySet new.
    self javaExtDirs do: [
        :dir |
        dir exists ifFalse: [
            Logger
                log: dir pathName
                        , ', included in JavaRelease>>javaExtDirs, does not exist'
                severity: #info
                facility: 'JVM'
        ] ifTrue: [
            dir recursiveDirectoryContents do: [
                :filename |
                (filename endsWith: '.class') ifTrue: [ extDirsClasses add: filename asSymbol ].
                (filename endsWith: '.jar') ifTrue: [
                    self selectAllClassNamesIn: dir asFilename / filename asFilename to: extDirsClasses
                ].
            ]
        ].
    ].

    "Created: / 02-11-2011 / 12:12:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRelease methodsFor:'object conversions'!

as_ST_String: aJavaString
    "Given a java.lang.String instance, returns a coresponding
     Smalltalk String"

    ^self subclassResponsibility

    "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 <hlopkmar@fel.cvut.cz>"
    "Modified: / 07-02-2013 / 20:01:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

as_String:aString
    "Given a Smalltalk string, returns corresponsing instance of
     java.lang.String"

   ^self subclassResponsibility

    "Created: / 07-08-1997 / 21:15:49 / cg"
    "Modified: / 07-02-2013 / 20:02:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'private'!

bootBundle
    | src b |

    src := self sourcePath detect:[:e|e endsWith: 'src.zip'] ifNone:[nil].
    b := JavaCodeBundle new name: 'Runtime Library'.
    self bootClassPath do:[:each|
        b add: (JavaCodeLibrary new 
                name: (each copyFrom: (each lastIndexOf: Filename separator) + 1);
                classes: each;
                sources: src;
                yourself)
    ].
    ^b

    "Created: / 12-02-2013 / 14:57:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

extBundle
    | src b |

    src := self sourcePath detect:[:e|e endsWith: 'src.zip'] ifNone:[nil].
    b := JavaCodeBundle new name: 'Extensions'.
    self javaExtDirs do:[:extnm|
        | ext |

        ext := extnm asFilename.
        ext exists ifTrue:[
            ext directoryContentsAsFilenamesDo:[:each|
                each suffix = 'jar' ifTrue:[
                    b add: (JavaCodeLibrary new 
                            name: each baseName;
                            classes: each pathName;
                            sources: src;
                            yourself)
                ]
            ].
        ].
    ].
    ^b

    "Created: / 12-02-2013 / 14:57:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

searchInternalIndex: anIdentityCollection for: className
    | classFileName |
    classFileName := (className asSlashedJavaClassName) asSymbol.
    ^ anIdentityCollection includes: classFileName asSymbol.

    "Created: / 02-11-2011 / 12:27:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

selectAllClassNamesIn: jarArchiveName to: anIdentityCollection
    | jar  classesInJar |
    jar := ZipArchive readingFrom: jarArchiveName asFilename readStream.
    classesInJar := jar entries select: [:each | each endsWith: '.class'. ].
    classesInJar do: [:each |
        anIdentityCollection add: (each copyFrom: 1 to: each size - 6) asSymbol
    ].

    "
     JavaRelease any."

    "Created: / 02-11-2011 / 12:17:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified (format): / 02-11-2011 / 23:34:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateClassIndexFrom: jarArchiveName
    | jar  classesInJar |
    jar := ZipArchive
                readingFrom: (self jreHome asFilename / jarArchiveName asFilename)
                        readStream.
    classesInJar := jar entries select: [:each | each endsWith: '.class'. ].
    classesInJar do: [:each | classes add: each asSymbol].

    "
     JavaRelease any."

    "Created: / 01-11-2011 / 14:18:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !

!JavaRelease methodsFor:'queries'!

bootClassPathIncludesClassNamed: className
    bootClassPathClasses isNil ifTrue:[self initializeBootClassPathIndex].
    ^ self searchInternalIndex: bootClassPathClasses for: className.

    "Created: / 02-11-2011 / 12:11:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 31-07-2012 / 18:00:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

extDirsIncludesClassNamed: className
    "Looks like a bug, shouldn't it look to extDirClasses?"

    classes isNil ifTrue:[self initializeClassIndex].
    ^self searchInternalIndex: classes for: className.

    "Created: / 02-11-2011 / 12:11:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified (comment): / 31-07-2012 / 18:00:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

includesClassNamed: className
    classes isNil ifTrue:[self initializeClassIndex].
    ^self searchInternalIndex: classes for: className.

    "Created: / 01-11-2011 / 14:50:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 31-07-2012 / 17:58:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isAvailable

    ^self javaHomeOrNil notNil

    "
        JavaRelease openJDK6 isAvailable
        JavaRelease oracleJDK6 isAvailable

        JavaRelease openJDK7 isAvailable
        JavaRelease oracleJDK7 isAvailable


        JavaRelease available
    "

    "Created: / 22-11-2010 / 13:15:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 12-02-2013 / 03:18:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isCustom
    ^false

    "Created: / 27-07-2012 / 00:08:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'searching'!

searchForJavaHome

    | h |

    bundle := nil.
    h := (OperatingSystem getEnvironment:'JAVA_HOME').
    h notNil ifTrue:[
        (h endsWith: '\jre') ifTrue:[
            h := h copyTo: h size - 5
        ].
        h := h asFilename.

        "/Do not trust JAVA_HOME, it might be wrong (on Windows machine due
        "/to a registry mess
        (self validateJavaHome: h) ifTrue:[ javaHome := h. ^ javaHome ].
    ].

    self javaHomes do: [:home| 
        | homeAsFilename |

        homeAsFilename := home asFilename.
        homeAsFilename exists ifTrue:
            [(self validateJavaHome: homeAsFilename) ifTrue:
                [^javaHome := home]]].

    ^nil

    "
    Java release searchForJavaHome
    Java release javaHome

    "

    "Created: / 27-10-2010 / 19:03:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-03-2011 / 13:29:14 / Jan Kurs <kursjan@fit.cvut.cz>"
    "Modified: / 15-03-2011 / 13:47:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
    "Modified: / 19-07-2012 / 11:08:04 / jv"
    "Modified: / 20-02-2013 / 02:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

searchForSourcePath

    | java_home src_zip |

    sourcePath := OrderedCollection new.
    bundle := nil.
    java_home := self javaHome.
    java_home notNil ifTrue:[
        src_zip := self javaHome asFilename / 'src.zip'.
        src_zip exists ifTrue:[sourcePath add: src_zip pathName].
    ].

    "
        JavaRelease openJDK6 searchForSourcePath; sourcePath
    "

    "Created: / 27-10-2010 / 21:15:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-01-2013 / 15:55:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'validating'!

validateJavaHome1: home

    home isNil ifTrue:[ ^ false ].

    "Just JRE"
    ( home  asFilename / 'lib' / 'rt.jar' ) exists ifTrue:[^true].

    "Full JDK"
    ( home asFilename / 'jre' / 'lib' / 'rt.jar' ) exists ifTrue:[^true].

    ^ false

    "
        JavaRelease basicNew validateJavaHome: '/usr/lib/jvm/java-6-openjdk'
        JavaRelease basicNew validateJavaHome: '/tmp'
    "

    "Created: / 12-02-2013 / 02:50:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

validateJavaHome2: home
    self subclassResponsibility

    "Created: / 12-02-2013 / 02:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

validateJavaHome: home

    ^(self validateJavaHome1: home) and:[self  validateJavaHome2: home]


    "
        JavaRelease basicNew validateJavaHome: '/usr/lib/jvm/java-6-openjdk'
        JavaRelease basicNew validateJavaHome: '/tmp'
    "

    "Created: / 27-10-2010 / 19:14:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-02-2013 / 02:51:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

validateJavaVersionString:aVersionString
    "Return true if aVersionString (which is what 'java -version' returns)
     matches what I expect."

    ^ false
! !

!JavaRelease::OpenJDK6 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
!

version_SVN
    ^ 'Id::                                                                                                                        '
! !

!JavaRelease::OpenJDK6 methodsFor:'accessing'!

javaExtDirsOnUNIX

    ^{
        self jreHome asFilename / 'lib' / 'ext' .
        '/usr/java/packages/lib/ext' asFilename
    }

    "Created: / 31-08-2011 / 20:01:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-12-2012 / 15:46:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaExtDirsOnWindows

    ^{
        self jreHome asFilename / 'lib' / 'ext' .
    }

    "Created: / 31-08-2011 / 20:02:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-12-2012 / 15:46:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnUNIX
    | arch |

    arch := OperatingSystem getSystemInfo at:#machine.
    arch = 'x86_64' ifTrue:[arch := 'amd64'].

    ^ {
        '/usr/lib/jvm/java-6-openjdk-',arch.        "/ JDK - newer linuxes
        '/usr/lib/jvm/java-6-openjdk'  .            "/ JDK - older linuxes

        '/usr/lib/jvm/java-6-openjdk-',arch, '/jre'.  "/ JRE - newer linuxes
        '/usr/lib/jvm/java-6-openjdk/jre'  .        "/ JRE - older linuxes
    }

    "
    JavaRelease::OpenJDK6 new javaHomesOnUNIX
    "

    "Modified: / 21-02-2013 / 03:57:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnWindows
    "raise an error: must be redefined in concrete subclass(es)"

    ^ #() "/ There is nothing like Open JDK 6 for Windows!!

    "Modified: / 06-02-2013 / 13:37:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaNativeMethodsImplementation
    "Returns an object that imolements native methods."

    ^ JavaNativeMethodImpl_OpenJDK6

    "Modified: / 16-01-2013 / 19:59:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name
    "superclass JavaRelease says that I am responsible to implement this method"

    ^ 'Open JDK 6'

    "Modified: / 27-10-2010 / 19:16:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    ^80
    "/^70

    "Created: / 22-11-2010 / 13:35:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-02-2011 / 06:59:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selector
    "Returns instance-creation selector to get the receiver.
     See JavaRelease class, protocol instance creation"

    ^#openJDK6

    "Created: / 27-07-2012 / 10:05:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OpenJDK6 methodsFor:'object conversions'!

as_ST_String: aJavaString
    "Given a java.lang.String instance, returns a coresponfing
     Smalltalk String"

    | str  count  offs  start  stop |

    aJavaString isNil ifTrue: [ ^ nil ].

    "/ count := aJavaString instVarNamed:'count'.

    count := aJavaString instVarAt: 3+1"lockWord".

    "/ str := aJavaString instVarNamed:'value'

    str := aJavaString instVarAt: 1+1"lockWord".
    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+1"lockWord".

    "/ 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

    "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 <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-02-2013 / 00:56:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

as_String:aString
    "Given a Smalltalk string, returns corresponsing instance of
     java.lang.String"

    "hard-coding internas of java.lang.String here is bad ..."

    |s|

    s := Java java_lang_String basicNew.
    s instVarAt:1+1"_lockWord_"  put: aString.
    s instVarAt:3+1"_lockWord_"  put: aString size.
    ^ s

    "
     Java as_String:'hello world'
    "

    "Created: / 07-08-1997 / 21:15:49 / cg"
    "Modified: / 08-02-2013 / 00:58:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OpenJDK6 methodsFor:'searching'!

searchForSourcePath

    | jdkHome src_zip |

    super searchForSourcePath.

    sourcePath := OrderedCollection new.
    jdkHome := self jdkHome.
    jdkHome notNil ifTrue:[
        src_zip := jdkHome asFilename / 'src.zip'.
        src_zip exists ifTrue:[sourcePath add: src_zip pathName].
    ].

    "
        JavaRelease openJDK7 searchForSourcePath; sourcePath
        JavaRelease sunJDK6 searchForSourcePath; sourcePath
    "

    "Created: / 03-09-2012 / 18:38:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 23-01-2013 / 12:22:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 06-02-2013 / 12:55:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OpenJDK6 methodsFor:'validating'!

validateJavaHome2: home
    "Bit of a hack, but..."
    ^OperatingSystem isUNIXlike 
        and: [(home asString includesString: 'oracle') not
        and: [(home asString includesString: 'sun') not]]

    "Created: / 12-02-2013 / 02:52:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 11-04-2013 / 14:22:19 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!

validateJavaVersionString:aVersionString
    "Return true if aVersionString (which is what 'java -version' returns)
     matches what I expect."

    ^ aVersionString matches: 'java version "1.6.*'
! !

!JavaRelease::OpenJDK7 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
!

version_SVN
    ^ 'Id::                                                                                                                        '
! !

!JavaRelease::OpenJDK7 methodsFor:'accessing'!

javaHomesOnUNIX
    | arch |

    arch := OperatingSystem getSystemInfo at:#machine.
    arch = 'x86_64' ifTrue:[arch := 'amd64'].

    ^ {
        '/usr/lib/jvm/java-7-openjdk-',arch.        "/ JDK - newer linuxes
        '/usr/lib/jvm/java-7-openjdk'  .            "/ JDK - older linuxes

        '/usr/lib/jvm/java-7-openjdk-',arch, '/jre'."/ JRE - newer linuxes
        '/usr/lib/jvm/java-7-openjdk/jre'  .        "/ JRE - older linuxes
    }

    "
    JavaRelease::OpenJDK7 new javaHomesOnUNIX
    "

    "Created: / 11-02-2012 / 17:47:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-02-2013 / 03:57:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnWindows
    "raise an error: must be redefined in concrete subclass(es)"

    ^ #() "/ not yet implemented

    "Modified: / 06-02-2013 / 13:37:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaNativeMethodsImplementation
    "Returns an object that imolements native methods."

    ^ JavaNativeMethodImpl_OpenJDK7

    "Created: / 07-02-2013 / 20:53:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name
    ^ 'Open JDK 7'

    "Created: / 27-07-2012 / 00:03:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-02-2013 / 10:23:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    ^ super priority - 10
    "/^70

    "Modified: / 04-02-2011 / 06:59:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 11-02-2012 / 17:47:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selector
    "Returns instance-creation selector to get the receiver.
     See JavaRelease class, protocol instance creation"

    ^#openJDK7

    "Created: / 27-07-2012 / 10:05:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OpenJDK7 methodsFor:'object conversions'!

as_ST_String: aJavaString
    "Given a java.lang.String instance, returns a coresponfing
     Smalltalk String"

    ^aJavaString instVarAt: 1+1"_lockWord_".

    "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 <hlopkmar@fel.cvut.cz>"
    "Modified: / 08-02-2013 / 00:58:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

as_String:aString
    "Given a Smalltalk string, returns corresponsing instance of
     java.lang.String"

    |s|

    s := Java java_lang_String basicNew.
    s instVarAt:1+1"_lockWord_"  put: aString.
    ^s

    "
     Java as_String:'hello world'
    "

    "Created: / 07-08-1997 / 21:15:49 / cg"
    "Modified: / 08-02-2013 / 00:57:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OpenJDK7 methodsFor:'validating'!

validateJavaVersionString:aVersionString
    "Return true if aVersionString (which is what 'java -version' returns)
     matches what I expect."

    ^ aVersionString matches: 'java version "1.7.*' 
! !

!JavaRelease::OracleJDK6 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
!

version_SVN
    ^ 'Id::                                                                                                                        '
! !

!JavaRelease::OracleJDK6 methodsFor:'accessing'!

javaHomeOnWindowsFromRegistry
    "Return path to java home (either JDK or JRE) based on values in registry.
     If not on windows or registry key not found, return nil"

    |entry vsn home |

    OperatingSystem isMSWINDOWSlike ifFalse:[ ^ nil ].
    vsn := '1.6'.

    "Search for JDK first..."
    entry := (OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\', vsn).
    entry notNil ifTrue:[
        home := entry valueNamed:'JavaHome'.
        (home notNil and:[(home := home asFilename) exists]) ifTrue:[ ^ home ].
    ].
    "Search for JRE...."
    entry := (OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\', vsn).
    entry notNil ifTrue:[
        home := entry valueNamed:'JavaHome'.
        (home notNil and:[(home := home asFilename) exists]) ifTrue:[ ^ home ].
    ].

    ^nil

    "Created: / 16-02-2013 / 02:52:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-02-2013 / 03:51:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnUNIX

    ^ #( '/usr/lib/jvm/java-6-sun' )

    "Created: / 22-11-2010 / 13:31:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnWindows
    |home paths |

    home := self javaHomeOnWindowsFromRegistry.
    home notNil ifTrue:[ ^ Array with: home ].

    paths := OrderedCollection new.
    #(
        'C:\Program Files\Java'
        'C:\Program Files (x86)\Java'
    ) do:[:rootpath|
        | root |

        root := rootpath asFilename.
        root exists ifTrue:[
            "Search for JDK first"
            root directoryContents do:[:dir|
                (dir startsWith:self javaHomeOnWindowsJDKDirectoryPrefix) ifTrue:[
                    | path |
                    (path := root / dir) isDirectory ifTrue:[
                        paths add: path
                    ].
                ].
            ].
            "Search for JDK first"
            root directoryContents do:[:dir|
                (dir startsWith:self javaHomeOnWindowsJREDirectoryPrefix) ifTrue:[
                    | path |
                    (path := root / dir) isDirectory ifTrue:[
                        paths add: path
                    ].
                ].
            ].

        ]
    ].

    ^ paths

    "
     self basicNew javaHomesOnWindows
    "

    "Modified (format): / 19-08-2011 / 00:46:40 / cg"
    "Modified: / 19-07-2012 / 11:04:44 / jv"
    "Modified: / 21-02-2013 / 03:27:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaNativeMethodsImplementation
    "Returns an object that imolements native methods."

    ^ JavaNativeMethodImpl_SunJDK6

    "Created: / 06-02-2013 / 08:39:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name

    ^ 'Oracle JDK 6'

    "Created: / 22-11-2010 / 13:31:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-02-2013 / 03:03:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    "/There is no OpenJDK 6 for Windows yet...
    OperatingSystem isMSWINDOWSlike ifTrue:[
        ^100
    ].
    ^75

    "Created: / 22-11-2010 / 13:35:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 19-07-2012 / 10:57:55 / jv"
!

selector
    "Returns instance-creation selector to get the receiver.
     See JavaRelease class, protocol instance creation"

    ^#oracleJDK6

    "Created: / 27-07-2012 / 10:05:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-02-2013 / 03:03:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OracleJDK6 methodsFor:'private'!

javaHomeOnWindowsJDKDirectoryPrefix
    ^'jdk1.6'

    "Created: / 19-07-2012 / 11:04:34 / jv"
!

javaHomeOnWindowsJREDirectoryPrefix
    ^'jdk6'

    "Created: / 21-02-2013 / 03:19:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OracleJDK6 methodsFor:'searching'!

searchForJavaHome
    | h |

    "Try registry first..."
    h := self javaHomeOnWindowsFromRegistry.
    h notNil ifTrue:[ javaHome := h. ^ javaHome ].
    ^super searchForJavaHome



    "
        JavaRelease openJDK7 searchForSourcePath; sourcePath
        JavaRelease sunJDK6 searchForSourcePath; sourcePath
    "

    "Created: / 20-02-2013 / 02:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OracleJDK6 methodsFor:'validating'!

validateJavaHome2: home
    | homeFromRegistry f |

    homeFromRegistry := self javaHomeOnWindowsFromRegistry.
    homeFromRegistry = home ifTrue:[ ^ true ].

    "JDK..."
    (f := home / 'LICENSE') exists ifTrue:[
        f readingFileDo:[:s|
            ((s nextLine = 'Please refer to http://java.com/license')
                and:[(home / 'release') exists not
                    and:[(home / 'THIRDPARTYLICENSEREADME-JAVAFX.txt') exists not]]) ifTrue:[ ^ true ]
        ].
    ].
    "JRE..."
    (f := home / 'COPYRIGHT') exists ifTrue:[
        f readingFileDo:[:s|
            (s nextLine includesString: 'Oracle') ifTrue:[
                ^(home / 'LICENSE.txt') exists
            ]
        ].
    ].
    ^false

    

    "
        JavaRelease::OracleJDK6 new validateJavaHome: 'c:\Program Files\Java\jdk1.7.0_13' asFilename
        JavaRelease::OracleJDK6 new validateJavaHome: 'c:\Program Files\Java\jdk1.7.0_13\jre' asFilename
        JavaRelease::OracleJDK6 new validateJavaHome: 'c:\Program Files\Java\jdk1.6.0_34' asFilename
        JavaRelease::OracleJDK6 new validateJavaHome: 'c:\Program Files\Java\jdk1.6.0_34\jre' asFilename

    "

    "Created: / 12-02-2013 / 02:52:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-02-2013 / 02:54:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

validateJavaVersionString:aVersionString
    "Return true if aVersionString (which is what 'java -version' returns)
     matches what I expect."

    ^ aVersionString matches: 'java version "1.6.*' 
! !

!JavaRelease::OracleJDK7 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
! !

!JavaRelease::OracleJDK7 methodsFor:'accessing'!

javaHomeOnWindowsFromRegistry
    "Return path to java home (either JDK or JRE) based on values in registry.
     If not on windows or registry key not found, return nil"

    |entry vsn home prg|

    OperatingSystem isMSWINDOWSlike ifFalse:[ ^ nil ].
    vsn := '1.7'.

    "Search for JDK first..."
    entry := (OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\', vsn).
    entry notNil ifTrue:[
        home := entry valueNamed:'JavaHome'.
        (home notNil and:[(home := home asFilename) exists]) ifTrue:[ ^ home ].
    ].
    "Search for JRE...."
    entry := (OperatingSystem registryEntry key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\', vsn).
    entry notNil ifTrue:[
        home := entry valueNamed:'JavaHome'.
        (home notNil and:[(home := home asFilename) exists]) ifTrue:[ ^ home ].
    ].

    (prg := OperatingSystem getEnvironment:'ProgramFiles(x86)') notEmptyOrNil ifTrue:[
        (home := prg asFilename / 'Java' / 'jre7') exists ifTrue:[ ^ home ].
    ].
    (prg := OperatingSystem getEnvironment:'ProgramFiles') notEmptyOrNil ifTrue:[
        (home := prg asFilename / 'Java' / 'jre7') exists ifTrue:[ ^ home ].
    ].
    ^nil

    "Created: / 16-02-2013 / 02:52:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-02-2013 / 03:51:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnUNIX

    ^ #( '/usr/lib/jvm/java-7-sun' )

    "Created: / 22-11-2010 / 13:31:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 11-02-2013 / 02:49:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnWindows
    |home paths |

    home := self javaHomeOnWindowsFromRegistry.
    home notNil ifTrue:[ ^ Array with: home ].

    paths := OrderedCollection new.
    #(
        'C:\Program Files\Java'
        'C:\Program Files (x86)\Java'
    ) do:[:rootpath|
        | root |

        root := rootpath asFilename.
        root exists ifTrue:[
            "Search for JDK first"
            root directoryContents do:[:dir|
                (dir startsWith:self javaHomeOnWindowsJDKDirectoryPrefix) ifTrue:[
                    | path |
                    (path := root / dir) isDirectory ifTrue:[
                        paths add: path
                    ].
                ].
            ].
            "Search for JDK first"
            root directoryContents do:[:dir|
                (dir startsWith:self javaHomeOnWindowsJREDirectoryPrefix) ifTrue:[
                    | path |
                    (path := root / dir) isDirectory ifTrue:[
                        paths add: path
                    ].
                ].
            ].

        ]
    ].

    ^ paths

    "
     self basicNew javaHomesOnWindows
    "

    "Modified (format): / 19-08-2011 / 00:46:40 / cg"
    "Modified: / 19-07-2012 / 11:04:44 / jv"
    "Modified: / 21-02-2013 / 03:27:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaNativeMethodsImplementation
    "Returns an object that imolements native methods."

    ^ JavaNativeMethodImpl_SunJDK7

    "Created: / 06-02-2013 / 08:39:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 11-02-2013 / 02:50:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name

    ^ 'Oracle JDK 7'

    "Created: / 22-11-2010 / 13:31:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-02-2013 / 03:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    "/There is no OpenJDK 6 for Windows yet...
    OperatingSystem isMSWINDOWSlike ifTrue:[
        ^89
    ].
    ^65

    "Created: / 22-11-2010 / 13:35:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 19-07-2012 / 10:57:55 / jv"
    "Modified: / 16-02-2013 / 09:19:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selector
    "Returns instance-creation selector to get the receiver.
     See JavaRelease class, protocol instance creation"

    ^#oracleJDK7

    "Created: / 27-07-2012 / 10:05:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-02-2013 / 03:03:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OracleJDK7 methodsFor:'private'!

javaHomeOnWindowsJDKDirectoryPrefix
    ^'jdk1.7'

    "Created: / 19-07-2012 / 11:04:34 / jv"
    "Modified: / 21-02-2013 / 03:56:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomeOnWindowsJREDirectoryPrefix
    ^'jdk7'

    "Created: / 21-02-2013 / 03:19:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OracleJDK7 methodsFor:'searching'!

searchForJavaHome
    | h |

    "Try registry first..."
    h := self javaHomeOnWindowsFromRegistry.
    h notNil ifTrue:[ javaHome := h. ^ javaHome ].
    ^super searchForJavaHome



    "
        JavaRelease openJDK7 searchForSourcePath; sourcePath
        JavaRelease sunJDK6 searchForSourcePath; sourcePath
    "

    "Created: / 20-02-2013 / 02:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OracleJDK7 methodsFor:'validating'!

validateJavaHome2: home
    | homeFromRegistry f |

    homeFromRegistry := self javaHomeOnWindowsFromRegistry.
    homeFromRegistry = home ifTrue:[ ^ true ].

    "JDK..."
    (f := home / 'release') exists ifTrue:[
        f readingFileDo:[:s|
            s nextLine = 'JAVA_VERSION="1.7.0"' ifTrue:[ ^ true ]
        ].
    ].
    "JRE..."
    (f := home / 'COPYRIGHT') exists ifTrue:[
        f readingFileDo:[:s|
            (s nextLine includesString: 'Oracle') ifTrue:[
                ^(home / 'THIRDPARTYLICENSEREADME-JAVAFX.txt') exists
            ]
        ].
    ].
    ^false

    

    "
        JavaRelease::OracleJDK7 new validateJavaHome: 'c:\Program Files\Java\jdk1.7.0_13' asFilename
        JavaRelease::OracleJDK7 new validateJavaHome: 'c:\Program Files\Java\jdk1.7.0_13\jre' asFilename
        JavaRelease::OracleJDK7 new validateJavaHome: 'c:\Program Files\Java\jdk1.6.0_34' asFilename
        JavaRelease::OracleJDK7 new validateJavaHome: 'c:\Program Files\Java\jdk1.6.0_34\jre' asFilename

    "

    "Created: / 12-02-2013 / 02:52:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-02-2013 / 02:54:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

validateJavaVersionString:aVersionString
    "Return true if aVersionString (which is what 'java -version' returns)
     matches what I expect."

    ^ aVersionString matches: 'java version "1.7.*' 
! !

!JavaRelease::SunJDK122 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
!

version_SVN
    ^ 'Id::                                                                                                                        '
! !

!JavaRelease::SunJDK122 methodsFor:'accessing'!

javaHomesOnUNIX
    "superclass JavaRelease says that I am responsible to implement this method"

    ^#(
            '/home/jv/Projects/JavaX/jdk1.2.2' "/On Jan Vrany's machine :-)
        )

    "Created: / 22-11-2010 / 13:26:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnWindows

	^ #()

!

name
    "superclass JavaRelease says that I am responsible to implement this method"

    ^ 'Sun JDK 1.2.2'

    "Modified: / 27-07-2012 / 00:14:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    ^10

    "Created: / 22-11-2010 / 13:34:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selector
    "Returns instance-creation selector to get the receiver.
     See JavaRelease class, protocol instance creation"

    ^#sunJDK122

    "Created: / 27-07-2012 / 10:06:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::SunJDK122 methodsFor:'displaying'!

displayString

    ^self isAvailable ifTrue:[
        self name
    ] ifFalse:[
        (self name , ' ' , '(not available)') asText colorizeAllWith: Color gray
    ]

    "Created: / 27-07-2012 / 00:13:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::SunJDK122 methodsFor:'queries'!

isAvailable
    "We don't really support it"

    ^false

    "Created: / 27-07-2012 / 00:04:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::SunJDK122 methodsFor:'validating'!

validateJavaVersionString:aVersionString
    "Return true if aVersionString (which is what 'java -version' returns)
     matches what I expect."

    ^ aVersionString matches: 'java version "1.2.*'
! !

!JavaRelease class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libjava/JavaRelease.st,v 1.10 2013-03-18 17:08:04 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libjava/JavaRelease.st,v 1.10 2013-03-18 17:08:04 cg Exp $'
!

version_SVN
    ^ 'Id::                                                                                                                        '
! !