Created
June 11, 2012 08:39
-
-
Save charles-dyfis-net/2909106 to your computer and use it in GitHub Desktop.
clojure.osgi aware nREPL middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn osgi-bundle-handler | |
"If the namespace currently associated with this REPL has an OSGi | |
bundle associated, use this to set osgi/*bundle* and | |
clojure.lang.Compiler/LOADER." | |
[h] | |
(fn [msg] | |
(let [ns-meta (meta (get (deref (:session msg)) #'clojure.core/*ns*)) | |
bundle (and ns-meta (:clojure.osgi.core/bundle ns-meta)) | |
classloader (or (:repl-classloader ns-meta) | |
(and bundle (osgi/bundle-class-loader bundle))) | |
dynamic-loader (and classloader (clojure.lang.DynamicClassLoader. classloader))] | |
(when bundle | |
(swap! (:session msg) assoc #'osgi/*bundle* bundle)) | |
(when dynamic-loader | |
(swap! (:session msg) assoc clojure.lang.Compiler/LOADER dynamic-loader)) | |
(h msg)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment