Read profiles from ~/.lein/profiles.clj and :profiles key in defproject.
This commit is contained in:
parent
7a59a30193
commit
d490acd9d7
3 changed files with 25 additions and 10 deletions
|
@ -64,9 +64,9 @@
|
||||||
(def profiles
|
(def profiles
|
||||||
"Profiles get merged into the project map. The :dev and :user
|
"Profiles get merged into the project map. The :dev and :user
|
||||||
profiles are active by default."
|
profiles are active by default."
|
||||||
(atom {:dev {:test-path ["test"]
|
(atom (merge {:dev {:test-path ["test"]
|
||||||
:resources-path ["dev-resources"]}
|
:resources-path ["dev-resources"]}}
|
||||||
:user (user/profile)}))
|
(user/profiles))))
|
||||||
|
|
||||||
;; Modified merge-with to provide f with the conflicting key.
|
;; Modified merge-with to provide f with the conflicting key.
|
||||||
(defn- merge-with-key [f & maps]
|
(defn- merge-with-key [f & maps]
|
||||||
|
@ -105,11 +105,14 @@
|
||||||
(defn- merge-profile [project profile]
|
(defn- merge-profile [project profile]
|
||||||
(merge-with-key profile-key-merge project profile))
|
(merge-with-key profile-key-merge project profile))
|
||||||
|
|
||||||
(defn ^:internal merge-profiles [project profiles-to-apply]
|
(defn- profiles-for [project profiles-to-apply]
|
||||||
;; We reverse because we want profile values to override the
|
;; We reverse because we want profile values to override the
|
||||||
;; project, so we need "last wins" in the reduce, but we want the
|
;; project, so we need "last wins" in the reduce, but we want the
|
||||||
;; first profile specified by the user to take precedence.
|
;; first profile specified by the user to take precedence.
|
||||||
(reduce merge-profile project (map @profiles (reverse profiles-to-apply))))
|
(map (merge @profiles (:profiles project)) (reverse profiles-to-apply)))
|
||||||
|
|
||||||
|
(defn ^:internal merge-profiles [project profiles-to-apply]
|
||||||
|
(reduce merge-profile project (profiles-for project profiles-to-apply)))
|
||||||
|
|
||||||
(defn read
|
(defn read
|
||||||
"Read project map out of file, which defaults to project.clj."
|
"Read project map out of file, which defaults to project.clj."
|
||||||
|
|
|
@ -33,5 +33,7 @@
|
||||||
(for [plugin (.listFiles (io/file (leiningen-home) "plugins"))]
|
(for [plugin (.listFiles (io/file (leiningen-home) "plugins"))]
|
||||||
(.getAbsolutePath plugin)))
|
(.getAbsolutePath plugin)))
|
||||||
|
|
||||||
(defn profile []
|
(defn profiles []
|
||||||
{})
|
(let [profiles-file (io/file (leiningen-home) "profiles.clj")]
|
||||||
|
(if (.exists profiles-file)
|
||||||
|
(load-file (.getAbsolutePath profiles-file)))))
|
|
@ -1,7 +1,14 @@
|
||||||
(ns leiningen.core.test.project
|
(ns leiningen.core.test.project
|
||||||
(:refer-clojure :exclude [read])
|
(:refer-clojure :exclude [read])
|
||||||
(:use [clojure.test]
|
(:use [clojure.test]
|
||||||
[leiningen.core.project]))
|
[leiningen.core.project])
|
||||||
|
(:require [leiningen.core.user :as user]))
|
||||||
|
|
||||||
|
(use-fixtures :once
|
||||||
|
(fn [f]
|
||||||
|
;; Can't have user-level profiles interfering!
|
||||||
|
(with-redefs [user/plugins (constantly {})]
|
||||||
|
(f))))
|
||||||
|
|
||||||
(deftest test-read-project
|
(deftest test-read-project
|
||||||
(is (= {:name "leiningen", :group "leiningen", :version "2.0.0-SNAPSHOT",
|
(is (= {:name "leiningen", :group "leiningen", :version "2.0.0-SNAPSHOT",
|
||||||
|
@ -41,5 +48,8 @@
|
||||||
|
|
||||||
(deftest test-merge-profile-paths
|
(deftest test-merge-profile-paths
|
||||||
(with-redefs [profiles test-profiles]
|
(with-redefs [profiles test-profiles]
|
||||||
(is (= {:resources-path ["/etc/myapp" "test/hi" "resources"]}
|
(is (= ["/etc/myapp" "test/hi" "blue-resources" "resources"]
|
||||||
(merge-profiles {:resources-path ["resources"]} [:qa :test])))))
|
(-> {:resources-path ["resources"]
|
||||||
|
:profiles {:blue {:resources-path ["blue-resources"]}}}
|
||||||
|
(merge-profiles [:qa :test :blue])
|
||||||
|
:resources-path)))))
|
Loading…
Reference in a new issue