<?xml version="1.0"?>

<project name="aop examples annotated" default="help">

   <property name="build.sysclasspath" value="ignore"/>
   <property name="junit.timeout" value="180000"/>
   <!-- 3 minutes -->

   <property file="./build.properties"/>

   <!-- set local properties for this build -->
   <path id="lib.classpath">
      <fileset dir="${cache_lib}">
         <include name="**/*.jar"/>
      </fileset>
      <pathelement path="${build}"/>
   </path>

   <path id="aop.classpath">
      <fileset dir="${cache_lib}">
         <include name="javassist.jar"/>
         <include name="trove.jar"/>
         <include name="concurrent.jar"/>
         <include name="jboss-common.jar"/>
         <include name="jboss-aop.jar"/>
         <include name="log4j.jar"/>
      </fileset>
   </path>

   <target name="help" description="help page">
      <echo message="build.sh &lt;command&gt; where command is:"/>
      <echo message="         compile       -- compile the examples code"/>
      <echo message="         clobber       -- clean up the whole directory"/>
      <echo message="         run.aop.example -- run aop examples with annoc and aopc pre-compiler"/>
      <echo message="         run.aop.demo  -- run demo gui for aop cache"/>
   </target>

   <!-- set up directory -->
   <target name="init" description="Prepare to build.">
      <!-- Create the time stamp -->
      <tstamp/>
      <!-- Create the build directory structure used by compile
and copy the deployment descriptors into it-->
      <mkdir dir="${build}"/>
      <mkdir dir="${reports}"/>
   </target>

   <target name="clean" description="Clean up compiled classes">
      <delete dir="${output}"/>
   </target>

   <target name="clobber" depends="clean"/>

   <!-- compile directory -->
   <target name="compile" depends="init" description="Build unit testing class">
      <javac srcdir="${source}"
             destdir="${build}"
             includes="**/**"
             debug="true"
             deprecation="true">
         <classpath>
            <path refid="lib.classpath"/>
         </classpath>
      </javac>

      <copy todir="${output}/etc">
         <fileset dir="${cache_etc}">
            <include name="**/*"/>
         </fileset>
      </copy>
   </target>

   <target name="generateClassLoader"
           description="Generate a new modified class loader so we can perform load time instrumentation">
      <!-- Generate the new classloader in a special dir under output -->
      <property name="build.bootclasspath" value="${output}/gen-bootclasspath"/>
      <java classname="org.jboss.aop.hook.GenerateInstrumentedClassLoader">
         <classpath>
            <path refid="lib.classpath"/>
         </classpath>
         <arg value="${build.bootclasspath}"/>
      </java>
   </target>

   <target name="run.aop.example" depends="generateClassLoader, compile"
           description="run standalone server replicator.">

      <!-- Create a special bootclasspath that contains the classloader we generated, plus the library files used by aop.  DO NOT INCLUDE the domain model classes -->
      <path id="bootclasspath">
         <pathelement location="${build.bootclasspath}"/>
         <path refid="aop.classpath"/>
      </path>
      <property name="bootclasspath" refid="bootclasspath"/>

      <java classname="test.examples.StudentMaintTest" fork="yes">

         <!-- Set the bootclasspath to be the one we created above -->
         <jvmarg value="-Xbootclasspath/p:${bootclasspath}"/>
         <jvmarg value="-Djboss.aop.path=${source}/jboss-aop.xml"/>
         <classpath refid="lib.classpath"/>
         <classpath path="${build}"/>
         <classpath path="${output}/etc"/>
      </java>

   </target>

   <target name="run.aop.demo" depends="compile" description="run tree cache demo.">
      <java classname="org.jboss.cache.aop.TreeCacheAopView" fork="yes">
         <jvmarg value="-Xmx128M"/>
         <classpath refid="lib.classpath"/>
         <sysproperty key="log4j.configuration" value="file:${output}/etc/log4j.xml"/>
         <classpath path="${output}/etc"/>
         <classpath path="${build}"/>
      </java>
   </target>


</project>
