<?xml version="1.0"?>

<!--  SPECjAppServer build definitions.

  April 2002 : Modified for SPECjAppServer 2001
  
  April 2001 : Minor Modifications by Tom Daly (Sun)
  
  March 2001 : Thanks to Bill Kayser (Alliare) for creating the initial version of this
	       ant input file and for the documentation accompanying it which has been 
	       incorporated into the README.html

  Please refer to the readme.html for instructions on building and deploying 
  the SPECjAppServer source.

  This file contains targets for compiling and packaging war files and
  ejb files using ant 1.3 or later.

  You can find the ant binaries at http://jakarta.apache.org/ant

  It should not be necessary to edit this file.  

  EXECUTING TARGETS

  To execute a target for a particular appserver such as the reference
  implementation, do this:

  ant -Dappserver=ri.1.3.1 target

  Substitute "ri.1.3.1" for the name of the appserver, such as "tomcat" or 
  "jrun". 

  "ant" should be invoked from the SPECjAppServer top directory ($JAS_HOME)

  SUPPORTED TARGETS

  These are the targets you are most likely to use:

  clean:              Delete all output files
  jAppServer-ear:     Builds all ejb jar files and warfiles needed for 
                      SPECjAppServer, minus the supplier, emulator and driver.
  emulator-ear:       Builds the emulator ear file with the war inside.
  allejbs:	          Builds just the ejb jar files for all deployable ejbs
  clean-driver:	      Removes the driver class files and jar in preparation for 
	                  rebuilding.
  driver:	          Builds the driver.jar file, this must be called explicitly
	                  as it is not part of the default build also driver.jar is not 
	                  removed by the "clean" target
  load:		          builds the load.jar file

  -->

<project name="SPECjAppServer" default="all">

  <!-- This property determines where env and config files will
       be loaded from.  The default is "ri.1.3.1" which means that
       config/ri.1.3.1.env will be loaded and the EJB descriptors will
       be found in src/deploy/ri.1.3.1.  -->

  <property name="appserver" value="sjsas-pe"/>

  <!-- This is the classpath used for compilation.
       If you don't have the j2ee.jar file handy, you
       can substitute it with the individual ext jar
       files if you have them instead.  -->

  
  <!-- Load the external properties.  
       These will override any settings here. -->
  <property file="config/${appserver}.env"/>

   <property name="compile.classpath"
            value="${CLASSPATH}" />
 
  <!-- This uses the JDK1.3 compiler if available.  You may need to set JAVA_HOME. -->
    <property name="build.compiler" value="modern"/> 

    <property name="descriptor-dir" location="src/deploy/${appserver}"/>

    <target name="all" depends="jAppServer-deploy,emulator-ear,load"/>

    <!-- Delete all the targets -->
    <target name="clean">
        <delete dir="./classes/WEB-INF" />
        <mkdir dir="./classes/WEB-INF" />
        <delete>
          <fileset dir="jars/." 
              includes="**/*~,**/*.class,*.zip,**/*.?ar"
	      excludes="ant/lib/*.jar,jars/*chart*.jar,jars/driver.jar,
                        jars/launcher.jar,jars/xercesImpl.jar,
			jars/xmlParserAPIs.jar,jars/jakarta-regexp-1.2.jar,
			jars/load.jar,jars/reporter.jar,jars/*Client.jar"/>
           </delete>
        <!--<delete dir="./classes/*"/>-->
   </target>

    <!-- Compile everything -->
    <target name="compile">
    <echo message="The classpath for compilation is ${compile.classpath}" />
    <echo message="Skipping recompile; prohibited by spec rules" />
    <!--
    <javac srcdir="src"
           deprecation="on"
	   debug="on"
	   destdir="classes"
	   includes="**/*.java"
	   excludes="**/charts*/*"
	   target="1.2"
	   classpath="${compile.classpath}"/>
    -->
    </target>


    <!-- DRIVER clean and REBUILD Targets
 	 It is not expected that the driver will need to be deleted or rebuilt
         but the next 2 targets provide for this should the user explicitly want
	 to do it. So be aware that the "clean" target will not effect the 
	 driver classes or jar, you must use "ant clean-driver" to remove driver files
	 and then "ant driver" to build the new driver

	 The driver target also rebuilds the launcher.jar file which contains the 
	 logic to initiate the driver in a portable fashion.
    -->

    <target name="clean-driver" >
        <delete>
            <fileset dir="." includes="**/driver/*.class, **/jars/driver.jar,
				      **/jars/launcher.jar" />
        </delete>
    </target>

    <target name="driver" depends="compile">
    <rmic base="./classes" includes="**/driver/*Impl.class,**/driver/*Agent.class" 
			   excludes="**/driver/Agent.class" /> 
    <jar jarfile="jars/driver.jar">
        <fileset dir="classes"
               includes="**/driver/*.class,**/driver/http/*.class"/>
    </jar>    
    <jar jarfile="jars/launcher.jar">
        <fileset dir="classes"
               includes="**/launcher/*.class"/>
    </jar></target>


  <!-- Definitions for the names of the descriptor files -->

  <property name="dd.util" value="util.xml"/>
  <property name="dd.corp" value="corp.xml"/>
  <property name="dd.orders" value="orders.xml"/>
  <property name="dd.mfg" value="mfg.xml"/>
  <property name="dd.supp" value="supplier.xml"/>
  <property name="dd.servlet" value="servlet.xml"/>
  <property name="dd.web" value="web.xml"/>
  <property name="dd.application" value="application.xml"/>
  <property name="dd.emu-web" value="emulator-web.xml"/>
  <property name="dd.emu-app" value="emulator-app.xml"/>

  <property name="tmpdir" value="./tmpdir"/>  

  <!-- sunone app server -->
  <property name="dd.util-appserv" value="sun-util.xml"/>
  <property name="dd.corp-appserv" value="sun-corp.xml"/>
  <property name="dd.orders-appserv" value="sun-orders.xml"/>
  <property name="dd.mfg-appserv" value="sun-mfg.xml"/>
  <property name="dd.supp-appserv" value="sun-supplier.xml"/>
  <property name="dd.servlet-appserv" value="sun-servlet.xml"/>
  <property name="dd.web-appserv" value="sun-web.xml"/>
  <property name="dd.application-appserv" value="sun-application.xml"/>
  <property name="dd.emu-web-appserv" value="sun-emulator-web.xml"/>

  <!-- EJB Jar Packaging  -->

  <target name="allejbs" depends="util,corp,orders,mfg,supplier-ejb"/>

  <target name="util" depends="compile">
    <jar jarfile="jars/util.jar">
      <fileset dir="classes"
               includes="**/common/**,**/util/**"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.util}"
                  fullpath="META-INF/ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.util-appserv}"
                  fullpath="META-INF/sun-ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="sun-util-cmp-mappings.xml"
                  fullpath="META-INF/sun-cmp-mappings.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="specjschema.dbschema"
                  fullpath="specjschema.dbschema"/></jar></target>


  <target name="corp" depends="compile">
    <jar jarfile="jars/corp.jar">
      <fileset dir="classes"
               includes="**/common/**,**/ruleengine/**,**/corp/**,**/util/sequenceses/**,**/orders/helper/ShoppingCart.class,**/orders/helper/ShoppingCartDataBean.class"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.corp}"
                  fullpath="META-INF/ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.corp-appserv}"
                  fullpath="META-INF/sun-ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="sun-corp-cmp-mappings.xml"
                  fullpath="META-INF/sun-cmp-mappings.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="specjschema.dbschema"
                  fullpath="specjschema.dbschema"/></jar></target>

  <target name="orders" depends="compile">
    <jar jarfile="jars/orders.jar">
      <fileset dir="classes"
               includes="**/common/**,**/util/sequenceses/**,**/corp/customerent/**,**/corp/customerses/**,**/orders/**"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.orders}"
                  fullpath="META-INF/ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.orders-appserv}"
                  fullpath="META-INF/sun-ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="sun-orders-cmp-mappings.xml"
                  fullpath="META-INF/sun-cmp-mappings.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="specjschema.dbschema"
                  fullpath="specjschema.dbschema"/></jar></target>

  <target name="mfg" depends="compile">
    <jar jarfile="jars/mfg.jar">
      <fileset dir="classes"
               includes="**/common/**,**/util/sequenceses/**,**/mfg/**"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.mfg}"
                  fullpath="META-INF/ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.mfg-appserv}"
                  fullpath="META-INF/sun-ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="sun-mfg-cmp-mappings.xml"
                  fullpath="META-INF/sun-cmp-mappings.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="specjschema.dbschema"
                  fullpath="specjschema.dbschema"/></jar></target>
                  

  <!-- 
    The supplier needs to have the xerces xml parser classes 
    so add xerces.jar in the classpath of the server
  -->

  <target name="supplier-ejb" depends="compile">
    <property name="tmpfile" value="tmp.xml"/>
    <antcall target="process-dd">
      <param name="source-dd" value="${descriptor-dir}/${dd.supp}"/>
      <param name="target-dd" value="${tmpfile}"/></antcall>
	     
    <jar jarfile="jars/supplier.jar">
      <fileset dir="classes"
               includes="**/common/**,**/util/sequenceses/**,**/supplier/**"
               excludes="**/supplier/helper/LogManager.class,
                         **/supplier/web/**,**/supplier/emulator/**"/>
      <zipfileset dir="."
                  includes="${tmpfile}"
                  fullpath="META-INF/ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.supp-appserv}"
                  fullpath="META-INF/sun-ejb-jar.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="sun-supplier-cmp-mappings.xml"
                  fullpath="META-INF/sun-cmp-mappings.xml"/>
      <zipfileset dir="${descriptor-dir}"
                  includes="specjschema.dbschema"
                  fullpath="specjschema.dbschema"/></jar>
                  
    <delete file="${tmpfile}"/></target>

  <!-- This is an ant subroutine.

       This routine should be called with the property source-dd set
       to the deployment descriptor which will be copied to the file
       given by target-dd with the emulator host and port tokens
       substituted.  

       NOTE: This could be done automatically if the tokens
       fit ant token syntax: @token@   Ant does automatic token 
       substitution during <copy>   -->

  <target name="process-dd">
    <property name="tmpfile" location="classes/tmp.xml"/>
    <copy tofile="${target-dd}"
          overwrite="true"
          file="${source-dd}"/>
    <replace file="${target-dd}"
             token="-EMULATOR_HOST-"
	     value="${EMULATOR_HOST}"/>
    <replace file="${target-dd}"
             token="-EMULATOR_PORT-"
	     value="${EMULATOR_PORT}"/>
    <replace file="${target-dd}"
             token="-EMULATOR_PREFIX-"
	     value="${EMULATOR_PREFIX}"/>
    <replace file="${target-dd}"
             token="-JAS_HOST-"
	     value="${JAS_HOST}" />
    <replace file="${target-dd}"
             token="-JAS_PORT-"
	     value="${JAS_PORT}" />
    <replace file="${target-dd}"
             token="-JAS_PREFIX-"
	     value="${JAS_PREFIX}" /></target>

  <!-- Web application archive packaging.
       The web applications consist of the targets:
         
	 supplier-war
	 web-war
	 emulator-war       -->
 
  <target name="supplier-war" depends="compile">
    <war warfile="jars/supplier.war"
         webxml="${descriptor-dir}/${dd.servlet}"
         basedir="src/docroot" includes="dtd/**/*">
      <classes 
         dir="classes" 
         includes="**/common/**,**/supplier/helper/**,
                   **/supplier/web/**"/>
      <!-- vendor specific dd -->
	  <zipfileset dir="${descriptor-dir}"
	                  includes="${dd.servlet-appserv}"
	                  fullpath="WEB-INF/sun-web.xml"/></war></target>


  <target name="web-war" depends="compile">
    <war warfile="jars/web.war"
         webxml="${descriptor-dir}/${dd.web}"
	 basedir="src/docroot">
      <classes 
         dir="classes" 
         includes="**/servlet/**,**/util/**"
	 excludes="**/util/helper/**,**/util/sequenceent/**,**/util/sequenceses/**"/>
      <!-- vendor specific dd -->
	  <zipfileset dir="${descriptor-dir}"
	                  includes="${dd.web-appserv}"
	                  fullpath="WEB-INF/sun-web.xml"/></war></target>


  <!-- 
    The emulator needs to have the xerces xml parser classes 
    so add xerces.jar in the classpath of the server
  -->
  <target name="emulator-war" depends="compile">

    <property name="tmpfile" location="classes/tmp.xml"/>
    <antcall target="process-dd">
      <param name="source-dd" value="${descriptor-dir}/${dd.emu-web}"/>
      <param name="target-dd" value="${tmpfile}"/></antcall>
    <war warfile="jars/emulator.war"
         webxml="${tmpfile}"
	 basedir="src/docroot"
	 includes="dtd/**/*">
      <classes 
         dir="classes" 
         includes="**/common/**,**/supplier/emulator/**,
                   **/jini/**,**/supplier/helper/**"/>
      <!-- vendor specific dd -->
	  <zipfileset dir="${descriptor-dir}"
	                  includes="${dd.emu-web-appserv}"
	                  fullpath="WEB-INF/sun-web.xml"/>
    </war>
    <delete file="${tmpfile}"/></target>

  <!-- Convenience target for building the entire supplier -->
  <target name="supplier" depends="supplier-ejb,supplier-war"/>

  <!-- EAR Files -->
  <target name="jAppServer-ear" depends="util,supplier,web-war,corp,orders,mfg">  
    <mkdir dir="${tmpdir}" />
    <mkdir dir="${tmpdir}/META-INF"/>
    <copy todir="${tmpdir}/META-INF" >
	  <fileset dir="${descriptor-dir}" 
	  includes="${dd.application},${dd.application-appserv}" /> 
    </copy>
    <copy todir="${tmpdir}" >
        <fileset dir="jars"
                 includes="corp.jar,mfg.jar,orders.jar,supplier.jar,util.jar
                           supplier.war,web.war" />
    </copy>
    <jar jarfile="jars/SPECjAppServer.ear" 
         basedir="${tmpdir}">
    </jar>
    <delete dir="${tmpdir}" />
  </target>

  <target name="emulator-ear" depends="emulator-war">
    <zip zipfile="jars/emulator.ear"
         basedir="jars"
	 includes="emulator.war">
      <zipfileset dir="${descriptor-dir}"
                  includes="${dd.emu-app}"
		  fullpath="META-INF/application.xml"/></zip>
  </target>
  
  <target name="jAppServer-deploy" depends="jAppServer-ear">
	  <echo message="deploying ear file " />
	  <copy todir="${J2EE_HOME}/domains/spec2004-1/autodeploy" 
		  overwrite="true" file="jars/SPECjAppServer.ear" />
  </target>

  <target name="load" depends="compile">
    <jar jarfile="jars/load.jar"
         basedir="classes"
         includes="org/spec/jappserver/load/**/*.class"/></target>
    
  <!-- Compile charts -->
  <target name="compile-charts">
    <echo message="The classpath for compilation is ${compile.classpath}:jars/jcchart450K.jar" />
    <javac srcdir="src"
           deprecation="on"
	   debug="on"
	   destdir="classes"
	   includes="**/charts*/*"
	   target="1.2"
	   classpath="${compile.classpath}:jars/jcchart450K.jar"/>
  </target>

  <target name="charts" depends="compile-charts">
    <jar jarfile="jars/charts.jar"
         basedir="classes"
         includes="org/spec/jappserver/charts/*.class"/>
  </target>

</project>
