Since I didn't find any other solutions on the web, I worte an ant build.xml
that generates jdo metadata files based on @jdo xdoclet tags in java files
having the @jdo.persistence-capable tag and afterwards uses these metadata
files to automatically enhances the class files using the sun JDO enhancer.
This is the first build I ever wrote, therefore it doesn't contain any best
practices. Therefore comments and suggestions are more than welcome.
Sebastian
<?xml version="1.0" encoding="UTF-8"?>
<project name="JDOTest" default="compile" basedir=".">
<!-- ================================ -->
<!-- Global properties -->
<!-- ================================ -->
<property name="version" value="1.0"/>
<property name="jarname" value="jdotest.jar"/>
<property name="runclass" value="sebthom.jdotest.Main"/>
<property name="classpath" value=""/>
<property name="build.compiler" value="jikes"/>
<!-- ================================ -->
<!-- Project directories -->
<!-- ================================ -->
<property name="bin" value="bin"/>
<property name="docs" value="docs"/>
<property name="includes" value="includes"/>
<property name="lib" value="lib"/>
<property name="src" value="src"/>
<property name="bin_absolute" location="${bin}"/>
<property name="docs_absolute" location="${docs}"/>
<property name="includes_absolute" location="${includes}"/>
<property name="lib_absolute" location="${lib}"/>
<property name="src_absolute" location="${src}"/>
<!-- ================================ -->
<!-- Class path -->
<!-- ================================ -->
<path id="base.path">
<!-- use the value of the ${classpath} property in the classpath -->
<pathelement path="${classpath}"/>
<!-- includes all jar files in lib -->
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<!-- includes all jar files in includes -->
<fileset dir="${includes}">
<include name="**/*.jar"/>
</fileset>
<!-- includes all compiled class files in includes -->
<dirset dir="${includes}">
<include name="**"/>
</dirset>
</path>
<!-- ================================ -->
<!-- Additional ant tasks -->
<!-- ================================ -->
<taskdef classpathref="base.path"
resource="net/sf/antcontrib/antcontrib.properties" />
<taskdef classpathref="base.path" name="jdodoclet"
classname="xdoclet.modules.jdo.JdoDocletTask"/>
<!-- ================================ -->
<!-- Target: display properties -->
<!-- ================================ -->
<target name="display properties">
<echoproperties/>
</target>
<!-- ================================ -->
<!-- Target: compile -->
<!-- ================================ -->
<target name="compile">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${bin}"/>
<!-- run javac to compile the source files -->
<javac srcdir="${src}" destdir="${bin}" debug="on"
classpathref="base.path"/>
<!-- generate metadata.jdo file in bin directory -->
<jdodoclet
addedtags="@xdoclet-generated at ${TODAY},@copyright The XDoclet
Team,@author XDoclet,@version ${version}"
excludedtags="@version,@author,@todo"
destdir="${bin}"
verbose="false"
>
<fileset dir="${src}">
<include name="**/*.java"/>
</fileset>
<jdometadata generation="package"/>
</jdodoclet>
<!-- enhance every class containing @jdo.persistence-capable tag -->
<foreach target="compile.jdoEnhancer" param="param_JavaFile">
<fileset dir="${src}">
<include name="**/*.java"/>
<or>
<contains text="@jdo.persistence-capable"
casesensitive="no"/>
<contains text="@jdo:persistence-capable"
casesensitive="no"/>
</or>
</fileset>
</foreach>
</target>
<target name="compile.jdoEnhancer">
<!-- set javaFile.fullname --> <property name ="javaFile.fullname"
value="${param_JavaFile}"/>
<!-- set javaFile.directory --> <dirname
property="javaFile.directory" file="${javaFile.fullname}"/>
<!-- set javaFile.filename --> <basename property="javaFile.filename"
file="${javaFile.fullname}"/>
<!-- set javaFile.basename --> <basename property="javaFile.basename"
file="${javaFile.fullname}" suffix=".java"/>
<!-- set classFile.fullname -->
<pathconvert property="classFile.fullname" targetOS="unix">
<path>
<pathelement
location="${javaFile.directory}${file.separator}${javaFile.basename}.class"/>
</path>
<map from="${src_absolute}" to="${bin_absolute}" />
</pathconvert>
<!-- set classFile.directory -->
<dirname property="classFile.directory"
file="${classFile.fullname}"/>
<echo>Enhancing: ${classFile.fullname}</echo>
<java fork="yes" failonerror="yes"
classname="com.sun.jdori.enhancer.Main" classpathref="base.path">
<!-- Even if the enhancer expects a parameter for the location of
the JDO file, the JDO file
has to be named {package}.jdo and has to be at the same level
as the package folder itself.
Any other location or filename will be ignored by the
enhancer.
/com/
/com/mycompany/
/com/mycompany/mypackage.jdo <== the JDO file is named
{package}.jdo
/com/mycompany/mypackage/MyClass.class
-->
<arg line="-d "${bin}" -f
"${classFile.directory}.jdo" "${classFile.fullname}""/>
</java>
</target>
<!-- ================================ -->
<!-- Target: jar -->
<!-- ================================ -->
<target name="jar" depends="compile">
<!-- Create the directory for the jar file -->
<mkdir dir="${lib}"/>
<pathconvert pathsep=" " property="jar.classpath" refid="base.path"/>
<!-- make a jar file -->
<jar jarfile="${lib}/${jarname}" basedir="${bin}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="${runclass}"/>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
</target>
<!-- ================================ -->
<!-- Target: docs -->
<!-- ================================ -->
<target name="docs" depends="compile">
<!-- Create the directory for the java docs -->
<mkdir dir="${docs}"/>
<!-- create javadocs -->
<javadoc
sourcepath="${src}"
defaultexcludes="yes"
destdir="${docs}"
author="true"
version="true"
use="true"
windowtitle="${ant.project.name} API Documentation Version:
${version}"
>
<classpath refid="base.path"/>
<packageset dir="${src}" defaultexcludes="yes">
<include name="sebthom/**" />
</packageset>
</javadoc>
</target>
<!-- ================================ -->
<!-- Target: run -->
<!-- ================================ -->
<target name="run" depends="jar,docs">
<!-- run the class -->
<java classname="${runclass}" classpathref="base.path">
<!-- to add a command line arg use: <arg value="-h"/> -->
</java>
</target>
<!-- ================================ -->
<!-- Target: clean -->
<!-- ================================ -->
<target name="clean">
<!-- Delete the ${bin} and ${docs} directory trees -->
<delete dir="${bin}"/>
<delete dir="${docs}"/>
<!-- Delete output jar file -->
<delete file="${lib}/${jarname}"/>
</target>
</project>
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
Bitte l�cheln! Fotogalerie online mit GMX ohne eigene Homepage!
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user