Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated project version and readme.

  • Loading branch information...
commit 7fa627abbc607810ea1b6a3302f2196bbf5f5ab1 2 parents 96e4ecd + 50357bb
@Licenser authored
View
4 README
@@ -21,3 +21,7 @@ org.clojars.wuschel/lein-search "42.2.3" - a non official release, and it's lat
Copyright © 2009 Heinz N. Gies.
This code is published under the EPL, have fun! See LICENSE.html for the booring stuff.
+
+## Thanks
+
+Big thanks to purcell@github for a bunch of improvements and cleanup in the code.
View
2  project.clj
@@ -1,4 +1,4 @@
-(defproject lein-search "0.3.0"
+(defproject lein-search "0.3.1"
: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
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
6 src/leiningen/search.clj
@@ -11,9 +11,9 @@
(defn search-clojar [what]
(let [p (re-pattern what)]
- (doall (filter
+ (doall (filter
(fn [{description :description artifact-id :artifact-id group-id :group-id}]
- (or
+ (or
(re-find p (or description ""))
(re-find p artifact-id)
(re-find p group-id)))
@@ -32,7 +32,7 @@
what (if show-versions (first args) what)]
(if (.exists (File. (str *lein-dir* "/clojars")))
(let [m (search-clojar what)]
- (println (str "Results for " what ":"))
+ (println "Results for " what ":")
(if show-versions
(println (str-join "\n" (map (fn [{versions :versions artifact-id :artifact-id group-id :group-id}] (str (artifact-name group-id artifact-id) ": " (str-join ", " versions))) m)))
(println (str-join "\n" (map (fn [{description :description artifact-id :artifact-id group-id :group-id}] (format "%-40s - %s" (artifact-name group-id artifact-id) (re-sub #"\n\s*" " " (or description "No description given")))) m)))))
View
59 src/leiningen/update.clj
@@ -1,28 +1,30 @@
(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 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 update-artifact [project dep-type artifact new-version]
+ (update-dependency-list project dep-type
+ (fn [deps]
+ (for [[a v] deps]
+ [a (if (= a (symbol artifact))
+ new-version
+ v)]))))
-(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)"))
+(defn yes-or-no-prompt [question]
+ (print question " (y/n) ")
(flush)
(let [r (chomp (good-read-line))]
(cond
(= r "y") true
(= r "n") false
- :else (recur artifact version new-version))))
+ :else (recur question))))
+
+(defn ask-for-update [artifact version new-version]
+ (yes-or-no-prompt (str "You are currently using "artifact" in version "version". Do you want to update to "new-version"?")))
(defn find-updates [[artifact version]]
(let [res (first (find-clojar (str artifact)))
@@ -30,22 +32,19 @@
(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)))))
-
+ (let [project-clj-path (str (:root project) "/project.clj")
+ maybe-add-updates
+ (fn [dep-type initial]
+ (reduce (fn [p [artifact version new-version]]
+ (if (and new-version (ask-for-update artifact version new-version))
+ (update-artifact p dep-type (str artifact) new-version)
+ p))
+ initial
+ (map find-updates (dep-type project))))
+ updated-project (->> (read-clj project-clj-path)
+ (maybe-add-updates :dependencies)
+ (maybe-add-updates :dev-dependencies))]
+ (with-out-writer project-clj-path
+ (pr updated-project))))
View
51 src/leiningen/update_repo.clj
@@ -1,38 +1,33 @@
(ns leiningen.update-repo
"Updates the clojars.org repositories index."
- (:use clojure.contrib.duck-streams)
- (:import (java.io File InputStreamReader PushbackReader) java.util.zip.GZIPInputStream java.net.URL))
+ (:use [clojure.contrib.duck-streams :only (reader writer with-out-writer)])
+ (:import (java.io File) java.util.zip.GZIPInputStream java.net.URL))
(def *lein-dir* (str (System/getProperty "user.home") "/.lein"))
(defn split-version [v]
- (if (re-find #"(\d+)\.(\d+)\.(\d+)(-.*)?" v)
- (let [[_ major minor patch suffix] (re-find #"(\d+)\.(\d+)\.(\d+)(?:-(.*))?" v)]
- [(Integer/parseInt major) (Integer/parseInt minor) (Integer/parseInt patch) (or suffix "")])
- '(0 0 0 "")))
+ (if-let [[_ major minor patch suffix] (when v (re-find #"(\d+)\.(\d+)(?:\.(\d+))?(?:-(.*))?" v))]
+ [(Integer/parseInt major) (Integer/parseInt minor) (Integer/parseInt (or patch "0")) (or suffix "")]
+ [0 0 0 ""]))
(defn compare-versions [v1 v2]
- (let [[v1-major v1-minor v1-patch v1-suffix] (split-version v1)
- [v2-major v2-minor v2-patch v2-suffix] (split-version v2)]
- (cond
- (> v1-major v2-major) 1
- (< v1-major v2-major) -1
- :else (cond
- (> v1-minor v2-minor) 1
- (< v1-minor v2-minor) -1
- :else (cond
- (> v1-patch v2-patch) 1
- (< v1-patch v2-patch) -1
- :else (cond
- (= v1-suffix v2-suffix) 0
- (= v1-suffix "") 1
- (= v2-suffix "") -1
- (= v1-suffix "SNAPSHOT") 1
- (= v2-suffix "SNAPSHOT") -1
- :else (.compareTo v1-suffix v2-suffix)))))))
+ (let [vers1 (split-version v1)
+ vers2 (split-version v2)
+ version-comparison (.compareTo (subvec vers1 0 3) (subvec vers2 0 3))]
+ (if (zero? version-comparison)
+ (let [v1-suffix (last vers1)
+ v2-suffix (last vers2)]
+ (cond
+ (= v1-suffix v2-suffix) 0
+ (= v1-suffix "") 1
+ (= v2-suffix "") -1
+ (= v1-suffix "SNAPSHOT") 1
+ (= v2-suffix "SNAPSHOT") -1
+ :else (.compareTo v1-suffix v2-suffix)))
+ version-comparison)))
(defn read-index [url]
- (with-open [r (PushbackReader. (InputStreamReader. (GZIPInputStream. (.openStream (URL. url)))))]
+ (with-open [r (reader (GZIPInputStream. (.openStream (URL. url))))]
(loop [result [] code (read r false false)]
(if code
(recur (conj result code) (read r false false))
@@ -40,6 +35,6 @@
(defn update-repo [project & args]
(if (not (.exists (File. *lein-dir*))) (.mkdirs (File. *lein-dir*)))
- (with-open [w (writer (str *lein-dir* "/clojars"))]
- (println "Getting the list of packages on clojars.org ...")
- (binding [*out* w] (pr (read-index "http://clojars.org/repo/feed.clj.gz")))))
+ (println "Getting the list of packages on clojars.org ...")
+ (with-out-writer (writer (str *lein-dir* "/clojars"))
+ (pr (read-index "http://clojars.org/repo/feed.clj.gz"))))
Please sign in to comment.
Something went wrong with that request. Please try again.