Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
91 lines (80 sloc) 3.21 KB
(ns lucid.package.resolve
(:require [lucid.aether :as aether]
[ :as classpath]
[hara.reflect :as reflect]
[clojure.set :as set]
[clojure.string :as string])
(:import [clojure.lang Symbol IPersistentVector]))
(defn list-dependencies
"list the dependencies for a particular coordinate
(list-dependencies '[[im.chit/hara.test \"2.4.8\"]])
=> '[[im.chit/hara.class.enum \"2.4.8\"]
[im.chit/hara.class.inheritance \"2.4.8\"]
[im.chit/hara.common.checks \"2.4.8\"]
[im.chit/hara.common.error \"2.4.8\"]
[im.chit/hara.common.primitives \"2.4.8\"]
[im.chit/hara.common.string \"2.4.8\"]
[im.chit/ \"2.4.8\"]
[im.chit/ \"2.4.8\"]
[im.chit/hara.event \"2.4.8\"]
[im.chit/ \"2.4.8\"]
[im.chit/ \"2.4.8\"]
[im.chit/ \"2.4.8\"]
[im.chit/hara.namespace.import \"2.4.8\"]
[im.chit/hara.protocol.string \"2.4.8\"]
[im.chit/ \"2.4.8\"]
[im.chit/hara.test \"2.4.8\"]]"
{:added "1.2"}
(list-dependencies coordinates {}))
([coordinates {:keys [repositories] :as opts}]
(->> coordinates
(map (fn [coord]
(-> (aether/aether opts)
(aether/resolve-dependencies coord))))
(apply set/union)
(defn resolve-with-dependencies
"resolves an entry with all artifact dependencies
(resolve-with-dependencies '
'[im.chit/hara.test \"2.4.8\"])
=> '[[im.chit/ \"2.4.8\"]
{:added "1.2"}
([x context] (resolve-with-dependencies x context {}))
([x context {:keys [repositories] :as opts}]
(let [resolve-entry (fn [x context]
(classpath/resolve-entry x context {:tag :coord}))]
(cond (string? context)
(->> (list-dependencies [context] opts)
(resolve-entry x))
(vector? context)
(let [n (first context)]
(cond (or (string? n)
(instance? IPersistentVector n))
(resolve-entry x context)
(symbol? n)
(->> (list-dependencies [context] repositories)
(resolve-entry x))))
(throw (Exception. (str "Not supported: " x " " context)))))))
(def add-url
(reflect/query-class ["addURL" :#]))
(defn pull
"pulls down the necessary dependencies from maven and adds it to the project
(pull '[org.clojure/core.match \"0.2.2\"])
=> '[[org.clojure/core.cache \"0.6.3\"]
[org.clojure/core.match \"0.2.2\"]
[org.clojure/core.memoize \"0.5.6\"]
[org.clojure/data.priority-map \"0.0.2\"]
[org.clojure/tools.analyzer \"0.1.0-beta12\"]
[org.clojure/tools.analyzer.jvm \"0.1.0-beta12\"]
[org.ow2.asm/asm-all \"4.1\"]]"
{:added "1.1"}
(let [deps (list-dependencies [coord])]
(doseq [dep deps]
(add-url (.getClassLoader clojure.lang.RT)
( (str "file:" (classpath/artifact :path dep)))))