-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathproject.clj
148 lines (136 loc) · 6.86 KB
/
project.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
(require '[clojure.string :as string])
(defn deep-merge
{:license "Copyright © 2019 James Reeves
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version."}
([])
([a] a)
([a b]
(when (or a b)
(letfn [(merge-entry [m e]
(let [k (key e)
v' (val e)]
(if (contains? m k)
(assoc m k (let [v (get m k)]
(cond
(and (map? v) (map? v')) (deep-merge v v')
(and (coll? v) (coll? v')) (into (empty v)
(distinct (into v v')))
true (do
(assert (not (and v v')))
(or v v')))))
(assoc m k v'))))]
(->> b
seq
(reduce merge-entry (or a {}))))))
([a b & more]
(reduce deep-merge (or a {}) (cons b more))))
(def repo-mapping (atom {}))
(def git-hosts (atom #{}))
(defn process-dep-entry! [{:keys [jars-atom subprojects-atom]}
[k {:keys [mvn/version sha exclusions git/url local/root]}]]
{:pre [@jars-atom @subprojects-atom]}
(when url
(let [{:keys [host path]} (-> url java.net.URI. bean)
[gh-org gh-project] (-> path
(string/replace #"^/" "")
(string/replace #"\.git$" "")
(string/split #"/"))]
(swap! repo-mapping assoc k {:coordinates (symbol (str gh-org "/" gh-project))})
(swap! git-hosts conj host)))
(if-not root
[k (or version sha) :exclusions (->> exclusions
(mapv (fn [e]
(-> e str (string/replace #"\$.*" "") symbol))))]
(do
(if (string/ends-with? root ".jar")
(swap! jars-atom conj root)
(let [f (java.io.File. root "deps.edn")]
(assert (-> f .exists)
(str "Expected " root " to denote an existing deps.edn file"))
(swap! subprojects-atom conj (.getCanonicalPath f))))
nil)))
(defn prefix [filename item]
(-> filename java.io.File. .getParent (java.io.File. item) .getCanonicalPath))
(defn add-jars [m jars-atom sub? deps-edn-filename]
{:pre [@jars-atom]}
(cond-> m
(seq @jars-atom) (update :resource-paths (fn [v]
(cond->> @jars-atom
true (into (or v []))
sub? (mapv (partial prefix deps-edn-filename)))))))
(declare add-subprojects)
(defn process-profiles [aliases deps-edn-filename root-deps-edn-filename]
(->> (for [[k {:keys [override-deps extra-deps extra-paths replace-paths]}] aliases
:let [jars-atom (atom #{})
subprojects-atom (atom #{} :validator (fn [v]
(not (contains? v deps-edn-filename))))
sub? (not= deps-edn-filename root-deps-edn-filename)
sot (cond->> [[] extra-paths replace-paths]
true (reduce into)
true distinct
sub? (map (partial prefix deps-edn-filename))
true vec)]]
[k (-> {:dependencies (->> [override-deps extra-deps]
(keep (partial map (partial process-dep-entry! {:jars-atom jars-atom
:subprojects-atom subprojects-atom})))
(apply concat)
distinct
vec)
:source-paths sot
:test-paths sot}
(add-jars jars-atom sub? deps-edn-filename)
(add-subprojects subprojects-atom deps-edn-filename))])
(into {})))
(defn parse-deps-edn [deps-edn-filename root-deps-edn-filename]
(let [{:keys [aliases deps paths]} (clojure.edn/read-string (slurp deps-edn-filename))
profiles (process-profiles aliases deps-edn-filename root-deps-edn-filename)
jars-atom (atom #{})
subprojects-atom (atom #{}
:validator (fn [v]
(not (contains? v root-deps-edn-filename))))
dependencies (->> deps
(keep (partial process-dep-entry! {:jars-atom jars-atom
:subprojects-atom subprojects-atom}))
(vec))
sub? (not= deps-edn-filename root-deps-edn-filename)
sot (cond->> paths
sub? (mapv (partial prefix deps-edn-filename)))]
(-> {:dependencies dependencies
:profiles (clojure.set/rename-keys profiles {:test-common :test})
:source-paths sot
:test-paths sot
:resource-paths (cond->> @jars-atom
sub? (map (partial prefix deps-edn-filename))
true vec)}
(add-subprojects subprojects-atom root-deps-edn-filename))))
(defn add-subprojects [m subprojects-atom root-deps-edn-filename]
(->> @subprojects-atom
(reduce (fn [v subproject]
(deep-merge v
(parse-deps-edn subproject root-deps-edn-filename)))
m)))
(let [f (-> "deps.edn" java.io.File. .getCanonicalPath)
{:keys [profiles dependencies resource-paths source-paths]} (parse-deps-edn f f)]
(defproject org.rksm/suitable (or (not-empty (System/getenv "PROJECT_VERSION"))
"0.0.0")
:license {:name "MIT"
:url "https://opensource.org/licenses/MIT"}
:source-paths ~source-paths
:resource-paths ~resource-paths
:dependencies ~dependencies
:profiles ~profiles
:plugins [[reifyhealth/lein-git-down "0.4.0"]]
:middleware [lein-git-down.plugin/inject-properties]
:git-down ~(deref repo-mapping)
:repositories ~(->> @git-hosts
(map (fn [r]
(let [n (-> r (string/split #"\.") first)
u (str "git://" r)]
[[(str "public-" n) {:url u}]
[(str "private-" n) {:url u :protocol :ssh}]])))
(apply concat)
vec)
:deploy-repositories [["clojars" {:url "https://clojars.org/repo"
:username :env/clojars_username
:password :env/clojars_password
:sign-releases false}]]))