<project name="EJB3Trail" default="all" basedir=".">

  <property name="src.dir" value="${basedir}/src"/>
  <property name="build.dir"   value="${basedir}/build"/>

  <!-- The build classpath -->
  <path id="build.classpath">
    <fileset dir="${basedir}/lib/">
      <include name="*.jar"/>
    </fileset>
  </path>

  <taskdef name="java2html"
    classname="de.java2html.anttasks.Java2HtmlTask"
    classpath="${basedir}/lib/java2html.jar"
  />

  <target name="prepare">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir}/classes"/>
    <mkdir dir="${build.dir}/jar"/>
    <mkdir dir="${build.dir}/EJB3Trail"/>
    <mkdir dir="${build.dir}/zip"/>
  </target>

  <!-- MUST use JDK 1.5 compiler -->
  <target name="compile" depends="prepare">
    <javac destdir="${build.dir}/classes"
      classpathref="build.classpath"
      debug="on">
      <src path="${src.dir}"/>
    </javac>
  </target>

  <!-- Package all the EJB classes -->
  <target name="package-ejb" depends="compile">
    <jar jarfile="${build.dir}/jar/beans.jar">
      <fileset dir="${build.dir}/classes">
        <include name="trail/**"/>
      </fileset>

      <fileset dir="dd/ejb">
        <include name="import.sql" />
        <include name="*.properties"/>
      </fileset>

      <metainf dir="dd/ejb">
        <include name="persistence.xml"/>
      </metainf>
    </jar>
  </target>


  <!-- Package the web module -->
  <target name="package-web" depends="compile">
    <war warfile="${build.dir}/jar/web.war"
      webxml="dd/web/web.xml">

      <fileset dir="docs">
        <include name="**/*"/>
        <exclude name="**/*.cp"/>
        <exclude name="**/*.graffle"/>
      </fileset>
      <webinf dir="dd/web">
        <include name="jboss-web.xml"/>
      </webinf>
    </war>
  </target>

  <!-- Creates an ear file containing all
       the modules as well as application.xml. -->
  <target name="assemble-app">
    <jar jarfile="${build.dir}/jar/EJB3Trail.ear">

      <metainf dir="dd/ear">
        <include name="application.xml"/>
        <include name="jboss-app.xml" />
      </metainf>

      <fileset dir="${build.dir}/jar"
        includes="*.jar,*.war"/>
    </jar>

    <delete file="${build.dir}/jar/web.war"/>
    <delete file="${build.dir}/jar/beans.jar"/>
    <delete dir="${build.dir}/classes"/>
  </target>

  <!-- Package the source zip file -->
  <target name="assemble-src" depends="prepare">

    <copy todir="${build.dir}/EJB3Trail">
      <fileset dir="..">
        <include name="tools/**"/>
        <include name="EJB3/**"/>
        <exclude name="**/CVS"/>
        <exclude name="**/.svn"/>
        <exclude name="**/build"/>
        <exclude name="**/dd2"/>
      </fileset>
      <fileset dir=".">
        <include name="README.txt"/>
      </fileset>
    </copy>

    <zip destfile="${build.dir}/zip/EJB3Trail.zip"
         basedir="${build.dir}/EJB3Trail"
    />
  </target>

  <target name="clean">
    <delete dir="${build.dir}" />
    <delete dir="docs/serviceobjects/slsb/code"/>
    <delete dir="docs/serviceobjects/sfsb/code"/>
    <delete dir="docs/serviceobjects/lifecycle/code"/>
    <delete dir="docs/serviceobjects/jmx/code"/>
    <delete dir="docs/serviceobjects/mdb/code"/>
    <delete dir="docs/serviceobjects/mdpojo/code"/>
    <delete dir="docs/serviceobjects/injection/code"/>
    <delete dir="docs/persistence/orm/code"/>
    <delete dir="docs/persistence/entitymanager/code"/>
    <delete dir="docs/persistence/entityquery/code"/>
    <delete dir="docs/persistence/updateentity/code"/>
    <delete dir="docs/services/transaction/code"/>
    <delete dir="docs/services/apptrans/code"/>
    <delete dir="docs/services/security/code"/>
    <delete dir="docs/services/interceptor/code"/>
  </target>

  <target name="all">
    <antcall target="clean" />
    <antcall target="java2html"/>
    <antcall target="package-ejb" />
    <antcall target="package-web" />
    <antcall target="assemble-app" />
    <antcall target="assemble-src" />
  </target>

  <!-- The following 4 tasks use dd2 to build
       a target that uses virtual host on
       demo.jboss.com domain. -->
  <target name="all2">
    <antcall target="clean" />
    <antcall target="java2html"/>
    <antcall target="package-ejb" />
    <antcall target="package-web2" />
    <antcall target="assemble-app" />
    <antcall target="assemble-src" />
  </target>
  <target name="package-web2" depends="compile">
    <war warfile="${build.dir}/jar/web.war"
      webxml="dd2/web/web.xml">

      <fileset dir="docs">
        <include name="**/*"/>
        <exclude name="**/*.cp"/>
        <exclude name="**/*.graffle"/>
      </fileset>
      <webinf dir="dd2/web">
        <include name="jboss-web.xml"/>
      </webinf>
    </war>
  </target>


  <target name="java2html">

      <!-- SLSB -->
      <delete dir="docs/serviceobjects/slsb/code"/>
      <mkdir dir="docs/serviceobjects/slsb/code"/>
      <java2html
        srcdir="${src.dir}/trail/slsb/" destdir="docs/serviceobjects/slsb/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/slsb/" destdir="docs/serviceobjects/slsb/code/" includes="calculator.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- SFSB -->
      <delete dir="docs/serviceobjects/sfsb/code"/>
      <mkdir dir="docs/serviceobjects/sfsb/code"/>
      <java2html
        srcdir="${src.dir}/trail/sfsb/" destdir="docs/serviceobjects/sfsb/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/sfsb/" destdir="docs/serviceobjects/sfsb/code/" includes="calculator.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- session bean life cycle -->
      <delete dir="docs/serviceobjects/lifecycle/code"/>
      <mkdir dir="docs/serviceobjects/lifecycle/code"/>
      <java2html
        srcdir="${src.dir}/trail/lifecycle/" destdir="docs/serviceobjects/lifecycle/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/lifecycle/" destdir="docs/serviceobjects/lifecycle/code/" includes="calculator.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- JMX -->
      <delete dir="docs/serviceobjects/jmx/code"/>
      <mkdir dir="docs/serviceobjects/jmx/code"/>
      <java2html
        srcdir="${src.dir}/trail/jmx/" destdir="docs/serviceobjects/jmx/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/jmx/" destdir="docs/serviceobjects/jmx/code/" includes="calculator.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- MDB -->
      <delete dir="docs/serviceobjects/mdb/code"/>
      <mkdir dir="docs/serviceobjects/mdb/code"/>
      <java2html
        srcdir="${src.dir}/trail/mdb/" destdir="docs/serviceobjects/mdb/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/mdb/" destdir="docs/serviceobjects/mdb/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- MDPOJO -->
      <delete dir="docs/serviceobjects/mdpojo/code"/>
      <mkdir dir="docs/serviceobjects/mdpojo/code"/>
      <java2html
        srcdir="${src.dir}/trail/mdpojo/" destdir="docs/serviceobjects/mdpojo/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/mdpojo/" destdir="docs/serviceobjects/mdpojo/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Injection -->
      <delete dir="docs/serviceobjects/injection/code"/>
      <mkdir dir="docs/serviceobjects/injection/code"/>
      <java2html
        srcdir="${src.dir}/trail/injection/" destdir="docs/serviceobjects/injection/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/serviceobjects/injection/" destdir="docs/serviceobjects/injection/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- ORM -->
      <delete dir="docs/persistence/orm/code"/>
      <mkdir dir="docs/persistence/orm/code"/>
      <java2html
        srcdir="${src.dir}/trail/entity/beans" destdir="docs/persistence/orm/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- EntityManager Basic -->
      <delete dir="docs/persistence/entitymanager/code"/>
      <mkdir dir="docs/persistence/entitymanager/code"/>
      <java2html
        srcdir="${src.dir}/trail/entity/basic" destdir="docs/persistence/entitymanager/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/persistence/entitymanager/" destdir="docs/persistence/entitymanager/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Entity query -->
      <delete dir="docs/persistence/entityquery/code"/>
      <mkdir dir="docs/persistence/entityquery/code"/>
      <java2html
        srcdir="${src.dir}/trail/entity/query" destdir="docs/persistence/entityquery/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/persistence/entityquery/" destdir="docs/persistence/entityquery/code/" includes="filter.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Update entity -->
      <delete dir="docs/persistence/updateentity/code"/>
      <mkdir dir="docs/persistence/updateentity/code"/>
      <java2html
        srcdir="${src.dir}/trail/entity/update" destdir="docs/persistence/updateentity/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/persistence/updateentity/" destdir="docs/persistence/updateentity/code/" includes="update.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Transaction -->
      <delete dir="docs/services/transaction/code"/>
      <mkdir dir="docs/services/transaction/code"/>
      <java2html
        srcdir="${src.dir}/trail/transaction" destdir="docs/services/transaction/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/services/transaction/" destdir="docs/services/transaction/code/" includes="update.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Application transaction -->
      <delete dir="docs/services/apptrans/code"/>
      <mkdir dir="docs/services/apptrans/code"/>
      <java2html
        srcdir="${src.dir}/trail/apptrans/" destdir="docs/services/apptrans/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/services/apptrans/" destdir="docs/services/apptrans/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Security -->
      <delete dir="docs/services/security/code"/>
      <mkdir dir="docs/services/security/code"/>
      <java2html
        srcdir="${src.dir}/trail/security/" destdir="docs/services/security/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/services/security/" destdir="docs/services/security/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="dd/web/" destdir="docs/services/security/code/" includes="web.xml"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

      <!-- Interceptor -->
      <delete dir="docs/services/interceptor/code"/>
      <mkdir dir="docs/services/interceptor/code"/>
      <java2html
        srcdir="${src.dir}/trail/interceptor/" destdir="docs/services/interceptor/code/" includes="**/*.java"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />
      <java2html
        srcdir="docs/services/interceptor/" destdir="docs/services/interceptor/code/" includes="*.jsp"
        style="eclipse" showLineNumbers="true" showFileName="true" showTableBorder="true"
      />

  </target>


</project>
