On 08/04/2010, at 5:45 PM, Jarkko Oranen wrote:
> Looks cool. This should help the XML-allergic :)
>
> Though, is there a reason why all symbol arguments to defmodel have to
> be quoted? It looks rather unpleasant. Seems like you should be able
> to fix that by changing the body of defmaven to
> `(reset! *MODEL* (Model ~@(for [a args] `(quote ~a))))
>
> Another possible approach is to wrap the free key-value pairs in a map
> or a vector so that it's easy to quote the whole form.
The point is that the unlike defproject, the body is assumed to be executable
content, rather than just data. And you can do
:dependencies '[[org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]
...
[hiccup "0.2.3"]]
which reduces the amount of quoting.
In fact, this defmaven form:
(defmaven 'org.clojure/clojure "1.2.0-master-SNAPSHOT"
:model-version "4.0.0"
:name "Lamdras Website"
:description "Acumen / LRMDS Integration"
:properties { :project.build.sourceEncoding "UTF-8" }
:packaging "war"
:dependencies [['ring/ring-servlet "0.2.0-RC2"]
['ring/ring-devel "0.2.0-RC2"]
['clj-routing/ "0.1.0-SNAPSHOT"]
['clout "0.2.0-SNAPSHOT"]
['compojure "0.4.0-SNAPSHOT"]
['hiccup "0.1.0-SNAPSHOT"]
'org.clojure/clojure
'org.clojure/clojure-contrib
'congomongo/congomongo]
:provided-dependencies [['org.mortbay.jetty/servlet-api-2.5 "6.1.14"]]
:build [:final-name "website"
:plugins [['org.apache.maven.plugins/maven-compiler-plugin "2.1"
:source "1.6" :target "1.6"]
['com.theoryinpractise/clojure-maven-plugin "1.3.1"
:sourceDirectories ["src/main/java"]
:executions [[:id "compile-clojure" :phase "compile" :goals
["compile"]]]]
['org.mortbay.jetty/maven-jetty-plugin "6.1.10"
:scanIntervalSeconds 10 :stopKey "foo" :stopPort 9999]]])
has an equivalent, canonical representation something like this:
(Model
:group-id "org.clojure" :artifact-id "clojure" :version "1.2.0-master-SNAPSHOT"
:model-version "4.0.0"
:name "Lamdras Website"
:description "Acumen / LRMDS Integration"
:properties { :project.build.sourceEncoding "UTF-8" }
:packaging "war"
:dependencies [(Dependency :group-id "ring" :artifact-id "ring-servlet"
:version "0.2.0-RC2")
(Dependency :group-id "ring" :artifact-id "ring-devel" :version
"0.2.0-RC2")
(Dependency :group-id "clj-routing" :artifact-id "clj-routing"
:version "0.1.0-SNAPSHOT")
(Dependency :group-id "clout" :artifact-id "clout" :version
"0.2.0-SNAPSHOT")
(Dependency :group-id "compojure" :artifact-id "compojure"
:version "0.4.0-SNAPSHOT")
(Dependency :group-id "hiccup" :artifact-id "hiccup" :version
"0.1.0-SNAPSHOT")
(Dependency :group-id "org.clojure" :artifact-id "clojure")
(Dependency :group-id "org.clojure" :artifact-id
"clojure-contrib")
(Dependency :group-id "congomongo" :artifact-id "congomongo")
(Dependency :group-id "org.mortbay.jetty" :artifact-id
"servlet-api-2.5" :version "6.1.14" scope: "provided")]
:build (Build
:final-name "website"
:plugins [(Plugin :group-id "org.apache.maven.plugins" :artifact-id
"maven-compiler-plugin" :version "2.1"
:configuration: [[:source "1.6"] [:target "1.6"]])
(Plugin :group-id "com.theoryinpractise" :artifact-id
"clojure-maven-plugin" :version "1.3.1"
:configuration [[:sourceDirectories [[:sourceDirectory
"src/main/java"]]]]
:executions [(Execution :id "compile-clojure" :phase
"compile" :goals ["compile"])])
(Plugin :group-id "org.mortbay.jetty" :artifact-id
"maven-jetty-plugin" :version "6.1.10"
:configuration [[:scanIntervalSeconds 10] [:stopKey "foo"]
[:stopPort 9999]])]))
where Model, Dependency, Build,. Plugin, Execution (and many more) are
functions that create e.g. org.apache.maven.model.Model and set the properties
from key/value arguments. There are a variety of shortcuts built into the
functions e.g. knowing the type of each field - which for the maven model is
even possible for List<> generics due to the presence of parallel addXXX(YYY)
methods for every setXXX(List) which gives you the erased parameter of the list
generic - allows you to elide the type constructor. The :configuration elements
are more complicated than I've shown because they need to generate nearly fill
XML with attributes and namespaces (but not mixed content).
Hopefully you can see that this syntax falls out of the direct construction of
maven Model object, unmediated by intermediate syntax or data structuring. So
there's a good reason for the way it looks.
Antony Blakey
-------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787
A reasonable man adapts himself to suit his environment. An unreasonable man
persists in attempting to adapt his environment to suit himself. Therefore, all
progress depends on the unreasonable man.
-- George Bernard Shaw
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
To unsubscribe, reply using "remove me" as the subject.