support disabling autoload of plugin hooks and middleware

This commit is contained in:
Justin Balthrop 2012-08-23 13:29:37 -07:00
parent 09e5f60684
commit ff5524bdf1
4 changed files with 36 additions and 4 deletions

View file

@ -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 file

@ -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 file

@ -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 file

@ -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.