Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extract common code for transforming dependency lists

  • Loading branch information...
commit 6556148a65f64515ba34ce98ea01ca6be622d5c9 1 parent d4c0084
@purcell purcell authored committed
Showing with 23 additions and 21 deletions.
  1. +16 −7 src/leiningen/add.clj
  2. +7 −14 src/leiningen/update.clj
View
23 src/leiningen/add.clj
@@ -10,14 +10,23 @@
(defn good-read-line []
(binding [*in* (-> System/in (java.io.InputStreamReader.) (clojure.lang.LineNumberingPushbackReader.))] (read-line)))
+(defn update-dependency-list
+ "Modify the project's dependency list of the given type by passing it through f"
+ [project dep-type f]
+ (->> project
+ (reduce
+ (fn [[form prev] n]
+ (if (= prev dep-type)
+ [(cons (vec (f n)) form) nil]
+ [(cons n form) n]))
+ [() nil])
+ first
+ reverse))
+
(defn add-artifact [project type artifact version]
- (reverse
- (first
- (reduce
- (fn [[form is-deps?] f]
- (if is-deps?
- [(cons (cons [(symbol artifact) version] f) form) false]
- [(cons f form) (= f type)])) ['() false] project))))
+ (update-dependency-list project type
+ (fn [deps]
+ (cons [(symbol artifact) version] deps))))
(defn find-clojar [what]
(let [p (re-pattern what)]
View
21 src/leiningen/update.clj
@@ -1,25 +1,18 @@
(ns leiningen.update
"lein update checks for newer versions of currently used dependencies and aks the user if they should be updated to the latest stable."
(:use (clojure.contrib duck-streams seq-utils str-utils)
- [leiningen.add :only [latest-stable add-artifact find-clojar good-read-line]]
+ [leiningen.add :only [latest-stable add-artifact find-clojar good-read-line update-dependency-list]]
[leiningen.search :only [read-clj]]
[leiningen.update-repo :only [compare-versions]]))
(defn update-artifact [project dep-type artifact new-version]
- (->> project
- (reduce
- (fn [[form prev] f]
- (if (= prev dep-type)
- [(cons (vec (for [[a v] f]
- [a (if (= a (symbol artifact))
+ (update-dependency-list project dep-type
+ (fn [deps]
+ (for [[a v] deps]
+ [a (if (= a (symbol artifact))
new-version
- v)]))
- form) nil]
- [(cons f form) f]))
- [() nil])
- first
- reverse))
+ v)]))))
(defn yes-or-no-prompt [question]
(print question " (y/n) ")
@@ -39,7 +32,7 @@
(if (and res (< 0 (compare-versions latest version)))
[artifact version latest]
[artifact version nil])))
-
+
(defn update [project & args]
(let [project-clj-path (str (:root project) "/project.clj")
maybe-add-updates
Please sign in to comment.
Something went wrong with that request. Please try again.