Permalink
Browse files

Support ordering repositories, fixes #268

  • Loading branch information...
1 parent ad39cec commit 9d7c8b52b0bde1f737c35cadb5d8f81ad598e79b @trptcolin trptcolin committed Sep 2, 2011
Showing with 27 additions and 8 deletions.
  1. +10 −8 src/leiningen/core.clj
  2. +17 −0 test/leiningen/test/core.clj
View
@@ -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."
@@ -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)))))))
+

0 comments on commit 9d7c8b5

Please sign in to comment.