<?xml version="1.0"?>

<!-- ===================================================================
     This file builds a runnable application wrapped up as a zip file.
     Unpacking the zip should result in a directory containing a shell
     script, a set of jars and any other resources needed.

     Properties we need:
       app.core.env.pname     core properties source
       app.run.shellscr       location of the skeleton shell script.
       app.run.jar.file       application jar file
       app.run.main.class     main class for application.

     Authors: Mike Douglass   douglm rpi.edu
     =================================================================== -->

<project name="bw.buildsh" default="build">
  <import file="${build.dir}/buildfilters.xml" />

  <import file="${build.dir}/platforms/${org.bedework.global.deploy.platform}Service.xml" />

  <target name="init">
    <!-- Destinations - where we build stuff -->
    <property name="app.dest.home"
              location="${org.bedework.temp.shellscr.home}/${propval.app.zip.name}" />
    <property name="app.dest.lib"
              location="${app.dest.home}/lib" />
    <property name="app.dest.classes"
              location="${app.dest.home}/classes" />
    <property name="app.dest.properties"
              location="${app.dest.classes}/properties/${org.bedework.deployment.name}" />
    <property name="app.dest.data"
              location="${app.dest.home}/data" />

    <property name="app.zip.file"
              location="${dist.home}/${propval.app.zip.name}.zip" />
  </target>

  <!-- ================================================================
       build target
       ================================================================ -->

  <target name="build" depends="init">
    <infoMsg message="* =========== Building ${propval.app.zip.name}" />

    <delete dir="${app.dest.home}" />

    <!-- Library stuff -->

    <mkdir dir="${app.dest.lib}" />

    <!-- Platform specific -->
    <antcall target="addLibs" inheritRefs="true" />

    <if>
      <isset property="org.bedework.sou.hibernate.properties" />
      <then>
        <if>
          <istrue value="${org.bedework.build.debug}" />
          <then>
            <echo message="************* Copy hib properties from ${org.bedework.sou.hibernate.properties}" />
          </then>
        </if>
        <copy todir="${app.dest.classes}">
          <fileset dir="${org.bedework.sou.hibernate.properties}/properties" />
          <filterset refid="property.filters" />
        </copy>
    
        <copy todir="${app.dest.classes}">
          <fileset dir="${org.bedework.sou.hibernate.properties}/hbms" />
          <filterset refid="property.filters" />
        </copy>
      </then>
    </if>

    <copy tofile="${app.dest.classes}/sysevents.properties"
          file="${org.bedework.config.sysevents.properties}" />

    <if>
      <isreference refid="org.bedework.extra.resources" />
      <then>
        <copy todir="${app.dest.classes}" overwrite="yes" >
          <fileset refid="org.bedework.extra.resources" />
          <filterset refid="property.filters" />
        </copy>
      </then>
    </if>

    <!-- Platform specific hibernate properties -->
    <antcall target="doHibProps" inheritRefs="true" />

    <!-- Create the env.properties file -->
    <mkdir dir="${app.dest.properties}" />

    <copy tofile="${app.dest.properties}/options.xml"
          file="${org.bedework.config.options}" >
      <filterset>
        <filter token="RPI-DEBUG" value="${app.debug.val}"/>
      </filterset>
      <filterset refid="property.filters" />
    </copy>

    <!-- ===============================================================
                       Add any resource files
         =============================================================== -->

    <!-- Platform specific -->
    <antcall target="addResources" inheritRefs="true" />

    <!-- ===============================================================
                       Add any data files
         =============================================================== -->

    <if>
      <istrue value="${org.bedework.shellscr.copy.data}" />
      <then>
        <mkdir dir="${app.dest.data}" />
    
        <copy todir="${app.dest.data}" overwrite="yes" >
          <fileset refid="org.bedework.shellscr.data" />
          <filterset refid="property.filters" />
        </copy>
      </then>
    </if>

    <!-- ===============================================================
                       Add any extra stuff
         =============================================================== -->

    <!-- Platform specific -->
    <antcall target="addExtras" inheritRefs="true" />
    
    <!-- ================================================================
         Build the zip file
         ================================================================ -->

    <mkdir dir="${dist.home}" />
    <delete file="${app.zip.file}" />

    <zip destfile="${app.zip.file}" >
      <zipfileset prefix="${propval.app.zip.name}" dir="${app.dest.home}" />
    </zip>
  </target>
</project>
