diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index ba1e521f..277fd9ee 100644 --- a/doc/PLUGINS.md +++ b/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 diff --git a/leiningen-core/src/leiningen/core/project.clj b/leiningen-core/src/leiningen/core/project.clj index 59d53aa4..70075b65 100755 --- a/leiningen-core/src/leiningen/core/project.clj +++ b/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] diff --git a/leiningen-core/test/leiningen/core/test/project.clj b/leiningen-core/test/leiningen/core/test/project.clj index 917a7013..b624ef31 100755 --- a/leiningen-core/test/leiningen/core/test/project.clj +++ b/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/"]}}}] diff --git a/sample.project.clj b/sample.project.clj index 0c245bf6..a68ef092 100644 --- a/sample.project.clj +++ b/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.