Skip to content

Instantly share code, notes, and snippets.

@charles-dyfis-net
Created June 11, 2012 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save charles-dyfis-net/2909106 to your computer and use it in GitHub Desktop.
Save charles-dyfis-net/2909106 to your computer and use it in GitHub Desktop.
clojure.osgi aware nREPL middleware
(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