Skip to content

Commit a296830

Browse files
committed
Fix install-latest when tool has available versions of multiple coordinate types
1 parent 5a6bea7 commit a296830

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

src/clojure/tools/tools/api.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@
7575
[lib coord as master-edn]
7676
(let [current (tool/resolve-tool as)
7777
coord (or coord (:coord current))
78+
coord-type (ext/coord-type coord)
7879
latest-coord (->> (ext/find-all-versions lib coord master-edn)
7980
(filter release-version?)
81+
(filter #(= coord-type (ext/coord-type %)))
8082
last
8183
(merge coord))]
8284
(if latest-coord

test-data/tools1/clj-new.edn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{:lib com.github.seancorfield/clj-new,
2+
:coord
3+
{:git/tag "v1.2.362",
4+
:git/sha "4ab680eb74651b2762df4e5bff7ed99fda1bf91d",
5+
:git/url "https://github.com/seancorfield/clj-new.git"}}
Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,92 @@
11
(ns clojure.tools.tools.api-test
22
(:require
3+
[clojure.edn :as edn]
4+
[clojure.java.io :as jio]
35
[clojure.string :as str]
46
[clojure.test :refer :all]
5-
[clojure.tools.tools.api :as sut]))
7+
[clojure.tools.tools.api :as api])
8+
(:import
9+
[java.io File]
10+
[java.nio.file Files StandardCopyOption]
11+
[java.util UUID]))
612

713
(def tool-install-name "temporary-ci-test-tool")
814

915
(deftest install-update-list-and-remove
1016
(testing "Install specific version that is not the latest"
1117
(let [expected-response (str tool-install-name ": Installed com.github.seancorfield/deps-new v0.4.9")
12-
actual-response (with-out-str (sut/install {'com.github.seancorfield/deps-new {:git/url "https://github.com/seancorfield/deps-new"
18+
actual-response (with-out-str (api/install {'com.github.seancorfield/deps-new {:git/url "https://github.com/seancorfield/deps-new"
1319
:git/tag "v0.4.9"} :as tool-install-name}))]
1420
(is (str/includes? actual-response expected-response))))
1521

1622
(testing "list installed tools"
1723
(let [expected-response (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new\\s*:git\\s*v0\\.4\\.9"))
18-
actual-response (with-out-str (sut/list nil))]
24+
actual-response (with-out-str (api/list nil))]
1925
(is (re-find expected-response actual-response))))
2026

2127
(testing "update installed tool to latest version"
2228
;; Would be more desirable if we had a test tool to install and could check the specific version that wouldn't change
2329
(let [expected-response (re-pattern (str tool-install-name ": Installed com\\.github\\.seancorfield/deps-new"))
24-
actual-response (with-out-str (sut/install-latest {:tool tool-install-name}))]
30+
actual-response (with-out-str (api/install-latest {:tool tool-install-name}))]
2531
(is (re-find expected-response actual-response))))
2632

2733
(testing "list installed tools reflects updated version"
2834
(let [old-tool (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new\\s*:git\\s*v0\\.4\\.9"))
2935
expected-response (re-pattern (str tool-install-name "\\s*com\\.github\\.seancorfield/deps-new"))
30-
actual-response (with-out-str (sut/list nil))]
36+
actual-response (with-out-str (api/list nil))]
3137
(is (not (re-find old-tool actual-response)) "The old tool was not successfully updated")
3238
(is (re-find expected-response actual-response))))
3339

3440
(testing "remove installed tool"
35-
(let [removal-response (with-out-str (sut/remove {:tool tool-install-name}))
36-
list-response (with-out-str (sut/list nil))]
41+
(let [removal-response (with-out-str (api/remove {:tool tool-install-name}))
42+
list-response (with-out-str (api/list nil))]
3743
(is (str/includes? removal-response "Tool removed"))
3844
(is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed"))))
3945

4046
(deftest install-latest-git-procurer-with-provided-coord
4147
(testing "Installed latest version of tool, for git procurer providing coord"
4248
(let [expected-response (re-pattern (str tool-install-name ": Installed com\\.github\\.seancorfield/deps-new"))
43-
actual-response (with-out-str (sut/install-latest {:lib 'com.github.seancorfield/deps-new
49+
actual-response (with-out-str (api/install-latest {:lib 'com.github.seancorfield/deps-new
4450
:coord {:git/url "https://github.com/seancorfield/deps-new"}
4551
:as tool-install-name}))]
4652
(is (re-find expected-response actual-response))))
4753

4854
(testing "remove installed tool"
49-
(let [removal-response (with-out-str (sut/remove {:tool tool-install-name}))
50-
list-response (with-out-str (sut/list nil))]
55+
(let [removal-response (with-out-str (api/remove {:tool tool-install-name}))
56+
list-response (with-out-str (api/list nil))]
5157
(is (str/includes? removal-response "Tool removed"))
52-
(is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed"))))
58+
(is (not (str/includes? list-response tool-install-name)) "The tool was not successfully removed"))))
59+
60+
(defn copy-dir [^String src ^String dest]
61+
(let [dest-dir (.toPath (jio/file dest))]
62+
(doseq [^File f (.listFiles (jio/file src)) :when (.isFile f)]
63+
(Files/copy (.toPath f)
64+
(.resolve dest-dir (.getName f))
65+
(into-array [StandardCopyOption/REPLACE_EXISTING])))))
66+
67+
(defmacro let-tools-dir
68+
[[dir-sym dir-path] & body]
69+
`(let [tmp# (jio/file (System/getProperty "java.io.tmpdir") (str (UUID/randomUUID)))
70+
tools# (jio/file tmp# ".clojure" "tools")
71+
old-home# (System/getProperty "user.home")
72+
~dir-sym (.getAbsolutePath tools#)]
73+
(try
74+
(.mkdirs tools#)
75+
(.deleteOnExit tmp#)
76+
(copy-dir ~dir-path (.getAbsolutePath tools#))
77+
(System/setProperty "user.home" (.getAbsolutePath tmp#))
78+
~@body
79+
(finally
80+
(System/setProperty "user.home" old-home#)))))
81+
82+
;; when out of date tool has both git and maven versions, only consider updates
83+
;; to version with the same coordinate type. here, git is installed
84+
(deftest install-latest-mixed
85+
(let-tools-dir [tools "test-data/tools1"]
86+
(let [old-edn (edn/read-string (slurp (jio/file tools "clj-new.edn")))
87+
old-tag (-> old-edn :coord :git/tag)]
88+
(api/install-latest {:tool "clj-new"})
89+
(let [new-edn (edn/read-string (slurp (jio/file tools "clj-new.edn")))
90+
new-tag (-> new-edn :coord :git/tag)]
91+
(is new-tag) ;; has a :git/tag
92+
(is (not= old-tag new-tag)))))) ;; ... that has been updated

0 commit comments

Comments
 (0)