JavaLibraries.st
branchdirectory_structure_refactoring
changeset 1818 2e5ed72e7dfd
parent 1691 826f8d7dc0df
child 1824 0200794e93f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/JavaLibraries.st	Thu Nov 15 22:10:02 2012 +0000
@@ -0,0 +1,203 @@
+"
+ 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:#JavaLibraries
+	instanceVariableNames:''
+	classVariableNames:'MavenRun'
+	poolDictionaries:''
+	category:'Languages-Java-Support'
+!
+
+!JavaLibraries 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
+
+"
+! !
+
+!JavaLibraries class methodsFor:'accessing'!
+
+directory
+
+    | dir |
+
+    dir := OperatingSystem getEnvironment: 'LIBJAVA_LIBS'.
+    dir notNil and:[(dir := dir asFilename) exists ifTrue:[ ^ dir ]].
+
+    ^Java cacheDirectory / 'libs'
+
+    "
+        JavaLibraries directory   
+    "
+
+    "Created: / 08-04-2011 / 16:27:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+url
+
+    ^(Smalltalk at:#stx_libjava) svnRepositoryUrlBase , '/libs'
+
+    "Created: / 08-04-2011 / 16:32:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaLibraries class methodsFor:'private'!
+
+checkoutDirectory
+
+"/    OperatingSystem getNetworkAddresses size < 2 
+"/        ifTrue:
+"/           [self error: 'No network connection!!'. ^self].
+
+    (OperatingSystem
+        executeCommand:('svn co "%1" "%2"' bindWith: self url with: self directory asString))
+        ifFalse:
+            [self error: 'Cannot checkout libraries!!'. ^self].
+
+    "Created: / 08-04-2011 / 16:38:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+runMaven
+
+    MavenRun ~~ true ifTrue:[
+        (OperatingSystem executeCommand:'mvn package' inDirectory: self directory asString)
+            ifFalse:[self error: 'Cannot run maven to download libraries!!'. ^self].
+        MavenRun := true
+    ].
+
+    "Created: / 20-08-2012 / 19:39:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+updateDirectory
+
+"/    OperatingSystem getNetworkAddresses size < 2 
+"/        ifTrue:
+"/            [^self].
+
+    (OperatingSystem
+        executeCommand:('svn update "%1" "%2"' bindWith: self url with: self directory asString))
+"/        ifFalse:
+"/            [self error: 'Cannot update libraries!!' mayProceed: true. ^self].
+
+    "Created: / 08-04-2011 / 16:38:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaLibraries class methodsFor:'utilities'!
+
+addToClassPath
+    | dir |
+
+    (dir := self directory / 'libs') exists ifFalse: [ self update ].
+    dir recursiveDirectoryContentsAsFilenames do: [ :file | 
+        file suffix = 'jar' ifTrue: [ Java addToClassPath: file pathName name: 'stx:libjava - libraries - ' , file baseName ]
+    ].
+
+    (dir := self directory / 'libs-src') exists ifTrue:[
+        dir recursiveDirectoryContentsAsFilenames do: [ :file | 
+            file suffix = 'jar' ifTrue: [ Java addToSourcePath: file pathName name: 'stx:libjava - libraries - ' , file baseName ]
+        ]
+    ].
+
+
+
+
+    "
+        JavaLibraries addToClassPath.
+        Java classPath"
+
+    "Created: / 02-09-2011 / 09:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-11-2011 / 12:51:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 22-08-2012 / 06:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+addToClassPath: jarname
+
+    | dir jar |
+
+    (dir := self directory) exists 
+        ifFalse:[self update].
+
+    (jar := dir / jarname) exists ifTrue: [
+        Java addToClassPath: jar pathName name: 'stx:libjava libraries'
+    ] ifFalse:[
+        self error:'Library ' , jarname , ' not found in ', dir pathName
+    ].
+
+    "
+        JavaLibraries addToClassPath:'junit4.jar'.
+        Java classPath
+    "
+
+    "Created: / 08-04-2011 / 16:49:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+flush
+
+    self directory recursiveRemove
+
+    "Created: / 08-04-2011 / 16:27:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+update
+
+    | dir |
+    dir := self directory.
+    dir exists 
+        ifTrue: [self updateDirectory]
+        ifFalse:[self checkoutDirectory].
+    self runMaven.                
+
+    "
+        JavaLibraries flush
+        JavaLibraries update.
+
+        UserPreferences current fileBrowserClass openOn: self directory
+
+    "
+
+    "Created: / 08-04-2011 / 16:29:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaLibraries class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id$'
+! !
+