Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn lein-env
"Create a new classlojure based leiningen environment by fetching all jars
and classes directories found inside the ccw.leiningen-core plugin."
(let [leiningen-core (bundle-dir "ccw.leiningen-core")
jar (fn [f] (and (.isFile f) (.endsWith (.getName f) ".jar")))
classes-dir (fn [d] (let [manifest (io/file d "META-INF" "MANIFEST.MF")]
(and (.exists manifest)
(.isFile manifest))))
libs (->> leiningen-core file-seq (filter #(or (jar %) (classes-dir %))))]
(apply c/classlojure libs)))
(defonce ^{:doc
"Ref of map of \"project-name\" -> delay of classlojure environment.
e.g. : (ref {\"project-foo\" (delay (lein-env))})" }
projects-envs (ref {}))
(defn project-env!
"Returns a classlojure environment for project, creating one if none exists yet,
or if recreate? is true."
[project & recreate?]
(let [pname (-> project e/project .getName)]
(commute projects-envs
#(if (or recreate? (not (% pname)))
(assoc % pname (delay (lein-env)))
@(@projects-envs pname)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.