Skip fetching deps unnecessarily when :checksum-deps is set.

This commit is contained in:
Phil Hagelberg 2011-01-15 09:23:03 -05:00
parent 0cf1ddf024
commit e30a38d549
4 changed files with 30 additions and 9 deletions

3
NEWS
View file

@ -2,6 +2,9 @@ Leiningen NEWS -- history of user-visible changes
= 1.5.0 / ???
* Skip fetching dependencies when they haven't changed in project.clj
if :checksum-deps is set.
* Add system property for $PROJECT.version.
* Add deploy task.

View file

@ -36,6 +36,13 @@
javax.jms/jms
com.sun.jdmk/jmxtools
com.sun.jmx/jmxri]]]
;; Dev dependencies are intended for use only during
;; development. Projects that depend on this project will not pull
;; in its dev-dependencies, and they won't be included in the uberjar.
:dev-dependencies [[org.clojure/swank-clojure "1.2.1"]]
;; Only re-fetch dependencies when they change in project.clj or
;; when :library-path directory is empty.
:checksum-deps true
;; Warns users of earlier versions of Leiningen.
:min-lein-version "1.3.0"
;; Before fetching dependencies, the contents of the lib/ directory
@ -58,10 +65,6 @@
;; namespaces matching leiningen.hooks.*. Warning: this will cause
;; Leiningen to start slowly, especially with many dependencies.
:implicit-hooks false
;; Dev dependencies are intended for use only during
;; development. Projects that depend on this project will not pull
;; in its dev-dependencies, and they won't be included in the uberjar.
:dev-dependencies [[org.clojure/swank-clojure "1.2.1"]]
;; These namespaces will be AOT-compiled. Needed for gen-class and
;; other Java interop functionality. :namespaces is an alias for this.
;; Put a regex here to compile all namespaces whose names match.

View file

@ -5,6 +5,7 @@
[leiningen.util.maven :only [make-dependency]]
[leiningen.util.file :only [delete-file-recursively]])
(:import (java.io File)
(java.security MessageDigest)
(org.apache.maven.artifact.ant Authentication DependenciesTask
RemoteRepository)
(org.apache.maven.settings Server)
@ -68,15 +69,30 @@
(defn use-dev-deps? [project skip-dev]
(and (not skip-dev) (seq (:dev-dependencies project))))
(defn- sha1-digest [content]
(.toString (BigInteger. 1 (-> (MessageDigest/getInstance "SHA1")
(.digest (.getBytes content)))) 16))
(defn- deps-checksum [project]
(sha1-digest (pr-str [(:dependencies project)
(:dev-dependencies project)])))
(defn fetch-deps? [project deps-set skip-dev]
(let [deps-checksum-file (File. (:root project) ".lein-deps-sum")]
(and (or (seq (project deps-set)) (use-dev-deps? project skip-dev))
(or (not (:checksum-deps project))
(empty? (.list (File. (:library-path project))))
(not (.exists deps-checksum-file))
(not= (slurp deps-checksum-file) (deps-checksum project))))))
(defn ^{:help-arglists '([] [skip-dev])} deps
"Download and install all :dependencies and :dev-dependencies listed in
project.clj. With an argument it will skip development dependencies."
([project skip-dev deps-set]
(when (or (seq (project deps-set)) (use-dev-deps? project skip-dev))
(when (fetch-deps? project deps-set skip-dev)
(when-not (:disable-implicit-clean project)
(delete-file-recursively (:library-path project) true))
(let [deps-task (make-deps-task project deps-set)
_ (.execute deps-task)
(delete-file-recursively (:library-path project) :silently))
(let [deps-task (doto (make-deps-task project deps-set) .execute)
fileset (.getReference lancet/ant-project
(.getFilesetId deps-task))]
(.mkdirs (File. (:library-path project)))

View file

@ -41,7 +41,6 @@ See also https://github.com/technomancy/leiningen/issues
** TODO re-compile all deps with current clojure version
Another thing that's going to start becoming more important as more
Clojure versions are introduced.
** TODO fail gracefully when run without an Internet connection (Issue #100)
** TODO improve test coverage
** TODO merge push task based on clj-ssh
lein-clojars task doesn't support DSA keys