<!-- build configuration -->
<project name="robodj" default="compile" basedir=".">

  <!-- import properties -->
  <property file="build.properties"/>

  <!-- things you may want to change -->
  <property name="app.name"       value="robodj"/>
  <property name="build.compiler" value="jikes"/>
  <property name="web.home"       value="/export/samskivert/pages/code"/>
  <property name="install.dir"    value="${web.home}/${app.name}"/>
  <property name="narya.home"     value="../../work/narya"/>

  <!-- things you probably don't want to change -->
  <property name="src.dir"          value="src/java"/>
  <property name="deploy.dir"       value="dist"/>
  <property name="dist.jar"         value="${app.name}.jar"/>
  <property name="javadoc.dir"      value="${deploy.dir}/docs"/>
  <property name="doc.packages"     value="robodj.*"/>
  <property name="doc.overview"     value="robodj/overview.html"/>
  <property name="nartool.path"     value="${narya.home}/bin"/>
  <property name="classes.dir"      value="${deploy.dir}/classes"/>

  <!-- declare our classpath -->
  <path id="classpath">
    <fileset dir="lib" includesfile="lib/CLIENT_LIBS"/>
    <pathelement location="${classes.dir}"/>
  </path>

  <!-- generates .java files for all .dobj files -->
  <target name="gendobj">
    <apply executable="${nartool.path}/gendobj"
      failonerror="true" parallel="true">
      <srcfile/>
      <fileset dir="src/java" includes="**/*.dobj"/>
    </apply>
  </target>

  <!-- generates marshaller and dispatcher classes for all invocation -->
  <!-- service declarations -->
  <target name="genservice">
    <!-- make sure the service class files are all compiled -->
    <javac srcdir="src/java" destdir="${classes.dir}"
           debug="on" optimize="${build.optimize}" deprecation="on">
      <classpath refid="classpath"/>
      <include name="**/*Service.java"/>
    </javac>
    <apply executable="${nartool.path}/genservice"
      failonerror="true" parallel="true">
      <arg value="--classpath"/>
      <arg value="${classes.dir}:lib/narya-distrib.jar:lib/narya-base.jar"/>
      <arg value="--sourcedir"/>
      <arg value="src/java"/>
      <fileset dir="src/java" includes="**/*Service.java"/>
    </apply>
  </target>

  <!-- prepares the application directories -->
  <target name="prepare" depends="gendobj">
    <mkdir dir="${deploy.dir}"/>
    <mkdir dir="${classes.dir}"/>
    <mkdir dir="${javadoc.dir}"/>
    <!-- copy media and properties into the target directory -->
    <copy todir="${classes.dir}">
      <fileset dir="${src.dir}" includes="**/*.jpg"/>
      <fileset dir="${src.dir}" includes="**/*.png"/>
      <fileset dir="${src.dir}" includes="**/*.properties"/>
    </copy>
  </target>

  <!-- cleans out the built application -->
  <target name="clean">
    <delete dir="${deploy.dir}"/>
  </target>

  <!-- cleans out the installed application -->
  <target name="purge" depends="clean">
    <delete dir="${install.dir}"/>
  </target>

  <!-- build the java class files -->
  <target name="compile" depends="prepare">
    <javac srcdir="${src.dir}" destdir="${classes.dir}"
           debug="on" optimize="off" deprecation="off">
      <classpath refid="classpath"/>
    </javac>
  </target>

  <!-- build the javadoc documentation -->
  <target name="javadoc" depends="prepare">
    <javadoc sourcepath="${src.dir}"
             packagenames="${doc.packages}"
             windowtitle="${app.name} API"
             doctitle="${app.name} API"
             overview="${src.dir}/${doc.overview}"
             destdir="${javadoc.dir}">
      <classpath refid="classpath"/>
      <link href="http://www.waywardgeeks.org/code/samskivert/javadoc"/>
      <link href="http://java.sun.com/products/jdk/1.3/docs/api"/>
    </javadoc>
  </target>

  <!-- a target for rebuilding everything -->
  <target name="all" depends="clean,prepare,compile,javadoc,dist"/>

  <!-- builds our distribution files (war and jar) -->
  <target name="dist" depends="prepare,compile">
    <jar destfile="${deploy.dir}/${dist.jar}"
         basedir="${classes.dir}"/>
  </target>

  <!-- installs the JWS app -->
  <target name="install" depends="dist">
    <mkdir dir="${install.dir}"/>
    <!-- copy the jar files used by the client -->
    <copy todir="${install.dir}">
      <fileset dir="lib" includesfile="lib/CLIENT_LIBS"/>
      <fileset dir="dist" includes="*.jar"/>
    </copy>
    <!-- sign the jar files -->
    <signjar keystore="${sign.keystore}" alias="${sign.alias}"
      storepass="${sign.storepass}" lazy="true">
      <fileset dir="${install.dir}" includes="*.jar"/>
    </signjar>
    <!-- copy the jnlp file(s) and associated business into place -->
    <filter filtersfile="build.properties"/>
    <copy todir="${install.dir}" filtering="true">
      <fileset dir="etc" includes="**/*.jnlp"/>
    </copy>
    <copy todir="${install.dir}">
      <fileset dir="etc" includes="**/*.png"/>
    </copy>
  </target>

  <!-- mirrors the files to the production web server -->
  <target name="mirror" depends="install">
    <echo message="Mirroring files to ${musicd_host}..."/>
    <apply executable="rsync" parallel="true">
      <fileset dir="${install.dir}" includes="**"/>
      <arg line="-av"/>
      <srcfile/>
      <arg line="${musicd_host}:${install.dir}"/>
    </apply>
  </target>
</project>
