<project name="Castor CPA - PTF" default="compile.examples" 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.java"            value="${source}/test/java"/>
    <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}-examples"/>
    <property name="archive-sources"      value="${project}-${version}${release}-examples-sources"/>

	<property name="exampleexcludes"      value="codegen/*,**/dax/**"/>

	<artifact:dependencies filesetId="dependency.fileset" useScope="test">
	    <artifact:pom 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}/../cpa/build/classes"/>
    	<!--
        <pathelement location="${basedir}/../lib/commons-logging-1.1.jar"/>
        <pathelement location="${basedir}/../lib/ldapjdk_4.1.jar"/>
        <pathelement location="${basedir}/../lib/log4j-1.2.13.jar"/>
        <pathelement location="${basedir}/../lib/junit_3.8.2.jar"/>
        -->
    </path>

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

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

    <target name="clean.examples" description="Removes examples build directory">
        <delete dir="${build}"/>
    </target>

    <target name="compile.examples" depends="prepare.examples, derive.examples.libs" description="Compile example code">
        <javac srcdir="${main.java}" destdir="${classes}"
               debug="on" encoding="ISO-8859-1" deprecation="false"
        	   excludes="${exampleexcludes}">
            <classpath refid="build.classpath"/>
        	<classpath>
        		<fileset dir="${basedir}/lib" />
        	</classpath>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${main.resources}">
                <include name="**"/>
            </fileset>
        </copy>
    </target>

    <target name="jar.examples" depends="compile.examples" description="Build examples JAR file">
        <delete file="${basedir}/../dist/${archive}.jar" />
        <delete file="${basedir}/../dist/${archive-sources}.jar" />
    	
        <jar jarfile="${build}/${archive}.jar" basedir="${classes}" includes="**" />
        <copy file="${build}/${archive}.jar" tofile="${basedir}/../dist/${archive}.jar"/>

        <jar jarfile="${build}/${archive-sources}.jar">
            <fileset dir="${basedir}/src/main/java" includes="**" />
            <fileset dir="${basedir}/src/main/resources" includes="**" />
        </jar>
        <copy file="${build}/${archive-sources}.jar" tofile="${basedir}/../dist/${archive-sources}.jar"/>

    	<!-- check re:manifest file
            <jar jarfile="${dist}/${archive.name}-examples.jar" manifest="${build}/examples/META-INF/MANIFEST.MF">
                 <fileset dir="${build}/examples"/>
            </jar>
		-->            
    	
    </target>

</project>
