<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
    <!ENTITY common SYSTEM "file:./common.xml">
]>

<!-- 
     This is the build file for the FAQApp application. The default target
     for the build is "all".
 -->
<project name="FAQApp" default="all" basedir=".">

   <!-- 
        Include the ./common.xml file. The common.xml file contains a common 
        set of properties and the common classpath which are required to 
        enable this application to be built. 
        Please review common.xml for more details.  
   -->
   &common;
   
   <!-- Sets the properties for the build process -->
   <target name="init" depends="common">
      <property name="app.name" value="FAQApp" />
      <property name="ear.name" value="${app.name}" />
      <property name="ejb.name" value="${ear.name}EJB" />
      <property name="web.name" value="${ear.name}Web" />
      <property name="ws.name" value="${ear.name}WebService" />
      <property name="bld.dir" value="./build" />
      <property name="dist.dir" value="./dist" />
      <property name="etc.dir" value="./etc" />
      <property name="lib.dir" value="./lib" />
      <property name="sql.dir" value="./sql" />
      <property name="doc.dir" value="./doc" />
      <property name="doc.images.dir" value="./doc/images" />
      <property name="src.ejb.dir" value="./src/ejb" />
      <property name="src.web.dir" value="./src/web/faqapp-web" />
      <property name="src.ws.dir" value="./src/web/faqws-web" />
      <property name="src.images.dir" value="${src.web.dir}/images" />
      <property name="bld.ear.dir" value="${bld.dir}/${ear.name}" />
      <property name="bld.ejb.dir" value="${bld.ear.dir}/${ejb.name}" />
      <property name="bld.web.dir" value="${bld.ear.dir}/${web.name}" />
      <property name="bld.ws.dir" value="${bld.ear.dir}/${ws.name}" />
      <property name="bld.images.dir" value="${bld.ear.dir}/${web.name}/images" />
      <property name="tmp.dir" value="./tmp" />
      <property name="bld.compiler" value="classic" />
      <property name="class.files" value="**/*.class" />
      <property name="bak.files" value="**/*~" />
      <property name="ade.path" value="**/.ade_path/**"/>
      <property name="ade.save" value="**/*#save*/**"/>
      <property name="ade.files" value="${ade.path}, ${ade.save}"/>
      <!-- 
          The deploy.* properties are used to perform the deployment operation
          to an OC4J standalone instance. Please ensure the details are
          correct for your specific environment.
      -->
      <property name="deploy.ormi" value="ormi://localhost" />
      <property name="deploy.username" value="admin" />
      <property name="deploy.password" value="welcome" />
   </target>

   <!-- Cleans the build environment -->    
   <target name="clean" depends="init">
      <delete dir="${bld.dir}" />
      <delete dir="${dist.dir}" />
      <delete>
         <fileset dir="." includes="${bak.files}" defaultexcludes="no"/>
      </delete>
   </target>

   <!-- Sets up the build environment, creates required directories -->
   <target name="setup" depends="init">
      <mkdir dir="${dist.dir}" />
      <mkdir dir="${bld.dir}" />
      <mkdir dir="${bld.ear.dir}" />
      <mkdir dir="${bld.ear.dir}/META-INF" />
      <mkdir dir="${bld.ejb.dir}/META-INF" />
      <mkdir dir="${bld.ws.dir}/WEB-INF" />
      <mkdir dir="${bld.web.dir}/WEB-INF/classes" />
      <mkdir dir="${bld.web.dir}/WEB-INF/lib" />
      <mkdir dir="${bld.images.dir}" />
   </target>

   <!-- Compiles the EJB classes, uses the common.class.path property  -->
   <target name="ejb-classes" depends="setup">
      <javac srcdir="${src.ejb.dir}"
             destdir="${bld.ejb.dir}"
             excludes="${ade.files}"
             debug="on">
         <classpath>
            <pathelement path="${common.class.path}" />
            <pathelement location="${bld.ejb.dir}" />
            <pathelement location="${dist.dir}/${ejb.name}.jar" />
         </classpath>
      </javac>
   </target>

   <!-- Copies the EJB deployment descriptors into the build area -->
   <target name="ejb-descriptor" depends="setup">
      <copy todir="${bld.ejb.dir}/META-INF">
         <fileset dir="${etc.dir}" includes="ejb-jar.xml, orion-ejb-jar.xml"/>
      </copy>
   </target>

   <!-- Packages the EJB classes and descriptors into a JAR file -->
   <target name="ejb-jar" depends="ejb-classes,ejb-descriptor">
      <jar jarfile="${dist.dir}/${ejb.name}.jar">
         <fileset dir="${bld.ejb.dir}" includes="**" />
      </jar>
   </target>

   <!-- 
       Compiles the Web classes, uses common.class.path, the Struts library,
       and the EJB classes.
    -->
   <target name="web-classes" depends="setup, ejb-jar">
      <javac srcdir="${src.web.dir}"
             destdir="${bld.web.dir}/WEB-INF/classes"
             excludes="${ade.files}"
             debug="on">
         <classpath>
            <pathelement path="${common.class.path}" />
            <pathelement location="${bld.web.dir}" />
            <pathelement location="${dist.dir}/${ejb.name}.jar" />
            <pathelement location="${lib.dir}/struts.jar"/>
         </classpath>
      </javac>
      <copy todir="${bld.web.dir}/WEB-INF/classes">
         <fileset dir="${src.web.dir}/etc" includes="ApplicationResources.properties"/>
      </copy>
   </target>

   <!-- Copies any additional libraries into the build area -->
   <target name="web-libraries" depends="setup">
      <copy todir="${bld.web.dir}/WEB-INF/lib">
         <fileset dir="${lib.dir}" includes="*.jar" />
      </copy>
   </target>

   <!-- Copies the static resources into the build area -->
   <target name="web-html" depends="setup">
      <copy todir="${bld.web.dir}">
         <fileset dir="${src.web.dir}" includes="*.html, *.css" />
         <fileset dir="${doc.dir}" includes="*.html, *.css" />
         <fileset dir="${sql.dir}" includes="*.sql" />
      </copy>
   </target>

   <!-- Copies the images into the build area -->
   <target name="web-images" depends="setup">
      <copy todir="${bld.images.dir}">
         <fileset dir="${src.images.dir}" includes="*.gif, *.bmp, *.jpg" />
         <fileset dir="${doc.images.dir}" includes="*.gif, *.bmp, *.jpg" />
      </copy>
   </target>

    <!-- Copies the JSP pages into the build area -->
   <target name="web-jsp" depends="setup">
      <copy todir="${bld.web.dir}">
         <fileset dir="${src.web.dir}/jsp" includes="*.jsp" />
      </copy>
   </target>

   <!-- Copies the deployment descriptor files into the build area -->
   <target name="web-descriptor" depends="setup">
      <copy todir="${bld.web.dir}/WEB-INF">
         <fileset dir="${src.web.dir}/etc" includes="web.xml, orion-web.xml, struts-config.xml, *.tld"/>
      </copy>
   </target>

   <!-- Packages the Web application into a WAR file -->
   <target name="web-war" depends="web-libraries, web-classes,web-html,web-images,web-jsp,web-descriptor">
      <jar jarfile="${dist.dir}/${web.name}.war">
         <fileset dir="${bld.web.dir}" includes="**" />
      </jar>
   </target>

   <!-- 
        Copies the static resources for the Web Service into 
        the build area 
   -->
   <target name="ws-html" depends="setup">
      <copy todir="${bld.ws.dir}">
         <fileset dir="${src.ws.dir}" includes="*.html, *.css" />
      </copy>
   </target>

   <!-- Copies the Web Service deployment descriptors into the build area -->
   <target name="ws-descriptor" depends="setup">
      <copy todir="${bld.ws.dir}/WEB-INF">
         <fileset dir="${src.ws.dir}/etc" includes="web.xml, orion-web.xml, *.tld"/>
      </copy>
   </target>

   <!-- Packages the Web Service into a WAR file -->
   <target name="ws-war" depends="ws-html,ws-descriptor">
      <jar jarfile="${dist.dir}/${ws.name}.war">
         <fileset dir="${bld.ws.dir}" includes="**" />
      </jar>
   </target>

   <!-- 
       Copies the J2EE Application deployment descriptors and the default
       security data file into the build area
    -->
   <target name="j2ee-descriptor" depends="setup">
      <copy todir="${bld.ear.dir}/META-INF">
         <fileset dir="${etc.dir}" includes="application.xml,
                                             orion-application.xml,
                                             jazn-data.xml"/>
      </copy>
   </target>

   <!-- 
        Creates a J2EE Application EAR file containing the archives that have 
        been generated for the EJB, Web and Web Service components
    -->
   <target name="j2ee-ear" depends="ejb-jar,web-war,ws-war,j2ee-descriptor">
      <jar jarfile="${dist.dir}/${ear.name}.ear">
         <fileset dir="${dist.dir}" includes="${ejb.name}.jar" />
         <fileset dir="${dist.dir}" includes="${web.name}.war" />
         <fileset dir="${dist.dir}" includes="${ws.name}.war" />
         <fileset dir="${bld.ear.dir}" includes="META-INF/*.xml" />
      </jar>
   </target>

   <!--
        The default target for this build file. A successful execution
         will result in the construction of the deployable EAR file for 
         this application
   -->
   <target name="all" depends="j2ee-ear" />

   <!-- The main deployment target, will deploy all components -->
   <target name="deploy" depends="deploy-ear,bind-web-app, bind-web-app-ws"/>

   <!-- 
        Deploys the EAR file to a standalone OC4J container instance. 
        This target uses the command line admin.jar utility provided
        with OC4J to deploy the EAR file. This can be used to deploy
        to a local or a remote instance. The details on which host to 
        deploy to and the corresponding administrator username and 
        password are obtained via the deploy.* properties set in the
        init target.
   -->
   <target name="deploy-ear" depends="j2ee-ear">
     <java jar="${J2EE_HOME}/admin.jar" fork="yes">
       <arg value="${deploy.ormi}" />
       <arg value="${deploy.username}" />
       <arg value="${deploy.password}" />
       <arg value="-deploy" />
       <arg value="-file" />
       <arg value="${dist.dir}/${app.name}.ear" />
       <arg value="-deploymentName" />
       <arg value="${app.name}" />
     </java>
   </target>

   <!--
       Binds the Web module contained in the application EAR file 
       to a URI context on the target OC4J standalone container instance.
       The URI context will be set to the value of the app.name property,
       which by default is FAQApp. This uses the command line admin.jar
       utility of OC4J and the deploy.* properties.
   -->
   <target name="bind-web-app" depends="deploy-ear">
     <java jar="${J2EE_HOME}/admin.jar" fork="yes">
       <arg value="${deploy.ormi}" />
       <arg value="${deploy.username}" />
       <arg value="${deploy.password}" />
       <arg value="-bindWebApp" />
       <arg value="${app.name}" />
       <arg value="${web.name}" />
       <arg value="http-web-site" />
       <arg value="/${app.name}" />
     </java>
   </target>

   <!-- 
       Binds the Web Services module contained in the EAR file to the 
       URI context of ws.name
   -->
   <target name="bind-web-app-ws" depends="deploy-ear">
     <java jar="${J2EE_HOME}/admin.jar" fork="yes">
       <arg value="${deploy.ormi}" />
       <arg value="${deploy.username}" />
       <arg value="${deploy.password}" />
       <arg value="-bindWebApp" />
       <arg value="${app.name}" />
       <arg value="${ws.name}" />
       <arg value="http-web-site" />
       <arg value="/${ws.name}" />
     </java>
   </target>

   <!-- Undeploys the application from the target OC4J container instance -->
   <target name="undeploy" depends="init">
     <java jar="${J2EE_HOME}/admin.jar" fork="yes">
       <arg value="${deploy.ormi}" />
       <arg value="${deploy.username}" />
       <arg value="${deploy.password}" />
       <arg value="-undeploy" />
       <arg value="${app.name}" />
     </java>
   </target>

</project>






