Permalink
Browse files

Add prepend-tasks for task hooking in simplistic cases.

  • Loading branch information...
1 parent dcf210d commit d839074a961f57c50d5c77f60391dc0d06ec0110 @technomancy committed Feb 16, 2011
Showing with 22 additions and 1 deletion.
  1. +10 −0 sample.project.clj
  2. +11 −1 src/leiningen/core.clj
  3. +1 −0 src/leiningen/repl.clj
View
@@ -129,3 +129,13 @@
:jvm-opts ["-Xmx1g"]
;; If your project is a Leiningen plugin, set this to skip the subprocess step
:eval-in-leiningen false)
+
+;; You can use Robert Hooke to modify behaviour of any task function,
+;; but the prepend-tasks function is shorthand that is more convenient
+;; on tasks that take a single project argument.
+(use '[leiningen.core :only [prepend-tasks]]
+ '[leiningen.deps :only [deps]]
+ '[leiningen.clean :only [clean]]
+ '[leiningen.pom :only [pom]])
+
+(prepend-tasks #'deps clean pom)
@@ -1,7 +1,8 @@
(ns leiningen.core
(:use [leiningen.util.ns :only [namespaces-matching]]
[clojure.string :only [split]]
- [clojure.walk :only [walk]])
+ [clojure.walk :only [walk]]
+ [robert.hooke :only [add-hook]])
(:import (java.io File)))
(def ^{:private true} project nil)
@@ -195,6 +196,15 @@
(abort "Wrong number of arguments to" task-name "task."
"\nExpected" args))))))
+(defn prepend-tasks
+ "Add a hook to target-var to run tasks-to-add, which must be tasks
+ taking a project argument and nothing else."
+ [target-var & tasks-to-add]
+ (add-hook target-var (fn [target project & args]
+ (doseq [t tasks-to-add]
+ (t project))
+ (apply target project args))))
+
(def arg-separator ",")
(defn- append-to-group [groups arg]
@@ -40,6 +40,7 @@
LineNumberingPushbackReader.)
*out* (OutputStreamWriter. outs#)
*err* *err*
+ ;; TODO: bugger; can't rebind in 1.3
;; clojure.main/repl has no way
;; to exit without signalling EOF,
;; which we can't do with a socket.

0 comments on commit d839074

Please sign in to comment.