-
-
Save laurentpetit/2912899 to your computer and use it in GitHub Desktop.
clojure.osgi aware nREPL middleware
This file contains 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 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