Antlib enhancement

From: Erik Hatcher (eri..hatchersolutions.com)
Date: Fri Apr 22 2005 - 16:46:06 EDT

  • Next message: Andrus Adamchik: "Re: Null Pointer error"

    Big thanks to the Cayenne team for building a very nice tool. I have
    been using 1.2M3 and was wanting a way to create my database from Ant
    directly from the model rather than from exporting a .sql file. I dug
    around a little and found the <cdbgen> task that has been added - very
    nice and exactly what I was looking for. Works great.

    One suggestion for making life easier in Ant with Cayenne is to take
    advantage of the Antlib facility:

            http://ant.apache.org/manual/CoreTypes/antlib.html

    To show how this works, I integrated it into my builds. First I
    created a cayenne-antlib.xml file like this:

            <antlib>
                    <taskdef name="cgen"
    classname="org.objectstyle.cayenne.tools.CayenneGenerator"/>
                    <taskdef name="cdbgen"
    classname="org.objectstyle.cayenne.tools.DbGeneratorTask"/> </antlib>

    I'm not using <cdeploy> yet, so I didn't add it.

    To pull in the Cayenne tasks into Ant in one shot, I do this:

            <project name="collex" default="default" xmlns:cayenne="cayenne">

                    <typedef file="cayenne-antlib.xml" uri="cayenne">
                            <classpath>
                                    <fileset refid="cayenne.jars"/>
                            </classpath>
                    </typedef>

    ...

            </project>

    I now use the tasks using <cayenne:cdbgen> and <cayenne:cgen>.

    Cayenne itself could embed an antlib.xml file like the above (with the
    cdeploy added) inside the Cayenne JAR file, and then it could be
    imported magically from the classpath using <typedef> as above, except
    resource="org/objectstyle/cayenne/antlib.xml" instead of file="..."
    (with antlib.xml living in the package org.objectstyle.cayenne). With
    Antlib, the tasks could even be defined just on the Ant <project>
    element using xmlns:cayenne="antlib:org.objectstyle.cayenne", but this
    would require all the dependent JAR's be on the Ant classpath and not
    quite friendly for Cayenne. But, Antlib in general is a great way to
    work with Ant these days.. it'll hide your fully qualified class names
    into a descriptor you control and will allow you to define new tasks
    without requiring more copy/paste into build files to taskdef.

    I would like to see this in the final binary release of 1.2 if
    possible. It's simple - embed a single XML file like the above in the
    Cayenne JAR files, that's all.

            Erik



    This archive was generated by hypermail 2.0.0 : Fri Apr 22 2005 - 16:46:44 EDT