<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE project [
   <!ENTITY common-config SYSTEM "build-common.xml">
]>
<!-- version: $Id: build.xml,v 1.18 2005/05/12 10:39:47 nthx Exp $ -->
<project name="pat" basedir="." default="help">
    <description>
        PAT - Persistent Applications Toolkit
        http://patsystem.sourceforge.net
    </description>

    &common-config;

    <target name="help">
    <echo>
    You may run several ant targets:
    >
    > ant skeleton-app               - runs your app found in
    >                                 (src/skeleton-app)
    >                                              
    > ant dist                       - creates binary library
    >                                  of PAT for use in your
    >                                  project
    >
    > ant tests                      - runs almost all tests
    > ant tests2                     - runs the rest of tests
    >
    > ant run-demo-withSnapshot      - demo app (with snapshot)
    > ant run-demo-withoutSnapshot   - demo app
    >
    > ant run-performance-demo       - adjustable performance
    >                                  demo
    </echo>
    </target>

    <target name="init" depends="common:init">
    </target>

    
    <!--
       |  Using PAT, compilation process consists of 3 phases
       |  1) Compile Java files
       |       (input=selected sources: "*.java")
       |  2) Compile annotations
       |       (input=all sources: "**/*.java")
       |  3) Weave *.class files with JBossAOP compiler
       |       (input=bytecode: "**/*.class"
       |              jboss.aop.path: "etc/")
     -->
    <target name="compile" depends="clean, init"
            description="Java sources compilation">
        <javac
            destdir="${build.classes.dir}"
            debug="on"
            deprecation="on"
            depend="on"
            nowarn="on"
            optimize="off">

            <include name="**/*.java" />
            <src path="${src.main.dir}" />
            <src path="${src.prevayler.dir}" />
            <src path="${src.tests.dir}" />
            <src path="${src.skeleton-app.dir}" />

            <classpath refid="run_classpath"/>
        </javac>
        <annotationc compilerclasspathref="run_classpath"
                     classpathref="run_classpath"
                     bytecode="true">
            <src path="${src.dir}"/>
        </annotationc>
        <aopc compilerclasspathref="run_classpath"
              classpathref="run_classpath"
              verbose="false">
            <classpath path="run_classpath" />
            <src path="${build.classes.dir}" />
            <aoppath path="${etc.dir}/" />
        </aopc>
    </target>

    <target name="dist" depends="compile"
            description="Creates distribution JARs">
        <mkdir dir="${dist.dir}" />
        <jar destfile="${dist.dir}/pat-${release}.jar"
             basedir="${build.classes.dir}">
            <include name="org/nthx/**/*.*"/>
            <include name="pat/**/*.*"/>
            <exclude name="org/nthx/pat/demo/**/*.*"/>
            <exclude name="org/nthx/pat/tests/**/*.*"/>
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Implementation-Version" value="${release} ${TODAY}"/>
            </manifest>
        </jar>
        <jar destfile="${dist.dir}/prevayler1-for_pat-${release}.jar"
             basedir="${build.classes.dir}">
            <include name="org/prevayler/**/*.*"/>
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Implementation-Version" value="${release} ${TODAY}"/>
            </manifest>
        </jar>
        <copy todir="${dist.dir}">
            <fileset dir="${jboss.aop.path}">
                <include name="**/*-aop.xml" />
            </fileset>
        </copy>
    </target>

    <!--
       | Run users app based on skeleton code
     -->
    <target name="skeleton-app" depends="compile"
            description="Runs skeleton app">
        <java classname="${app.main.class}"
              classpathref="run_classpath"
              fork="yes" dir="${build.classes.dir}">

            <classpath refid="run_classpath" />
            <sysproperty key="jboss.aop.path" value="${basedir}/${jboss.aop.path}" />
            <sysproperty key="repository.dir"
                         value="${basedir}/${repository.dir}/skeleton-app" />
        </java>
    </target>


    <!--
       |  Runs demonstration program, without taking snapshot
     -->
    <target name="run-demo-withoutSnapshot"
            depends="compile"
            description="Runs demo, but doesn't take a snapshot" >
        <java classname="org.nthx.pat.demo.Driver"
              classpathref="run_classpath"
              fork="yes" dir="${build.classes.dir}">

            <classpath refid="run_classpath" />
            <sysproperty key="take.snapshot" value="false" />
            <sysproperty key="repository.dir"
                         value="${basedir}/${repository.dir}/demo" />
            <sysproperty key="jboss.aop.path" value="${basedir}/${jboss.aop.path}" />
        </java>
    </target>
    <!--
       |  Runs demonstration program. The difference with above is
       |  it takes snapshot at the end
     -->
    <target name="run-demo-withSnapshot"
            depends="compile"
        description="Runs demo and takes a snapshot" >
        <java classname="org.nthx.pat.demo.Driver"
              classpathref="run_classpath"
              fork="yes" dir="${build.classes.dir}">

            <classpath refid="run_classpath" />
            <sysproperty key="take.snapshot" value="true" />
            <sysproperty key="repository.dir"
                         value="${basedir}/${repository.dir}/demo" />
            <sysproperty key="jboss.aop.path" value="${basedir}/${jboss.aop.path}" />
        </java>
    </target>

    <!--
       | Performance test: generate as much as possible, take snapshot, see if
       | your system can handle PAT.
       | Please customize numbers:
       |            -Xmx=???M  - maximum amount of memory for JVM
       |            users.count - data size
     -->
    <target name="run-performance-demo"
            depends="compile"
        description="Runs adjustable performance demo">
        <java classname="org.nthx.pat.demo.PerformanceDemo"
              classpathref="run_classpath"
              fork="yes" dir="${build.classes.dir}">
            <jvmarg value="-Xmx900M" />

            <classpath refid="run_classpath" />

            <!-- must be integer -->
            <sysproperty key="users.count" value="1099" />

            <sysproperty key="take.snapshot" value="true" />
            <sysproperty key="repository.dir"
                         value="${basedir}/${repository.dir}/performance" />
            <sysproperty key="jboss.aop.path" value="${basedir}/${jboss.aop.path}" />
        </java>
    </target>


    <!--
       |  Run test for PAT
     -->
    <target name="check-os">
        <condition property="isWindows">
        <or>
            <os family="windows"/>
            <os family="win9x"/>
        </or>
        </condition>
    </target>
    <target name="tests-windows-warning" depends="check-os" if="isWindows">
        <echo>
        WARNING: some tests may not pass on Windows.
        This is related to "File.delete() vs. System.gc()"
        Windows OS' issue.
        </echo>
        <sleep seconds="2" />
    </target>
    <target name="tests"
            depends="junit-check, compile, tests-windows-warning"
            description="Runs main test cases for PAT" >
        
        <delete verbose="true" dir="${basedir}/${repository.dir}/tests"/>
        <junit printsummary="yes"
               haltonfailure="yes"
               showoutput="yes"
               failureproperty="tests.failure"
               fork="true" dir="${build.classes.dir}" >
            <jvmarg value="-Drepository.dir=${basedir}/${repository.dir}/tests"/>
            <jvmarg value="-Djboss.aop.path=${basedir}/${jboss.aop.path}"/>

            <classpath refid="run_classpath" />
            
            <formatter type="plain" usefile="false" />

            <batchtest fork="yes"
                       haltonfailure="yes">
                <fileset dir="${src.tests.dir}">
                    <include name="**/*Test.java" />
                    <exclude name="**/*Recovery*Test.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

    <!--
       |  Run test for PAT - 2nd suite
     -->
    <target name="tests2" depends="junit-check, compile, tests-windows-warning"
            description="Runs Recovery type of tests">
        
        <delete verbose="true" dir="${basedir}/${repository.dir}/tests"/>
        <junit printsummary="yes"
               haltonfailure="yes"
               showoutput="yes"
               failureproperty="tests.failure"
               fork="true" dir="${build.classes.dir}" >
            <jvmarg value="-Drepository.dir=${basedir}/${repository.dir}/tests"/>
            <jvmarg value="-Djboss.aop.path=${basedir}/${jboss.aop.path}"/>

            <classpath refid="run_classpath" />
            
            <formatter type="plain" usefile="false" />

            <batchtest fork="yes"
                       haltonfailure="yes">
                <fileset dir="${src.tests.dir}">
                    <include name="**/*RecoveryTest.java" />
                </fileset>
            </batchtest>
            <batchtest fork="yes"
                       haltonfailure="yes">
                <fileset dir="${src.tests.dir}">
                    <include name="**/*RecoveryConfirmationTest.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>
</project>