Carlos,
I went down a similar road once before, using a Ruby DSL to generate
the XML for Spring DI. This approach may offer the quickest initial
return, but it hits a ceiling very quickly. You end up having two APIs
with a totally unnecessary XML layer in between. Worse, the XML layer
spews error messages that are totally meaningless in terms of the new
object model.
I am going to skip the XML entirely and program against the parts of
the Ant object model I want to keep. It may be worthwhile to write a
tool that goes in the other direction, reading XML and emitting
lancet, for people porting existing buildfiles.
Cheers,
Stuart
>
> On Nov 6, 7:48 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
>> I am playing around with using Clojure to control Ant, something
>> along
>> the lines of Groovy's Gant. [....]
>
> I know next to nothing about ant, and what kind of control will lancet
> provide, but the proposed syntax reminds me of what I got playing with
> XML generation.
> As an exercise, I tried to reproduce clojure's build.xml and pom.xml
> (the output of the code below differs only in whitespace).
> Your proposal is more succint (in particular when it comes to
> properties), but I think it can be easily "expanded" to the
> representation below (which maps directly into XML).
>
> Cheers,
>
> Carlos
>
> (defn write-attributes [key val & attrs]
> (print (format " %s=\"%s\"" (name key) val))
> (when attrs (apply write-attributes attrs)))
>
> (defn write-tag [data close]
> (let [tag (name (if (coll? data)
> (first data)
> data))]
> (print (format "<%s" tag))
> (when (coll? data)
> (apply write-attributes (rest data)))
> (if close
> (do (print "/>") nil)
> (do (print ">") tag))))
>
> (defn write-xml [tree]
> (if (coll? tree)
> (let [values (rest tree)
> close-tag (write-tag (first tree) (not values))]
> (when (or (not (= 1 (count values)))
> (coll? (first values)))
> (println))
> (doall (map write-xml values))
> (when close-tag
> (println (format "</%s>" close-tag))))
> (print tree)))
>
> ;; build.xml
>
> (write-xml
> '((:project :name "clojure" :default "jar")
> (:description "Build with \"ant jar\" and then start the REPL
> via \"java -cp clojure.jar clojure.lang.Repl src/boot.clj\".")
> ((:property :name "src" :location "src"))
> ((:property :name "jsrc" :location "${src}/jvm"))
> ((:property :name "cljsrc" :location "${src}/clj"))
> ((:property :name "build" :location "classes"))
> ((:property :name "clojure_jar" :location "clojure.jar"))
> ((:property :name "bootclj" :location "${cljsrc}/clojure/
> boot.clj"))
> ((:target :name "init")
> (:tstamp)
> ((:mkdir :dir "${build}")))
> ((:target :name "compile" :depends "init" :description "Compile
> Java sources.")
> ((:javac :srcdir "${jsrc}" :destdir "${build}" :includeJavaRuntime
> "yes" :debug "true" :target "1.5")))
> ((:target :name "jar" :depends "compile" :description "Create jar
> file.")
> ((:jar :jarfile "${clojure_jar}" :basedir "${build}")
> ((:fileset :dir "${cljsrc}" :includes "**/*.clj"))
> (:manifest
> ((:attribute :name "Main-Class" :value "clojure.lang.Repl"))
> ((:attribute :name "Class-Path" :value ".")))))
> ((:target :name "clean" :description "Remove autogenerated files
> and directories.")
> ((:delete :dir "${build}")))))
>
> ;; pom.xml
>
> (defn write-pom [pom]
> (println "<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
> (write-xml
> (conj pom '(:project
> :xmlns "http://maven.apache.org/POM/4.0.0"
> :xmlns:xsi "http//www.w3.org/2001/XMLSchema-instance"
> :xsi:schemaLocation "http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd"))))
>
> (write-pom
> '((:modelVersion "4.0.0")
> (:groupId "jvm.clojure")
> (:artifactId "clojure-lang")
> (:name "clojure-lang")
> (:version "1.0-SNAPSHOT")
> (:url "http://clojure.org/")
> (:build
> (:sourceDirectory "src/jvm")
> (:scriptSourceDirectory "src/clj")
> (:plugins (:plugin
> (:artifactId "maven-compiler-plugin")
> (:configuration (:source "1.5") (:target "1.5") (:optimize
> "true"))))
> (:resources (:resource (:directory "src/clj/"))))))
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---