> On 2008-11-26, Stuart Sierra <[EMAIL PROTECTED]> wrote:

>> The Ant task looks like this:

>>      <property name="cljsrc" location="${src}/clj"/>
>>      <property name="build" location="classes"/>
>>      <property name="precompile" location="${cljsrc}/precompile.clj"/>
>>      ...
>>      <target name="core" depends="compile"
>>              description="Precompile Clojure core sources.">
>>              <java classname="clojure.lang.Script"
>>                       classpath="${build}:${cljsrc}">
>>                         <sysproperty key="clojure.compile.path"
>>                                      value="${build}"/>
>>                      <arg value="${precompile}"/>
>>              </java>
>>      </target>

> It should be pretty easy to wrap this in a macrodef or two, which
> could go into an antlib.xml file in clojure.jar so that

The attached antlib.xml would need to go into clojure.jar under the
directory clojure (the rest of the attachment is a patch to build.xml
that takes care of this).

But in reality this approach doesn't get us very far since the whole
classpath logic is too complex to make it really useful when
implemented in XML instead of Java or Clojure.

Oh, an example for clj:compile is in the patch, but I'm cheating - it
won't work that easily for code other than Clojure itself.

<clj:script> works and may actually be usuable as is:

<project xmlns:clj="antlib:clojure">
  <taskdef uri="antlib:clojure">
    <classpath location="clojure.jar"/>
  </taskdef>

  <clj:script script="hello.clj">
    <classpath>
      <classpath location="clojure.jar"/>
    </classpath>
  </clj:script>
</project>

and hello.clj

(println "Hello, world!")

result in

Buildfile: testantlib.xml
     [java] Hello, world!

BUILD SUCCESSFUL
Total time: 1 second

Stefan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Index: src/jvm/clojure/antlib.xml
===================================================================
--- src/jvm/clojure/antlib.xml	(revision 0)
+++ src/jvm/clojure/antlib.xml	(revision 0)
@@ -0,0 +1,31 @@
+<antlib xmlns:clj="antlib:clojure">
+  
+  <macrodef name="script">
+    <attribute name="script"/>
+    <element name="classpath" optional="true"/>
+    <element name="args" optional="true"/>
+    <sequential>
+      <java classname="clojure.lang.Script" fork="true" failonerror="true">
+        <classpath/>
+        <arg value="@{script}"/>
+        <args/>
+      </java>
+    </sequential>
+  </macrodef>
+
+  <macrodef name="compile">
+    <attribute name="srcdir"/>
+    <attribute name="destdir"/>
+    <element name="classpath" optional="true"/>
+    <element name="args"/>
+    <sequential>
+      <java classname="clojure.lang.Compile"
+            fork="true" failonerror="true"
+            classpath="@{destdir}:@{srcdir}">
+        <sysproperty key="clojure.compile.path" value="@{destdir}"/>
+        <classpath/>
+        <args/>
+      </java>
+    </sequential>
+  </macrodef>
+</antlib>
Index: build.xml
===================================================================
--- build.xml	(revision 1127)
+++ build.xml	(working copy)
@@ -22,18 +22,30 @@
            debug="true" target="1.5"/>
   </target>
 
-  <target name="compile_clojure" depends="compile_java"
+  <target name="write_antlib" depends="compile_java"
+          description="writes the AntLib descriptor">
+    <copy todir="${build}">
+      <fileset dir="${jsrc}" includes="**/antlib.xml"/>
+    </copy>
+  </target>
+
+  <target name="compile_clojure" depends="compile_java,write_antlib"
           description="Compile Clojure sources.">
-    <java classname="clojure.lang.Compile"
-          classpath="${build}:${cljsrc}">
-      <sysproperty key="clojure.compile.path" value="${build}"/>
+    <taskdef uri="antlib:clojure">
+      <classpath location="${build}"/>
+    </taskdef>
+
+    <clj:compile srcdir="${cljsrc}" destdir="${build}"
+                 xmlns:clj="antlib:clojure">
+      <args>
       <arg value="clojure.core"/>
       <arg value="clojure.main"/>
       <arg value="clojure.set"/>
       <arg value="clojure.xml"/>
       <arg value="clojure.zip"/>
       <arg value="clojure.inspector"/>
-    </java>
+      </args>
+    </clj:compile>
   </target>
 
   <target name="jar" depends="compile_clojure"

Reply via email to