Permalink
Browse files

add nested elements for "exec" and "manifest" tasks in a appropriate …

…way.
  • Loading branch information...
1 parent 00e9a13 commit 773e48f24a3970237984efac719caf4f43d3cf57 Marcin Koziej committed Jun 22, 2011
Showing with 31 additions and 5 deletions.
  1. +1 −1 project.clj
  2. +30 −4 src/lancet/core.clj
View
2 project.clj
@@ -1,4 +1,4 @@
-(defproject lancet "1.0.0"
+(defproject lancet "1.0.1"
:description "Dependency-based builds, Clojure Style, with optional Ant underneath."
:license {:name "MIT X11 License"}
:dependencies [[org.apache.ant/ant "1.7.1"]
View
34 src/lancet/core.clj
@@ -2,7 +2,9 @@
(:gen-class)
(:import (java.beans Introspector)
(java.util.concurrent CountDownLatch)
- (org.apache.tools.ant.types Path)))
+ (org.apache.tools.ant.types Path)
+ (org.apache.tools.ant.taskdefs Manifest$Attribute)
+ (java.util Map)))
(def #^{:doc "Dummy ant project to keep Ant tasks happy"}
ant-project
@@ -53,16 +55,40 @@
(defn set-properties! [inst prop-map]
(doseq [[k v] prop-map] (set-property! inst (name k) v)))
-(defn instantiate-task [project name props & filesets]
+(def ant-task-hierarchy
+ (atom (-> (make-hierarchy)
+ (derive ::exec ::has-args))))
+
+(defmulti add-nested
+ "Adds a nested element to ant task.
+Elements are added in a different way for each type.
+Task name keywords are connected into a hierarchy which can
+be used to extensively add other types to this method.
+The default behaviour is to add an element as a fileset."
+ (fn [name task nested] [(keyword "lancet.core" name) (class nested)])
+ :hierarchy ant-task-hierarchy)
+
+(defmethod add-nested [::manifest Map]
+ [_ task props]
+ (doseq [[n v] props] (.addConfiguredAttribute task
+ (Manifest$Attribute. n v))))
+(defmethod add-nested [::has-args String]
+ [_ task arg]
+ (doto (.createArg task) (.setValue arg)))
+
+(defmethod add-nested :default [_ task nested] (.addFileset task nested))
+
+(defn instantiate-task [project name props & nested]
(let [task (.createTask project name)]
(when-not task
(throw (Exception. (format "No task named %s." name))))
(doto task
(.init)
(.setProject project)
(set-properties! props))
- (doseq [fs filesets]
- (.addFileset task fs))
+ (doseq [n nested]
+ (add-nested name task n)
+ )
task))
(defn runonce

0 comments on commit 773e48f

Please sign in to comment.