Allow implicit hooks/middleware to be disabled.

Fixes #1621.
This commit is contained in:
Phil Hagelberg 2014-08-05 10:10:43 -07:00
parent 828a5875d8
commit 8b9d66cd7c
2 changed files with 22 additions and 16 deletions

View file

@ -679,25 +679,27 @@
(utils/error "cannot resolve" hook-name "hook"))))
(defn load-hooks [project & [ignore-missing?]]
(doseq [hook-name (concat (plugin-hooks project) (:hooks project))]
;; if hook-name is just a namespace assume hook fn is called activate
(let [hook-name (if (namespace hook-name)
hook-name
(symbol (name hook-name) "activate"))]
(load-hook hook-name)))
(when (and (:implicits project true) (:implicit-hooks project true))
(doseq [hook-name (concat (plugin-hooks project) (:hooks project))]
;; if hook-name is just a namespace assume hook fn is called activate
(let [hook-name (if (namespace hook-name)
hook-name
(symbol (name hook-name) "activate"))]
(load-hook hook-name))))
project)
(defn apply-middleware
([project]
(reduce apply-middleware project
(concat (plugin-middleware project)
(:middleware project))))
(concat (plugin-middleware project) (:middleware project))))
([project middleware-name]
(if-let [middleware (utils/require-resolve middleware-name)]
(middleware project)
(do (when-not (:optional (meta middleware-name))
(utils/error "cannot resolve" middleware-name "middleware"))
project))))
(if (and (:implicits project true) (:implicit-middleware project true))
(if-let [middleware (utils/require-resolve middleware-name)]
(middleware project)
(do (when-not (:optional (meta middleware-name))
(utils/error "cannot resolve" middleware-name "middleware"))
project))
project)))
(defn load-certificates
"Load the SSL certificates specified by the project and register

View file

@ -165,10 +165,14 @@
:repl {:plugins [[cider/cider-nrepl "0.7.1"]]}}
;; Load these namespaces from within Leiningen to pick up hooks from them.
:hooks [leiningen.hooks.difftest]
;; Apply these middleware functions from plugins to your project when it
;; loads. Both hooks and middleware can be loaded implicitly by giving them a
;; name matching a specific pattern as well as by listing them here.
;; Apply these middleware functions from plugins to your project
;; when it loads. Both hooks and middleware can be loaded implicitly
;; or by being listed here.
:middleware [lein-xml.plugin/middleware]
;; These settings disable the implicit loading of middleware and
;; hooks, respectively. You can disable both with :implicits false.
:implicit-middleware false
:implicit-hooks false
;;; Entry Point
;; The -main function in this namespace will be run at launch