Skip to content

Commit

Permalink
Skip fetching deps unnecessarily when :checksum-deps is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jan 15, 2011
1 parent 0cf1ddf commit e30a38d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions sample.project.clj
Expand Up @@ -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
Expand All @@ -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.
Expand Down
24 changes: 20 additions & 4 deletions src/leiningen/deps.clj
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down
1 change: 0 additions & 1 deletion todo.org
Expand Up @@ -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
Expand Down

0 comments on commit e30a38d

Please sign in to comment.