Browse files

Don't load hooks unless they're specified in project.clj.

Turn on :implicit-hooks true to get back the old behaviour of scanning
the classpath.
  • Loading branch information...
1 parent 49eff45 commit b5cb0cb52f798eaccf34a9700705dea66f5cbe37 @technomancy committed Jul 30, 2010
Showing with 23 additions and 9 deletions.
  1. +7 −0 sample.project.clj
  2. +16 −9 src/leiningen/core.clj
@@ -41,6 +41,13 @@
;; Before fetching dependencies, the contents of the lib/ directory
;; will get deleted unless this is set to true.
:disable-implicit-clean false
+ ;; Load these namespaces on startup to pick up hooks from
+ ;; them. Hooks are generally included in plugins.
+ :hooks [leiningen.hooks.difftest]
+ ;; Set this to true to search the classpath for hooks. Will load all
+ ;; 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.
@@ -76,9 +76,14 @@
(catch e
-(defn- load-hooks []
- (try (doseq [n (sort (find-namespaces-on-classpath))
- :when (re-find #"^leiningen\.hooks\." (name n))]
+(defn- hook-namespaces [project]
+ (sort (or (:hooks project)
+ (and (:implicit-hooks project)
+ (filter #(re-find #"^leiningen\.hooks\." (name %))
+ (find-namespaces-on-classpath))))))
+(defn- load-hooks [project]
+ (try (doseq [n (hook-namespaces project)]
(require n))
(catch Exception e
(when-not (empty? (.list (File. "lib")))
@@ -99,17 +104,19 @@
(defn -main
([& [task-name & args]]
(let [task-name (or (@aliases task-name) task-name "help")
- args (if (@no-project-needed task-name)
- args
- (conj args (read-project)))
- compile-path (:compile-path (first args))]
+ project (when-not (@no-project-needed task-name)
+ (read-project))
+ compile-path (:compile-path project)]
(when compile-path (.mkdirs (File. compile-path)))
(binding [*compile-path* compile-path]
- (load-hooks)
+ (when project
+ (load-hooks project))
;; TODO: can we catch only task-level arity problems here?
;; compare args and (:arglists (meta (resolve-task task)))?
(let [task (resolve-task task-name)
- value (apply task args)]
+ value (apply task (if project
+ (cons project args)
+ args))]
(when (integer? value)
(System/exit value))))))
([] (apply -main (or *command-line-args* ["help"]))))

0 comments on commit b5cb0cb

Please sign in to comment.