Skip to content

Instantly share code, notes, and snippets.

@cgrand
Forked from laurentpetit/gist:2651931
Created May 10, 2012 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/2652814 to your computer and use it in GitHub Desktop.
Save cgrand/2652814 to your computer and use it in GitHub Desktop.
(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)]
(dosync
(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