<!--

  Ant Buildfile for MOA SL
  
  Authors: Gregor Karlinger

  $Id$

-->
<project name="moa-sl" default="dist-ws" basedir=".">
  <property environment="env"/>

	<!-- Remove comments if targets should be run in test mode, i.e. include test files -->
	<!--<property name="isTest" value="dummy"/>-->
	
	<property name="version" value="1.1.1"/>

  <property name="lib" value="lib"/>
  <property name="src" value="src"/>
  <property name="res" value="res"/>
  <property name="web-inf" value="WEB-INF"/>
  <property name="pages" value="pages"/>
  <property name="handbook" value="handbook"/>
  <property name="conf" value="conf"/>
  <property name="test" value="test"/>
  <property name="tempdir" value="workdir/temp"/>

  <property name="tmp" value="tmp"/>
  <property name="compile" value="${tmp}/compile"/>
  <property name="api-doc" value="${tmp}/api-doc"/>
  <property name="dist" value="${tmp}/dist"/>
  <property name="dist.ws" value="${dist}/ws"/>
  <property name="dist.ws.conf" value="${dist.ws}/conf"/>
  <property name="dist.ws-zip" value="${dist}/ws-zip"/>
  <property name="dist.src" value="${dist}/src"/>
  <property name="dist.src-zip" value="${dist}/src-zip"/>

  <property name="lib.axis" value="${lib}/axis-1.0"/>
  <property name="lib.commons-discovery" value="${lib}/commons-discovery-0.2"/>
  <property name="lib.commons-fileupload" value="${lib}/commons-fileupload-1.0"/>
  <property name="lib.commons-logging" value="${lib}/commons-logging-1.0.4"/>
  <property name="lib.log4j" value="${lib}/log4j-1.2.7"/>
  <property name="lib.servlet" value="${lib}/servlet-2.3"/>
  <property name="lib.xalan" value="${lib}/xalan-2.5.1"/>
  <property name="lib.xerces" value="${lib}/xerces-2.6.2"/>

  <path id="compile.classpath">
    <pathelement location="${lib.axis}/axis.jar"/>
    <pathelement location="${lib.axis}/jaxrpc.jar"/>
    <pathelement location="${lib.axis}/saaj.jar"/>
    <pathelement location="${lib.commons-logging}/commons-logging-api.jar"/>
    <pathelement location="${lib.commons-fileupload}/commons-fileupload-1.0.jar"/>
    <pathelement location="${lib.commons-discovery}/commons-discovery.jar"/>
    <pathelement location="${lib.log4j}/log4j-1.2.7.jar"/>
    <pathelement location="${lib.servlet}/servlet-2_3-fcs-classfiles.zip"/>
    <pathelement location="${lib.xalan}/xalan.jar"/>
    <pathelement location="${lib.xerces}/xmlParserAPIs.jar"/>
    <pathelement location="${lib.xerces}/xercesImpl.jar"/>
  </path>
  
  <target name="init">
    <description>set up directories etc.</description>
    <tstamp/>
    <mkdir dir="${tmp}"/>
    <mkdir dir="${compile}"/>
    <mkdir dir="${api-doc}"/>
  	<mkdir dir="${handbook}"/>
    <mkdir dir="${dist}"/>
    <mkdir dir="${dist.ws}"/>
    <mkdir dir="${dist.ws-zip}"/>
    <mkdir dir="${dist.src}"/>
    <mkdir dir="${dist.src-zip}"/>
  </target>
  
  <target name="compile" depends="init">
    <description>compile everything</description>
    <javac srcdir="${src}" destdir="${compile}"
           classpathref="compile.classpath" 
           debug="on">
    </javac>
  </target>

  <target name="package-ws" depends="compile, manifest">
    <description>package the server war file</description>
    <war warfile="${dist.ws}/moa-sl.war" webxml="${web-inf}/web.xml" manifest="${tmp}/MANIFEST.MF">
      <lib dir="${lib.axis}"/>
      <lib dir="${lib.commons-logging}"/>
      <lib dir="${lib.commons-fileupload}"/>
      <lib dir="${lib.commons-discovery}"/>
      <lib dir="${lib.log4j}"/>
      <lib dir="${lib.xalan}"/>
      <lib dir="${lib.xerces}"/>
      <classes dir="${compile}" excludes=""/>
      <classes dir="${res}" excludes="test/**"/>
      <classes file="${conf}/log4j/log4j.properties"/>
      <zipfileset dir="${pages}" excludes="" prefix="pages"/>
    	<zipfileset dir="${test}" excludes=".cvsignore" prefix="test">
    		<exclude unless="isTest" name="*/**"/>
    	</zipfileset>
      <zipfileset dir="${tempdir}" prefix="workdir/temp"/>	
    </war>
  </target>
  
  <target name="api-doc" depends="init">
    <description>create java doc</description>
    <!-- TODO does not work at the moment -->
  	<!--<javadoc defaultexcludes="yes"
           destdir="${api-doc}"
           author="true"
           version="true"
           use="true"
           windowtitle="MOA SL System Documentation">
      <packageset dir="src">
        <exclude name="test/**"/>
      </packageset>
      <link offline="false" href="http://java.sun.com/j2se/1.3/docs/api/"/>
      <doctitle><![CDATA[MOA SL System Documentation]]></doctitle>
      <classpath refid="compile.classpath"/>
    </javadoc>-->
  </target>
  
  <target name="dist-ws" depends="clean, package-ws">
    <description>create the webservice distributable</description>
    <copy toDir="${dist.ws}/conf">
      <fileset dir="${conf}"/>
    </copy>
  	<copy toDir="${dist.ws}/doc/handbook">
      <fileset dir="${handbook}" excludes="handbook/common/LogoMoa4c.3148x3545.jpg" />
    </copy>
    <copy toDir="${dist.ws}/endorsed14">
      <fileset dir="${lib.xalan}"/>
      <fileset dir="${lib.xerces}"/>
    </copy>
    <fixcrlf srcdir="${dist.ws}" includes="**/*.sh" eol="lf" eof="remove"/>
  </target>
  
  <target name="dist-ws-doc" depends="dist-ws, api-doc">
    <description>
      create the webservice-distributable, including all documentation
    </description>
    <copy toDir="${dist.ws}/doc/api-doc">
      <fileset dir="${api-doc}"/>
    </copy>
  </target>
  
  <target name="dist-ws-zip" depends="dist-ws-doc">
    <description>
      create the zipped webservice distributable
    </description>
    <zip zipfile="${dist.ws-zip}/moa-sl-${version}.zip">
      <zipfileset dir="${dist.ws}" prefix="moa-sl-${version}"/>
    </zip>
  </target>
  
  <target name="dist-src">
    <description>create the source distributable</description>
    <copy toDir="${dist.src}">
      <fileset dir="." excludes="tmp"/>
    </copy>
    <fixcrlf srcdir="${dist.src}" includes="**/*.sh" eol="lf" eof="remove"/>
  </target>
  
  <target name="dist-src-zip" depends="dist-src">
    <zip zipfile="${dist.src-zip}/moa-sl-${version}-src.zip">
      <zipfileset dir="${dist.src}" prefix="moa-sl-${version}-src"/>
    </zip>
  </target>
  
  <target name="dist-all" depends="dist-ws-zip, dist-src-zip">
    <description>create all distributables</description>
  </target>
  
  <target name="deploy-catalina" depends="dist-ws" if="env.CATALINA_HOME">
    <description>
      deploy the webservice to catalina (needs CATALINA_HOME defined)
    </description>
    <delete dir="${env.CATALINA_HOME}/webapps/moa-sl"/>
    <copy file="${dist.ws}/moa-sl.war" toDir="${env.CATALINA_HOME}/webapps"/>
    <!-- copy endorsed jars -->
    <copy toDir="${env.JAVA_ENDORSED_DIRS">
      <fileset dir="${dist.ws}/endorsed14"/>
    </copy>
    <!-- copy sample configuration -->
    <copy toDir="${env.CATALINA_HOME}/conf">
      <fileset dir="${conf}"/>
    </copy>
  </target>
  
  <target name="clean">
    <description>clean temporary files</description>
    <delete dir="${tmp}"/>
  </target>
	
  <target name="manifest">
    <filter token="version" value="${version}" /> 
    <copy file="manifest.template" tofile="${tmp}/MANIFEST.MF" overwrite="true" filtering="true" /> 
  </target>	
  	
</project>