JavaRelease.st
author Claus Gittinger <cg@exept.de>
Thu, 22 Dec 2005 18:00:03 +0100
changeset 2125 cfa7b540ebf1
parent 749 e898eaeff091
child 2152 1cbdfbcc685c
permissions -rw-r--r--
*** empty log message ***

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

 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:#JavaRelease
	instanceVariableNames:'javaHome classPath sourcePath'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Support'
!

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

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

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

!JavaRelease class methodsFor:'documentation'!

copyright
"
 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
 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.

 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.

"
! !

!JavaRelease class methodsFor:'instance creation'!

any

    | releases |

    releases := self allSubclasses reject: [:rel|rel isAbstract] thenCollect:[:rel|rel new].
    releases := releases asSortedCollection:[:a :b|a priority > b priority].
    releases := releases select:[:rel|rel isAvailable].
    ^releases isEmpty
        ifTrue:[self error: 'No Java release found']
        ifFalse:[releases first]

    "
        JavaRelease any
    "

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

openJDK6

    ^OpenJDK6 new

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

sunJDK122

    ^SunJDK122 new

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

sunJDK6

    ^SunJDK6 new

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

!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'!

classPath

    "Returns a default class path"

    classPath ifNil:[self searchForClassPath].
    ^classPath

    "
        JavaRelease openJDK6 classPath
    "

    "Created: / 27-10-2010 / 19:20:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-10-2010 / 21:48:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHome

    "Answer a Java home"

    javaHome ifNil:
        [javaHome := self searchForJavaHome.
        javaHome ifNil:[self error:'No java home found!!']].
    ^javaHome

    "
        JavaRelease openJDK6 javaHome
    "

    "Created: / 27-10-2010 / 18:59:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-11-2010 / 11:37:15 / 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
!

jreHome

    "Answers the directory where the JRE lives"

    | jreHome |

    ^(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>"
!

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:'queries'!

isAvailable

    ^self javaHomeOrNil notNil

    "
        JavaRelease openJDK6 isAvailable 
        JavaRelease sunJDK6 isAvailable  

    "

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

!JavaRelease methodsFor:'searching'!

searchForClassPath

    | jreHome   |
    classPath := OrderedCollection new.
    jreHome := self jreHome.
    "Ensure, that rt.jar is first"
    classPath add: (jreHome / 'lib' / 'rt.jar') asString.

    self searchForClassPathIn: jreHome / 'lib' .
    self searchForClassPathIn: jreHome / 'lib' / 'ext'.

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

searchForClassPathIn: dir

    dir exists ifFalse:[^self].

    dir directoryContentsAsFilenames do:
        [:file|
        (file suffix = 'jar' and:[file baseName ~= 'rt.jar'])
            ifTrue:[classPath add: file asString]]

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

searchForJavaHome

    | h |

    h := (OperatingSystem getEnvironment:'JAVA_HOME').
    h notNil ifTrue:[
        javaHome := h  asFilename.
        (javaHome / 'jre') exists ifTrue:[
            javaHome := javaHome / 'jre'.
        ].
        ^javaHome
    ].

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

    ^nil

    "Created: / 27-10-2010 / 19:03:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 22-11-2010 / 13:18:15 / 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>"
!

searchForSourcePath

    | src_zip |

    sourcePath := OrderedCollection new.
    src_zip := self javaHome asFilename directory / 'src.zip'.
    src_zip exists ifTrue:[sourcePath add: src_zip asString].

    "
        JavaRelease openJDK6 searchForSourcePath; sourcePath      
    "

    "Created: / 27-10-2010 / 21:15:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-08-2011 / 22:40:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease methodsFor:'validating'!

validateJavaHome: home

    "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: / 27-10-2010 / 19:14:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-10-2010 / 21:47:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaRelease::OpenJDK6 methodsFor:'accessing'!

javaHomesOnUNIX
    ^ #( '/usr/lib/jvm/java-6-openjdk/jre' )

    "Modified: / 07-08-2011 / 20:38:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

javaHomesOnWindows
    |vsn home heuristics|

    self breakPoint:#jv.

    heuristics :=
       #( 
         'C:\Program Files (x86)\Java\jdk1.6.0_24\jre' 
         'C:\Program Files\Java\jdk1.6.0_24\jre'
        ).

    vsn := (OperatingSystem registryEntry
        key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit')
            valueNamed:'CurrentVersion'.
    vsn notNil ifTrue:[
        home := (OperatingSystem registryEntry
            key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\',vsn)
                valueNamed:'JavaHome'.
        home notNil ifTrue:[
            ^ (Array with:(home,'\jre'))
            , heuristics
        ].
    ].
    ^ heuristics

    "
     self basicNew javaHomesOnWindows
    "

    "Modified: / 07-08-2011 / 20:38:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 19-08-2011 / 00:46:40 / cg"
!

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

!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-10-2010 / 21:42:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

priority

    ^10

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

!JavaRelease::SunJDK6 methodsFor:'accessing'!

javaHomesOnUNIX

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

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

javaHomesOnWindows

    self breakPoint:#jv.

    ^ #( 'C:\Program Files (x86)\Java\jdk1.6.0_24' 
	     'C:\Program Files\Java\jdk1.6.0_24'
	)

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

name

    ^ 'Sun JDK 6'

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

priority

    ^75

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

!JavaRelease class methodsFor:'documentation'!

version_CVS
    ^ '§Header: /cvs/stx/stx/libjava/JavaRelease.st,v 1.2 2011/08/18 22:47:38 cg Exp §'
!

version_SVN
    ^ '$Id$'
! !