Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 5bb8acc

Browse files
author
Yannick Scherer
committed
[#83] Read managed dependencies from project map
1 parent f680603 commit 5bb8acc

File tree

5 files changed

+75
-45
lines changed

5 files changed

+75
-45
lines changed

lein-ancient/src/leiningen/ancient/artifact/check.clj

+7-10
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,12 @@
8383
8484
We don't want to add a version to `:dependencies` but we want to
8585
check/update the one in `:managed-dependencies` - thus, we have to
86-
remove all entries in `:dependencies` that have a managed counterpart."
87-
[artifacts]
88-
(let [managed-artifacts
89-
(->> artifacts
90-
(filter
91-
(fn [{:keys [keys artifact]}]
92-
(contains? (set keys) :managed-dependencies)))
93-
(map (comp :symbol :artifact))
94-
(set))]
86+
remove all entries in `:dependencies` that have a managed counterpart.
87+
88+
We expect the list of dependencies to treat as managed as an option
89+
value to handle inheritance better."
90+
[{:keys [managed-dependencies]} artifacts]
91+
(let [managed-artifacts (set (map first managed-dependencies))]
9592
(remove
9693
(fn [{{:keys [symbol version-string]} :artifact, ks :keys}]
9794
(and (not (contains? (set ks) :managed-dependencies))
@@ -152,7 +149,7 @@
152149
"
153150
[options artifacts]
154151
(->> (collect-artifacts-from-map options [] artifacts)
155-
(remove-managed-dependencies)
152+
(remove-managed-dependencies options)
156153
(keep #(mark-artifact options %))))
157154

158155
;; ## Check

lein-ancient/src/leiningen/ancient/artifact/options.clj

+5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,16 @@
100100
(seq exclude) (update-in [:exclude] concat exclude)
101101
true (merge options))))
102102

103+
(defn- managed-dependencies-options
104+
[options {:keys [managed-dependencies]}]
105+
(assoc options :managed-dependencies managed-dependencies))
106+
103107
(defn options
104108
"Prepare the option map."
105109
([] (options {}))
106110
([opts]
107111
(-> {:cache (ref {})}
112+
(managed-dependencies-options opts)
108113
(repository-options opts)
109114
(version-options opts)
110115
(selector-options opts))))

lein-ancient/src/leiningen/ancient/utils.clj

+9-7
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,23 @@
9090
(defn parse
9191
"Create a map of `:artifact-opts`, `:opts` and `:args` from the given
9292
project and arguments."
93-
[{:keys [repositories mirrors] :as project} args
93+
[{:keys [repositories mirrors managed-dependencies] :as project} args
9494
& {:keys [change-defaults exclude fixed]}]
9595
(try
9696
(let [[opts' rst] (cli/parse args
9797
:change-defaults change-defaults
9898
:exclude exclude)
9999
opts (merge opts' fixed)
100-
artifact-opts (-> (assoc opts
101-
:repositories repositories
102-
:mirrors mirrors)
100+
artifact-opts (-> opts
101+
(merge
102+
{:managed-dependencies managed-dependencies
103+
:repositories repositories
104+
:mirrors mirrors})
103105
(o/options))]
104106
{:artifact-opts artifact-opts
105-
:opts opts
106-
:project project
107-
:args rst})
107+
:opts opts
108+
:project project
109+
:args rst})
108110
(catch Throwable t
109111
(errorf "%s" (.getMessage t)))))
110112

lein-ancient/test/leiningen/ancient/artifact/check_test.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
[org.clojure/clojure "1.5.1"]
107107
[managed]]
108108
:managed-dependencies [[managed "0.2.0"]]}
109-
opts (o/options {})
109+
opts (o/options
110+
{:managed-dependencies '[[managed "0.2.0"]]})
110111
artifacts (->> (collect-artifacts opts data)
111112
(filter :include?)
112113
(map (juxt (comp :symbol :artifact)

lein-ancient/test/leiningen/ancient/artifact/files_test.clj

+52-27
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,30 @@
77
(:import [java.io StringWriter]))
88

99
(defn- const-opts
10-
[v]
10+
[v & [extra-opts]]
1111
(o/options
12-
{:plugins? true
13-
:repositories
14-
{"const" (constantly [v])}}))
12+
(merge
13+
extra-opts
14+
{:plugins? true
15+
:repositories
16+
{"const" (constantly [v])}})))
17+
18+
(defn- test-upgrade!
19+
[?file opts contents expected outdated-count]
20+
(with-temp-file [tmp contents]
21+
(let [f (?file tmp)
22+
r (read! f)]
23+
(is (satisfies? Dependencies f))
24+
(is (satisfies? Dependencies r))
25+
(let [outdated (check! r opts)]
26+
(is (= outdated-count (count outdated)))
27+
(is (every? :latest outdated))
28+
(is (every? #{"0.1.1"} (map (comp :version-string :latest) outdated)))
29+
(let [u (upgrade! r outdated)]
30+
(is (satisfies? Dependencies u))
31+
(is (= expected (write-string! u)))
32+
(write-out! u)
33+
(is (= expected (slurp tmp))))))))
1534

1635
(deftest t-project-file-upgrading
1736
(are [?fmt ?file]
@@ -21,36 +40,14 @@
2140
opts (const-opts "0.1.1")
2241
contents (format ?fmt (pr-str ?artifact))
2342
expected (format ?fmt (pr-str upgraded))]
24-
(with-temp-file [tmp contents]
25-
(let [f (?file tmp)
26-
r (read! f)]
27-
(is (satisfies? Dependencies f))
28-
(is (satisfies? Dependencies r))
29-
(let [outdated (check! r opts)]
30-
(is (= 1 (count outdated)))
31-
(is (every? :latest outdated))
32-
(is (every? #{"0.1.1"} (map (comp :version-string :latest) outdated)))
33-
(let [u (upgrade! r outdated)]
34-
(is (satisfies? Dependencies u))
35-
(is (= expected (write-string! u)))
36-
(write-out! u)
37-
(is (= expected (slurp tmp))))))))
43+
(test-upgrade! ?file opts contents expected 1))
3844
'[artifact]
3945
'[artifact "0.1.0"]
4046
'[artifact "0.1.0" :exclusions [other]])
4147
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
4248
" :dependencies [%s])")
4349
project-file
4450

45-
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
46-
" :managed-dependencies [%s])")
47-
project-file
48-
49-
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
50-
" :dependencies [[artifact]]"
51-
" :managed-dependencies [%s])")
52-
project-file
53-
5451
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
5552
" :dependencies [#_[ignore] %s])")
5653
project-file
@@ -63,6 +60,34 @@
6360
" %s]}")
6461
#(profiles-file % [:profiles :prof])))
6562

63+
(deftest t-project-file-upgrading-with-managed-dependencies
64+
(are [?fmt ?outdated-count]
65+
(are [?artifact]
66+
(let [[a _ & rst] ?artifact
67+
upgraded (reduce conj [a "0.1.1"] rst)
68+
opts (const-opts
69+
"0.1.1"
70+
{:managed-dependencies '[[artifact "0.2.0"]]})
71+
contents (format ?fmt (pr-str ?artifact))
72+
expected (format ?fmt (pr-str upgraded))]
73+
(test-upgrade! project-file opts contents expected ?outdated-count))
74+
'[artifact "0.1.0"]
75+
'[artifact "0.1.0" :exclusions [other]])
76+
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
77+
" :managed-dependencies [%s])")
78+
1
79+
80+
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
81+
" :dependencies [[artifact]]"
82+
" :parent-project {:path \"parent.clj\""
83+
" :inherit [:managed-dependencies]})")
84+
0
85+
86+
(str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"
87+
" :dependencies [[artifact]]"
88+
" :managed-dependencies [%s])")
89+
1))
90+
6691
(deftest t-project-file-upgrading-failure-because-of-modifications
6792
(let [opts (const-opts "0.1.1")
6893
contents (str "(defproject project-x \"0.1.1-SNAPSHOT\"\n"

0 commit comments

Comments
 (0)