<!--

  Ant Buildfile for MOA SS E-Recht Client
  
  Authors: Gregor Karlinger

  $Id$

-->
<project name="moa-sss-erecht-client" default="deploy-catalina" basedir=".">
  <property environment="env"/>
  <property name="script-suffix" value="${env.SCRIPT_SUFFIX}"/>
  <property name="version" value="0.1"/>

  <property name="lib" value="lib"/>
  <property name="src" value="src"/>
  <property name="res" value="data/res"/>
  <property name="web-inf" value="data/WEB-INF"/>
  <property name="pages" value="data/pages"/>
  <property name="static" value="data/static"/>
  <property name="test" value="data/test"/>
  <property name="conf" value="data/conf"/>
  <property name="handbook" value="handbook"/>
  <property name="tempdir" value="data/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.1"/>
  <property name="lib.commons-fileupload" value="${lib}/commons-fileupload-1.1.1"/>
  <property name="lib.commons-io" value="${lib}/commons-io-1.1"/>
  <property name="lib.log4j" value="${lib}/log4j-1.2.14"/>
  <property name="lib.servlet" value="${lib}/servlet-2.3"/>
  <property name="lib.xalan" value="${lib}/xalan-2.7.0"/>
  <property name="lib.xerces" value="${lib}/xerces-2.9.0"/>

  <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.axis}/commons-discovery-0.2.jar"/>
    <pathelement location="${lib.commons-fileupload}/commons-fileupload-1.1.1.jar"/>
    <pathelement location="${lib.commons-io}/commons-io-1.1.jar"/>
    <pathelement location="${lib.log4j}/log4j-1.2.14.jar"/>
    <pathelement location="${lib.servlet}/servlet-2_3-fcs-classfiles.zip"/>
    <pathelement location="${lib.xalan}/xalan.jar"/>
    <pathelement location="${lib.xerces}/xml-apis.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="${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 deprecation="true" srcdir="${src}" destdir="${compile}"
           classpathref="compile.classpath" 
    	     verbose="false"
           debug="on">
    </javac>
  </target>
  
  <target name="package-ws" depends="compile, manifest">
    <description>package the server war file</description>
    <war warfile="${dist.ws}/moa-ss-erecht-client.war" webxml="${web-inf}/web.xml" manifest="${tmp}/MANIFEST.MF">
      <lib dir="${lib.axis}"/>
      <lib dir="${lib.commons-fileupload}"/>
      <lib dir="${lib.commons-io}"/>
      <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.properties"/>
      <zipfileset dir="${pages}" includes="**" excludes="" prefix="pages"/>
      <zipfileset dir="${static}" excludes="" prefix="static"/>
      <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}/endorsed14">
      <fileset dir="${lib.xalan}"/>
      <fileset dir="${lib.xerces}"/>
    </copy>
    <copy toDir="${dist.ws}/handbook">
      <fileset dir="${handbook}" excludes="**/*.VSD"/>
    </copy>
    <copy toDir="${dist.ws}/testdaten">
      <fileset dir="${test}"/>
    </copy>
  </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-ss-erecht-client-${version}.zip">
      <zipfileset dir="${dist.ws}" prefix="moa-ss-erecht-client-${version}"/>
    </zip>
  </target>
  
  <target name="dist-src">
    <description>create the source distributable</description>
    <copy toDir="${dist.src}">
      <fileset dir="." excludes="tmp"/>
    </copy>
  </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-ss-erecht-client-${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_BASE">
    <description>
      deploy the webservice to catalina (needs CATALINA_HOME defined)
    </description>
    <delete dir="${env.CATALINA_BASE}/webapps/moa-ss-erecht-client"/>
    <copy file="${dist.ws}/moa-ss-erecht-client.war" toDir="${env.CATALINA_BASE}/webapps"/>
    <!-- copy endorsed jars -->
    <copy toDir="${env.JAVA_ENDORSED_DIRS}">
      <fileset dir="${dist.ws}/endorsed14"/>
    </copy>
    <!-- copy sample configuration -->
    <mkdir dir="${env.CATALINA_BASE}/conf/moa-ss-erecht-client"/>
  	<copy toDir="${env.CATALINA_BASE}/conf/moa-ss-erecht-client">
      <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>