Skip to content
Browse files

support disabling autoload of plugin hooks and middleware

  • Loading branch information...
1 parent 09e5f60 commit ff5524bdf10a0bf913312125892ee4ae95ef0136 @ninjudd ninjudd committed Aug 23, 2012
View
14 doc/PLUGINS.md
@@ -209,6 +209,20 @@ map whenever the active profiles change. We accomplish this by storing the fresh
project map and starting from that whenever we call `merge-profiles`,
`unmerge-profiles` or `set-profiles`.
+## Requiring Plugins
+
+To use a plugin in your project, just add a `:plugins` key to your project.clj
+with the same format as `:dependencies`. In addition to the options allowed by
+`:dependencies`, `:plugins` also allows you to disable auto-loading of hooks or
+middleware.
+
+```clj
+(defproject foo "0.1.0"
+ :plugins [[lein-pprint "1.1.1"]
+ [lein-foo "0.0.1" :hooks false]
+ [lein-bar "0.0.1" :middleware false]])
+```
+
## Clojure Version
Leiningen 2.0.0 uses Clojure 1.4.0. If you need to use a different
View
7 leiningen-core/src/leiningen/core/project.clj
@@ -264,10 +264,11 @@
project)
([project] (load-plugins project :plugins)))
-(defn- plugin-vars [project var-name]
- (for [[plugin] (:plugins project)]
+(defn plugin-vars [project type]
+ (for [[plugin _ & {:as opts}] (:plugins project)
+ :when (get opts type true)]
(with-meta (symbol (str (name plugin) ".plugin")
- (name var-name))
+ (name type))
{:optional true})))
(defn- plugin-hooks [project]
View
15 leiningen-core/test/leiningen/core/test/project.clj
@@ -127,6 +127,21 @@
(binding [*err* *out*]
(init-project (read (.getFile (io/resource "p3.clj")))))))))
+(deftest test-plugin-vars
+ (are [project hooks middleware] (= (list hooks middleware)
+ (map (partial plugin-vars project) [:hooks :middleware]))
+ {:plugins '[[lein-foo "1.2.3"]]}
+ '(lein-foo.plugin/hooks) '(lein-foo.plugin/middleware)
+
+ {:plugins '[[lein-foo "1.2.3" :hooks false]]}
+ '() '(lein-foo.plugin/middleware)
+
+ {:plugins '[[lein-foo "1.2.3" :middleware false]]}
+ '(lein-foo.plugin/hooks) '()
+
+ {:plugins '[[lein-foo "1.2.3" :hooks false :middleware false]]}
+ '() '()))
+
(deftest test-add-profiles
(let [expected-result {:dependencies [] :profiles {:a1 {:src-paths ["a1/"]}
:a2 {:src-paths ["a2/"]}}}]
View
4 sample.project.clj
@@ -47,7 +47,9 @@
;; provides new tasks or hooks.
:plugins [[lein-pprint "1.1.1"]
[lein-assoc "0.1.0"]
- [s3-wagon-private "1.1.1"]]
+ [s3-wagon-private "1.1.1"]
+ [lein-foo "0.0.1" :hooks false]
+ [lein-bar "0.0.1" :middleware false]]
;; If you configure a custom repository with a self-signed SSL
;; certificate, you will need to add it here. Paths should be either
;; be on Leiningen's classpath or relative to the project root.

0 comments on commit ff5524b

Please sign in to comment.
Something went wrong with that request. Please try again.