Permalink
Browse files

Added lein update to auto update dependencies in project.clj to newes…

…t versions.
  • Loading branch information...
1 parent a47c91e commit eb373fd1651ec823576ed852b7fdd90ad8584bdd @Licenser Licenser committed Apr 14, 2010
Showing with 56 additions and 5 deletions.
  1. +1 −1 project.clj
  2. +0 −1 src/lein_search/core.clj
  3. +4 −3 src/leiningen/add.clj
  4. +51 −0 src/leiningen/update.clj
View
@@ -1 +1 @@
-(defproject lein-search "0.2.0" :namespaces [leiningen.add leiningen.search leiningen.update-repo] :description "Leinigen plugin to search and add dependencies from clojars" :dependencies ([org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.1.0"]) :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"] [swank-clojure/swank-clojure "1.1.0"]])
+(defproject lein-search "0.3.0-SNAPSHOT" :namespaces [leiningen.update leiningen.add leiningen.search leiningen.update-repo] :description "Leinigen plugin to search and add dependencies from clojars" :dependencies ([org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.1.0"]) :dev-dependencies ([lein-clojars "0.5.0"] [swank-clojure/swank-clojure "1.1.0"]))
View
@@ -1 +0,0 @@
-(ns lein-search.core)
View
@@ -7,14 +7,15 @@
(defn good-read-line []
(binding [*in* (-> System/in (java.io.InputStreamReader.) (clojure.lang.LineNumberingPushbackReader.))] (read-line)))
-(defn add-artifact [project artifact version]
+
+(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 :dependencies)])) ['() false] project))))
+ [(cons f form) (= f type)])) ['() false] project))))
(defn find-clojar [what]
(let [p (re-pattern what)]
@@ -78,4 +79,4 @@
(println "Adding:" a v)
(with-open [o (writer (str (:root project) "/project.clj"))]
(binding [*out* o]
- (pr (add-artifact p a v)))))))))
+ (pr (add-artifact p :dependencies a v)))))))))
View
@@ -0,0 +1,51 @@
+(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.search :only [read-clj]]
+ [leiningen.update-repo :only [compare-versions]]))
+
+
+(defn update-artifact [project type artifact version]
+ (reverse
+ (first
+ (reduce
+ (fn [[form is-deps?] f]
+ (if is-deps?
+ [(cons (map (fn [[a v]] (if (= a (symbol artifact)) [a version] [a v])) f) form) false]
+ [(cons f form) (= f type)])) ['() false] project))))
+
+(defn ask-for-update [artifact version new-version]
+ (print (str "You are currently using "artifact" in version "version". Do you want to update to "new-version"? (y/n)"))
+ (flush)
+ (let [r (chomp (good-read-line))]
+ (cond
+ (= r "y") true
+ (= r "n") false
+ :else (recur artifact version new-version))))
+
+(defn find-updates [[artifact version]]
+ (let [res (first (find-clojar (str artifact)))
+ latest (if res (latest-stable (:versions res)) "0.0.0")]
+ (if (and res (< 0 (compare-versions latest version)))
+ [artifact version latest]
+ [artifact version nil])))
+
+(defn update [project & args]
+ (let [deps (:dependencies project)
+ dev-deps (:dev-dependencies project)
+ p (reduce (fn [p [artifact version new-version]]
+ (if (and new-version (ask-for-update artifact version new-version))
+ (update-artifact p :dev-dependencies (str artifact) new-version)
+ p))
+ (reduce (fn [p [artifact version new-version]]
+ (if (and new-version (ask-for-update artifact version new-version))
+ (update-artifact p :dependencies (str artifact) new-version)
+ p))
+ (read-clj (str (:root project) "/project.clj"))
+ (map find-updates deps))
+ (map find-updates dev-deps))]
+ (with-open [o (writer (str (:root project) "/project.clj"))]
+ (binding [*out* o]
+ (pr p)))))
+

0 comments on commit eb373fd

Please sign in to comment.