meyvn.nrepl_middleware.dynamic.clj Maven / Gradle / Ivy
The newest version!
(ns meyvn.nrepl-middleware.dynamic
(:require [clojure.tools.deps :as deps]
[meyvn.nrepl-middleware.utils :refer [find-classloader]]
[clojure.tools.deps.util.maven :refer [standard-repos]]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log])
(:import [clojure.lang DynamicClassLoader]
[java.io File]))
(defn add-loader-url
"Add url string or URL to loader"
[loader url]
(.addURL ^DynamicClassLoader loader url))
(defn get-urls
([query]
(let [[lib version] (str/split query #" ")]
(get-urls (symbol lib) {:mvn/version version})))
([lib coord]
(get-urls lib coord {:mvn/repos standard-repos}))
([lib coord config]
(let [dep-libs (deps/resolve-deps (merge config {:deps {lib coord}}) {})
paths (mapcat :paths (vals dep-libs))]
(->> paths (map io/file) (map #(.toURL ^File %))))))
(defn add-lib [query]
(if-let [cl (find-classloader)]
(let [urls (get-urls query)]
(run! (partial add-loader-url cl) urls)
true)
false))
© 2015 - 2024 Weber Informatics LLC | Privacy Policy