Support ordering repositories, fixes #268

This commit is contained in:
Colin Jones 2011-09-01 22:22:05 -05:00
parent ad39cec761
commit 9d7c8b52b0
2 changed files with 27 additions and 8 deletions

View file

@ -129,7 +129,7 @@ Warning: alpha; subject to change."
"clojars" {:url "http://clojars.org/repo/"}})
;; you can't remove or omit "central", you can only disable it;
;; maven/maven-ant-tasks adds it implicitly, and will continue to
;; maven/maven-ant-tasks adds it implicitly, and will continue to
;; report it in the list of checked repositories, even though it's
;; not been consulted. The URL will hopefully be clear enough to users.
(def disabled-central-repo {"central" {:url "http://disabled-central"
@ -146,13 +146,15 @@ Warning: alpha; subject to change."
(defn repositories-for
"Return a map of repositories including or excluding defaults."
[project]
(merge (when-not (:omit-default-repositories project)
default-repos)
(let [repositories (merge (and (:omit-default-repositories project)
disabled-central-repo)
(:repositories project))]
(into {} (for [[id settings] repositories]
[id (init-settings id settings)])))))
(let [project-repos (for [[id settings] (:repositories project)]
[id (init-settings id settings)])
all-repos (concat
(into []
(if (:omit-default-repositories project)
disabled-central-repo
default-repos))
project-repos)]
(apply array-map (mapcat identity all-repos))))
(defn exit
"Call System/exit. Defined as a function so that rebinding is possible."

View file

@ -56,3 +56,20 @@
(is (= ["http://disabled-central" "http://repo-1-url"]
(map :url (vals repos))))))
(deftest test-repositories-for-including-defaults
(let [repos (repositories-for sample-project)]
(is (get repos "central"))
(is (get repos "clojars"))
(is (get repos "snapshots"))))
(deftest test-repositories-for-many-repos-ordered
(let [repo-names (map #(str "repo-" %) (range 20))
fake-url-ify #(str % "-url")
repos (repositories-for
{:omit-default-repositories true
:repositories (map #(vector % (fake-url-ify %))
repo-names)})]
(is (= clojure.lang.PersistentArrayMap (class repos)))
(is (= {:url "repo-11-url"} (get repos "repo-11")))
(is (= (map fake-url-ify repo-names) (rest (map :url (vals repos)))))))