<project name="Castor XML - XML diff" default="compile.diff" basedir="."
	xmlns:artifact="antlib:org.apache.maven.artifact.ant">

    <!-- $Id: build.xml 0000 2007-01-19 21:12:08Z ekuns $ -->

    <property environment="env" />
    <property name="source"               value="${basedir}/src"/>
    <property name="main.java"            value="${source}/main/java"/>
    <property name="main.resources"       value="${source}/main/resources"/>
    <property name="test.resources"       value="${source}/test/resources"/>
    <property name="build"                value="${basedir}/build"/>
    <property name="classes"              value="${build}/classes"/>
    <property name="archive"              value="${project}-${version}${release}-xml-diff"/>

	<artifact:dependencies filesetId="dependency.fileset" useScope="test">
	    <artifact:pom id="core" file="${basedir}/pom.xml" />
    </artifact:dependencies>	
	
    <path id="build.classpath">
        <pathelement location="${basedir}/build/classes"/>
        <pathelement location="${basedir}/../build/classes"/>
        <pathelement location="${basedir}/../core/build/classes"/>
    	<!--
        <pathelement location="${basedir}/../lib/commons-logging-1.1.jar"/>
        <pathelement location="${basedir}/../lib/junit_3.8.2.jar"/>
        -->
    </path>

	<target name="derive.diff.libs">
		<mkdir dir="${basedir}/lib" />  	
	    <copy todir="${basedir}/lib" verbose="true">
	      <fileset refid="dependency.fileset"/>
	      <mapper type="flatten"/>
	    </copy>
	</target>	

    <target name="prepare.diff" unless="prepare.diff.executed">
        <mkdir dir="${build}"/>
        <mkdir dir="${classes}"/>
        <property name="prepare.diff.executed" value="true"/>
    </target>

    <target name="clean.diff" description="Removes XML diff build directory">
        <delete dir="${build}"/>
    </target>
	
    <target name="clean.tests.diff" description="Removes test build directory">
        <delete dir="${test.classes}"/>
    </target>


    <target name="compile.diff" depends="prepare.diff, derive.diff.libs" description="Compile XML diff">
        <javac srcdir="${main.java}" destdir="${classes}"
               debug="on" encoding="ISO-8859-1" deprecation="false"
               source="1.5" target="1.5">
            <classpath refid="build.classpath"/>
        	<classpath>
        		<fileset dir="${basedir}/lib"/>
        	</classpath>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${main.resources}">
                <include name="**"/>
            </fileset>
            <filterset begintoken="$${" endtoken="}">
                <filter token="VERSION" value="${version}"/>
                <filter token="RELEASE" value="${release}"/>
            </filterset>
        </copy>
    </target>

    <target name="jar.diff" depends="compile.diff" description="Build XML diff JAR file">
        <jar jarfile="${build}/${archive}.jar" basedir="${classes}" includes="**"
             manifest="${classes}/META-INF/MANIFEST.MF"/>
        <copy file="${build}/${archive}.jar" tofile="${basedir}/../dist/${archive}.jar"/>
    </target>

</project>
