Skip to content

Instantly share code, notes, and snippets.

@laurentpetit
Forked from charles-dyfis-net/gist:2909106
Created June 11, 2012 21:37
Show Gist options
  • Save laurentpetit/2912899 to your computer and use it in GitHub Desktop.
Save laurentpetit/2912899 to your computer and use it in GitHub Desktop.
clojure.osgi aware nREPL middleware
(defn classloader-handler
"Call cl-provider with the session each time a msg is sent.
The resulting classloader will then be used as context for executing msg."
[h cl-provider]
(fn [msg]
(let [classloader (cl-provider (:session msg))
dynamic-loader (and classloader (clojure.lang.DynamicClassLoader. classloader))]
(when dynamic-loader
(swap! (:session msg) assoc clojure.lang.Compiler/LOADER dynamic-loader))
(h msg))))
(defn osgi-classloader-provider
[session]
(let [ns-meta (meta (get (deref session) #'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)))]
classloader))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment