<?xml version="1.0"?>

<!--

Build file for `AddressBook', a sample J2EE application that contains a
Container-Managed Persistent Entity Bean.

See:

   http://www.jollem.com/orion-cmp-primer/

Version: $Revision: 1.1 $ $Date: 2005/02/08 10:10:55 $
Author:  Ernst de Haan

-->

<project name="addressbook" default="all" basedir=".">

   <!-- ***************************************************************** -->
   <!-- INITIALIZATION AND CLEANUP                                        -->
   <!-- ***************************************************************** -->


   <!-- Initialization needed for any target -->

   <target name="init">
      <property name="name" value="addressbook" />
      <property name="src.dir" value="src" />
      <property name="lib.dir" value="lib" />
      <property name="etc.dir" value="etc" />
      <property name="build.dir" value="build" />
      <property name="orion.dir" value="/usr/local/orion1.5.2" />
      <property name="build.compiler" value="classic" />
   </target>


   <!-- Removes all generated files and directories -->

   <target name="clean" depends="init">
      <deltree dir="${lib.dir}" />
      <deltree dir="${build.dir}" />
   </target>


   <!-- Prepares any other build target by creating the expected directory
        structure. -->

   <target name="prepare" depends="init">
      <mkdir dir="${lib.dir}" />
      <mkdir dir="${lib.dir}/ejb" />
      <mkdir dir="${lib.dir}/ejb/META-INF" />
      <mkdir dir="${lib.dir}/web" />
      <mkdir dir="${lib.dir}/web/WEB-INF" />
      <mkdir dir="${lib.dir}/web/WEB-INF/classes" />
      <mkdir dir="${lib.dir}/j2ee" />
      <mkdir dir="${lib.dir}/META-INF" />
      <mkdir dir="${build.dir}" />
   </target>


   <!-- ***************************************************************** -->
   <!-- THE EJB APPLICATION                                               -->
   <!-- ***************************************************************** -->


   <!-- Compiles the classes and interfaces for the entity bean. -->

   <target name="ejb-classes" depends="prepare">
      <javac srcdir="${src.dir}/java"
             destdir="${lib.dir}/ejb"
             includes="${name}/ejb/**"
             classpath="${orion.dir}/ejb.jar" />
   </target>


   <!-- Copies the deployment descriptor for the entity bean from the etc
        directory to the correct META-INF directory beneath lib -->

   <target name="ejb-descriptor" depends="prepare">
      <copyfile src="${etc.dir}/ejb-jar.xml"
                dest="${lib.dir}/ejb/META-INF/ejb-jar.xml" />
   </target>


   <!-- Creates the JAR that contains the compiled entity bean, related
        classes and interfaces, and the deployment descriptor -->

   <target name="ejb-jar" depends="ejb-classes,ejb-descriptor">
      <jar jarfile="${build.dir}/${name}-ejb.jar"
           basedir="${lib.dir}/ejb" />
   </target>


   <!-- ***************************************************************** -->
   <!-- THE WEB APPLICATION                                               -->
   <!-- ***************************************************************** -->

   <!-- Copies the JSPs from the src directory to the lib directory -->

   <target name="jsp" depends="prepare">
      <copydir src="${src.dir}/jsp"
               dest="${lib.dir}/web" />
   </target>


   <!-- Copies the HTML files to be included in the website from the src
        directory to the lib directory -->

   <target name="html" depends="prepare">
      <copydir src="${src.dir}/web"
               dest="${lib.dir}/web" />
   </target>


   <!-- Copies the deployment descriptor for the web application from the etc
        directory to the lib directory -->

   <target name="web-descriptor" depends="prepare">
      <copyfile src="${etc.dir}/web.xml"
                dest="${lib.dir}/web/WEB-INF/web.xml" />
   </target>


   <!-- Creates the WAR file that contains the JSP and HTML files, and the
        deployment descriptor for the web application -->

   <target name="web-war" depends="jsp,html,web-descriptor">
      <jar jarfile="${build.dir}/${name}-web.war"
           basedir="${lib.dir}/web" />
   </target>


   <!-- ***************************************************************** -->
   <!-- THE COMPLETE J2EE APPLICATION                                     -->
   <!-- ***************************************************************** -->


   <!-- Copies the J2EE application descriptor from the etc directory to the
        lib directory -->

   <target name="j2ee-descriptor" depends="prepare">
      <copyfile src="${etc.dir}/application.xml"
                dest="${lib.dir}/j2ee/META-INF/application.xml" />
   </target>

   <!-- Creates the EAR file that contains both the EJB application and the
        web application -->

   <target name="j2ee-ear" depends="ejb-jar,web-war,j2ee-descriptor">
      <copyfile src="${build.dir}/${name}-ejb.jar"
                dest="${lib.dir}/j2ee/${name}-ejb.jar" />
      <copyfile src="${build.dir}/${name}-web.war"
                dest="${lib.dir}/j2ee/${name}-web.war" />
      <jar jarfile="${build.dir}/${name}.ear"
           basedir="${lib.dir}/j2ee" />
   </target>

   <target name="all" depends="j2ee-ear" />

</project>
