comparison org/util.org @ 388:4c37d39a3cf6

removed dependency on swank, which had silently bit rotted. Restored functionality of mege-import-jme3.
author Robert McIntyre <rlm@mit.edu>
date Thu, 06 Jun 2013 10:09:37 -0400
parents 9fa92af29c3a
children 6ba908c1a0a9 a44d8a28cbea
comparison
equal deleted inserted replaced
387:13059eb62899 388:4c37d39a3cf6
14 * Imports 14 * Imports
15 15
16 #+name: import 16 #+name: import
17 #+begin_src clojure :results silent 17 #+begin_src clojure :results silent
18 (ns cortex.import 18 (ns cortex.import
19 (:require swank.util.class-browse)) 19 (:import java.io.File java.util.jar.JarFile))
20 20
21 (defn permissive-import 21 (defn permissive-import
22 [classname] 22 [classname]
23 (eval `(try (import '~classname) 23 (eval `(try (import '~classname)
24 (catch java.lang.Exception e# 24 (catch java.lang.Exception e#
30 (.startsWith classname "com.jme3.") 30 (.startsWith classname "com.jme3.")
31 ;; Don't import the LWJGL stuff since it can throw exceptions 31 ;; Don't import the LWJGL stuff since it can throw exceptions
32 ;; upon being loaded. 32 ;; upon being loaded.
33 (not (re-matches #".*Lwjgl.*" classname)))) 33 (not (re-matches #".*Lwjgl.*" classname))))
34 34
35 (defn jme-classes 35 (defn jme-jars []
36 "returns a list of all jme3 classes" 36 (map
37 [] 37 #(JarFile. (File. %))
38 (filter (partial re-matches #".*jME3.*")
39 (clojure.string/split
40 (System/getProperty "java.class.path") #":"))))
41
42 (defn jme-class-names []
38 (filter 43 (filter
39 jme-class? 44 jme-class?
40 (map :name 45 (map
41 swank.util.class-browse/available-classes))) 46 (comp
42 47 #(.replace % File/separator ".")
48 #(clojure.string/replace % ".class" ""))
49 (filter
50 (partial re-matches #".*\.class$")
51 (mapcat
52 #(map
53 str
54 (enumeration-seq
55 (.entries %)))
56 (jme-jars))))))
57
43 (defn mega-import-jme3 58 (defn mega-import-jme3
44 "Import ALL the jme classes. For REPL use." 59 "Import ALL the jme classes. For REPL use."
45 [] 60 []
46 (doall 61 (dorun
47 (map (comp permissive-import symbol) (jme-classes)))) 62 (map (comp permissive-import symbol) (jme-class-names))))
48 #+end_src 63 #+end_src
49 64
50 jMonkeyEngine3 has a plethora of classes which can be overwhelming to 65 jMonkeyEngine3 has a plethora of classes which can be overwhelming to
51 manage. This code uses reflection to import all of them. Once I'm 66 manage. This code uses reflection to import all of them. Once I'm
52 happy with the general structure of a namespace I can deal with 67 happy with the general structure of a namespace I can deal with