Make profiles string in target path smarter
When generating a profile scope string for the target path, any subset of active profiles that matches a composite profile are replaced with the composite. For example, the profiles [:base :system :user :provided :dev :foo] would be represented as "default+foo", because the :default profile is a composite of [:base :system :user :provided :dev].
This commit is contained in:
parent
9f2f9eb695
commit
3981ea4971
2 changed files with 26 additions and 1 deletions
|
@ -467,11 +467,24 @@
|
|||
(.toString (BigInteger. 1 (-> (java.security.MessageDigest/getInstance "SHA1")
|
||||
(.digest (.getBytes content)))) 16))
|
||||
|
||||
(defn- keyword-composite-profile? [profile]
|
||||
(and (composite-profile? profile) (every? keyword? profile)))
|
||||
|
||||
(defn- normalize-profile-names [project profiles]
|
||||
(reduce
|
||||
(fn [profiles [composite keys]]
|
||||
(if (set/subset? (set keys) (set profiles))
|
||||
(->> profiles (remove (set keys)) (cons composite))
|
||||
profiles))
|
||||
profiles
|
||||
(filter (comp keyword-composite-profile? val)
|
||||
(-> project meta :profiles))))
|
||||
|
||||
(defn profile-scope-target-path [project profiles]
|
||||
(let [n #(if (map? %) (subs (sha1 (pr-str %)) 0 8) (name %))]
|
||||
(if (:target-path project)
|
||||
(update-in project [:target-path] format
|
||||
(s/join "+" (map n (remove #{:default :provided} profiles))))
|
||||
(s/join "+" (map n (normalize-profile-names project profiles))))
|
||||
project)))
|
||||
|
||||
(defn target-path-subdirs [{:keys [target-path] :as project} key]
|
||||
|
|
|
@ -590,3 +590,15 @@
|
|||
[["central" {:url "https://repo1.maven.org/maven2/"
|
||||
:snapshots false}]
|
||||
["clojars" {:url "https://clojars.org/repo/"}]]}})))))))
|
||||
|
||||
(deftest test-profile-scope-target-path
|
||||
(let [project (with-meta
|
||||
{:target-path "target/%s"}
|
||||
{:profiles {:ab [:a :b] :a {} :b {} :c {} :d {}}})]
|
||||
(are [ps tp] (= (profile-scope-target-path project ps) {:target-path tp})
|
||||
[:a :b] "target/ab"
|
||||
[:a :b :c] "target/ab+c"
|
||||
[:b :c] "target/b+c"
|
||||
[:b :a] "target/ab"
|
||||
[:c :b :a] "target/ab+c"
|
||||
[:a] "target/a")))
|
||||
|
|
Loading…
Reference in a new issue