Skip to content

Instantly share code, notes, and snippets.

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

cgrand commented May 10, 2012

J'ai un doute sur la gestion du recreate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment