<project name="BrittonReportServer" default="war" basedir=".">
    
    <!-- Path properties -->
    <property name="src.dir" value="src"/>
    <property name="web.dir" value="web"/>
    <property name="lib.dir" value="${web.dir}/lib"/>
    <property name="build.dir" value="build"/>
    <property name="dist.dir" value="dist"/>
    <property name="reports.src.dir" value="${web.dir}/reports"/>
    <property name="reports.dest.dir" value="${web.dir}/reports"/>
    <!-- <property name="tomcat.home" value="/usr/local/tomcat" /> -->

    <!-- Define the classpath for Jasper and Servlet API -->
    <path id="jasper.classpath">
        <fileset dir="${lib.dir}">
            <include name="*.jar"/>
        </fileset>
        <fileset dir="/opt/tomcat/lib">
            <include name="*.jar"/>
        </fileset>
        <!-- <fileset dir="${tomcat.home}/lib">
            <include name="servlet-api.jar"/>
            <include name="jsp-api.jar"/>
            <include name="jasper.jar"/>
        </fileset> -->
        <!-- Ensure servlet-api is included, often provided by server -->
        <!-- <pathelement location="trunk/servlet-api.jar"/> -->
    </path>

    <!-- <path id="tomcat.classpath">
        <fileset dir="/opt/tomcat/lib">
            <include name="*.jar"/>
        </fileset>
    </path> -->

    <!-- Define JasperReports Ant Task -->
    <taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
        <classpath refid="jasper.classpath"/>
    </taskdef>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <!-- 1. Compile Servlet Java code -->
    <target name="compile-java" depends="clean">
        <mkdir dir="${build.dir}/classes"/>
        <javac srcdir="${src.dir}/java/com/britton" destdir="${build.dir}/classes">
            <!-- <classpath>
                <pathelement location="trunk/servlet-api.jar"/>
            </classpath> -->
            <classpath refid="jasper.classpath"/>
            <include name="**/*.java"/>
        </javac>
    </target>

    <!-- 2. Pre-compile JRXML reports to .jasper -->
    <target name="compile-reports">
        <!-- <mkdir dir="${reports.dest.dir}"/> -->
        <jrc srcdir="${reports.src.dir}" 
             destdir="${reports.dest.dir}">
            <classpath refid="jasper.classpath"/>
            <include name="**/*.jrxml"/>
        </jrc>
    </target>

    <target name="compile-all" depends="compile-java, compile-reports"/>

    <target name="war" depends="compile-all" description="Packages the application into a WAR file">
        <war destfile="${dist.dir}/BrittonReportServer.war" webxml="${web.dir}/WEB-INF/web.xml">
            <fileset dir="${web.dir}"/>
            <lib dir="${web.dir}/lib"/>
            <classes dir="${build.dir}/classes"/>
        </war>
    </target>
</project>