<project name="jivo" default="compile" basedir=".">

  <property name="app.name"      value="jivo"/>
  <property name="app.version"   value="1.0"/>
  <property name="build.home"    value="build/java"/>
  <property name="deploy.home"   value="deploy"/>
  <property name="compile.debug"   value="true"/>
  <property name="javadoc.home"   value="${doc.root}/api"/>

  <property file="/etc/benow/build.properties"/>
  <property file="etc/build.properties"/>


  <path id="compile.classpath">

    <!-- Include all needed jars -->
    <fileset dir="${lib.home}">
      <include name="*.jar"/>
    </fileset>

    <fileset dir="${lib.home}\linux\amd64">
      <include name="*.jar"/>
    </fileset>

    <fileset dir="${lib.home}\linux\i386">
      <include name="*.jar"/>
    </fileset>

    <fileset dir="${lib.home}\win32">
      <include name="*.jar"/>
    </fileset>

    <pathelement path="${build.home}"/>

  </path>

  <target name="all" depends="dist"
   description="Clean build and dist, then compile"/>

  <target name="clean"
   description="Delete old build directories">
    <delete dir="${build.home}" quiet="yes"/>
    <delete quiet="yes">
      <fileset dir="." includes="**/*~*" defaultexcludes="no"/>
      <fileset dir="." includes="**/*.log.*" defaultexcludes="no"/>
    </delete>

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

    <delete quiet="yes" includeEmptyDirs="true">
      <fileset dir="rmi_deploy" includes="**/*" defaultexcludes="no"/>
    </delete>
    
  </target>

  <target name="compile" 
   description="Compile Java sources">
    <mkdir dir="${build.home}"/>

    <javac srcdir="src/java"
          destdir="${build.home}"
           debug="${compile.debug}"
        deprecation="${compile.deprecation}"

        optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
    </javac>

<!-- copy castor settings.  indent on can cause problems on remote video page
    <copy todir="${build.home}" file="etc/castor.properties"/>
-->

  </target>

  <target name="dist" depends="clean,compile,jar"
   description="Create binary distribution">

    <mkdir dir="${dist.home}"/>

    <mkdir     dir="${dist.home}/ext"/>
  </target>

  <target name="jar" depends="compile"
   description="Create binary distribution">
  	
    <delete file="${app.name}.jar" failonerror="false"/>
    <mkdir dir="${lib.home}/t"/>
    <copy todir="${lib.home}/t">
      <fileset dir="${build.home}"/>
    </copy>
    <java classname="org.benow.java.packager.Packager" fork="true">
      <classpath refid="compile.classpath"/>
      <arg value="--output"/>
      <arg value="${lib.home}/t"/>
      <arg value="--file-exclude"/>
      <arg value="var/pkg,var/cache"/>
    </java>
    <jar jarfile="${app.name}.jar" basedir="${lib.home}/t"/>
    <delete dir="${lib.home}/t"/>

    <!-- create applet  jar
    <jar jarfile="html/classes/xsl.jar" basedir="${build.home}" includes="ca/reachable/web/client/**,ca/reachable/tv/Jivo**" manifest="${build.home}/META-INF/MANIFEST.MF"/>
 -->
  </target>

  <target name="setup">
    <java classname="org.benow.Launcher" fork="true">
      <classpath>
          <fileset dir="lib/java">
            <include name="*.jar"/>
          </fileset>
          <fileset file="${app.name}.jar"/>
       </classpath>
      <arg value="--make-script"/>
    </java>
  </target>


  <target name="javadoc" depends="compile"
   description="Create Javadoc API documentation">

    <delete dir="${doc.root}/api"/>
    <mkdir          dir="${doc.root}/api"/>
    <javadoc sourcepath="src/java"
                destdir="${doc.root}/api"
            windowtitle="${app.name} Documentation"
               doctitle="${app.name} Documentation"
           packagenames="com.*,test.*,org.*">
      <link href="http://benow.ca/docs/jdk1.4/api/"/>
      <link href="http://benow.ca/docs/xalan-j_2_0_D5/"/>
      <link href="http://benow.ca/docs/xerces-1_2_3/"/>
      <link href="http://benow.ca/docs/xerces-1_2_3/"/>
      <link href="http://benow.ca/docs/jsdk2.2b/"/>
      <classpath refid="compile.classpath"/>
    </javadoc> 
  </target>

	<target name="restart" depends="jar">
	    <exec executable="sudo">
		      <arg value="/etc/init.d/jivo"/>
	      <arg value="restart"/>
	    </exec>
	</target>
	
  <target name="pillow_fight" 
   description="Make webapp">

   <mkdir dir="wart/WEB-INF"/>

   <copy todir="wart/WEB-INF">
     <fileset dir=".">
       <exclude name="html/**"/>
       <exclude name="classes/**"/>
       <exclude name="database/**"/>
       <exclude name="deploy/**"/>
     </fileset>
   </copy>

   <mkdir dir="wart/WEB-INF/database"/>

   <copy todir="wart/WEB-INF/classes">
    <fileset dir="build/java"/>
   </copy>

   <copy todir="wart/">
    <fileset dir="html"/>
   </copy>

   <jar jarfile="jivo.war" basedir="wart"/>

   <delete dir="wart"/>
  </target>

</project>



