<!--

  Ant Buildfile for MOA SP/SS Server
  
  Authors: Patrick Peck, Gregor Karlinger

  $Id$

-->
<project name="moa-spss-server" default="deploy-catalina" basedir=".">
  <property environment="env"/>
  <property name="script-suffix" value="${env.SCRIPT_SUFFIX}"/>
  <property name="version" value="1.3.0D01"/>
  <property name="src" value="src"/>
  <property name="lib" value="lib"/>
  <property name="res" value="res"/>
  <property name="data" value="data"/>
  <property name="licenses" value="licenses"/>
  <property name="handbook" value="../spss.handbook"/>
  <property name="deploy.conf" value="${handbook}/conf"/>
  <property name="doc" value="doc"/>
  <property name="tmp" value="tmp"/>
  <property name="compile" value="${tmp}/compile"/>
  <property name="tools" value="${tmp}/tools"/>
  <property name="tmp.doc" value="${tmp}/doc"/>
  <property name="api-doc" value="${tmp}/api-doc"/>
  <property name="api-doc.internal" value="${tmp}/api-doc-internal"/>
  <property name="prj.build" value="../build"/>
  <property name="prj.common" value="../common"/>
  <property name="prj.handbook" value="../spss.handbook"/>
  <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.lib" value="${dist}/lib"/>
  <property name="dist.lib-zip" value="${dist}/lib-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.jaxp" value="${lib}/jaxp-1.2_01"/>
  <property name="lib.jaxen" value="${lib}/jaxen-1.0"/>
  <property name="lib.xerces" value="${lib}/xerces-j-2.4.0"/>
  <property name="lib.xalan" value="${lib}/xalan-j-2.5.1"/>
  <property name="lib.jsse" value="${lib}/jsse-1.0.3_03"/>
  <property name="lib.postgres-jdbc" value="${lib}/postgres-jdbc2-7.3"/>
  <property name="lib.iaik-moa" value="../spss.iaiklibsupdate/iaiklibs.prod"/>
  <property name="lib.junit" value="${lib}/junit-3.8.1"/>
  <property name="lib.servlet" value="${lib}/servlet-2.3"/>
  <property name="lib.commons-logging" value="${lib}/commons-logging-1.0.4"/>
  <property name="lib.commons-discovery" value="${lib}/commons-discovery-0.2"/>
  <property name="lib.log4j" value="${lib}/log4j-1.2.7"/>
  <property name="lib.idoclet" value="${lib}/iDoclet-1.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.jaxp}/jaxp-api.jar"/>
    <pathelement location="${lib.jaxp}/dom.jar"/>
    <pathelement location="${lib.jaxp}/sax.jar"/>
    <pathelement location="${lib.xerces}/xerces.jar"/>
    <pathelement location="${lib.jaxen}/jaxen-core.jar"/>
    <pathelement location="${lib.jaxen}/jaxen-dom.jar"/>
    <pathelement location="${lib.jaxen}/saxpath.jar"/>
    <pathelement location="${lib.xalan}/xalan.jar"/>
    <pathelement location="${lib.junit}/junit.jar"/>
    <fileset dir="${lib.jsse}" />
    <pathelement location="${lib.commons-logging}/commons-logging-api.jar"/>
    <pathelement location="${lib.commons-discovery}/commons-discovery.jar"/>
    <pathelement location="${lib.servlet}/servlet-2_3-fcs-classfiles.zip"/>
    <pathelement location="${lib.iaik-moa}/iaik_moa_full.jar"/>
    <pathelement location="${lib.iaik-moa}/iaik_ixsil.jar"/>
    <pathelement location="${lib.iaik-moa}/iaik_jce_full.jar"/>
    <pathelement location="${lib.iaik-moa}/iaik_ecc.jar"/>
    <pathelement location="${env.MOA_COMMON_TEST_JAR}"/>
  </path>
  
  <target name="init">
    <description>set up directories etc.</description>
    <tstamp/>
    <mkdir dir="${tmp}"/>
    <mkdir dir="${compile}"/>
    <mkdir dir="${tools}"/>
    <mkdir dir="${api-doc}"/>
    <mkdir dir="${api-doc.internal}"/>
    <mkdir dir="${dist}"/>
    <mkdir dir="${dist.ws}"/>
    <mkdir dir="${dist.ws-zip}"/>
    <mkdir dir="${dist.lib}"/>
    <mkdir dir="${dist.lib-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">
    <description>package the server war file</description>
    <war warfile="${dist.ws}/moa-spss.war" webxml="web.xml">
      <lib dir="${lib.xalan}"/>
      <lib dir="${lib.xerces}"/>
      <lib dir="${lib.jaxp}"/>
      <lib dir="${lib.log4j}"/>
      <lib dir="${lib.postgres-jdbc}"/>
      <lib dir="${lib.axis}"/>
      <lib dir="${lib.jaxen}"/>
      <!--
      <lib dir="${lib.iaik-moa}" 
           excludes="iaik_jce_full.jar, iaik_ecc.jar, iaik_Pkcs11Provider.jar, win32/**, linux/**, solaris/**, signed/**"/>
      -->     
      <lib file="${lib.commons-logging}/commons-logging.jar"/>
      <lib file="${lib.commons-discovery}/commons-discovery.jar"/>
      <lib file="${env.MOA_COMMON_JAR}"/>
      <classes dir="${compile}" excludes="test/**"/>
      <classes dir="${res}" excludes="resources/tools/**, test/**"/>
      <classes file="${handbook}/conf/moa-spss/log4j.properties"/>
      <webinf file="server-config.wsdd"/>
      <webinf dir="${handbook}" includes="conf/**"/>
      <zipfileset file="${res}/resources/wsdl/MOA-SPSS-1.3.xsd" prefix="resources/schemas"/>
    </war>
  </target>
  
  <target name="package-lib" depends="compile">
    <description>package the library jar file</description>
    <jar destfile="${dist.lib}/moa-spss.jar">
      <fileset dir="${compile}" excludes="test/**"/>
      <fileset dir="${res}" excludes="resources/tools/**, test/**"/>
      <fileset dir="${handbook}/conf/moa-spss" includes="log4j.properties"/>
    </jar>
  </target>
  
  <target name="package-tools" depends="compile">
    <description>package the configuration tools</description>
    <jar destfile="${tools}/tools.jar">
      <fileset dir="${compile}" includes="at/**/tools/**"/>
      <fileset dir="${res}" includes="resources/tools/**"/>	
    </jar>
  </target>
  
  <target name="api-doc-internal" depends="init">
    <description>create JavaDoc for the server internal classes</description>
    <javadoc defaultexcludes="yes"
           destdir="${api-doc.internal}"
           author="true"
           version="true"
           use="true"
           windowtitle="MOA SP/SS Server Internal API">
      <packageset dir="${prj.common}/src">
        <exclude name="test/**"/>
      </packageset>
      <packageset dir="src">
        <exclude name="test/**"/>
        <exclude name="at/gv/egovernment/moa/spss/api/**"/>
      </packageset>
      <group title="Exception Classes"
             packages="at.gv.egovernment.moa.spss.server">
      </group>
      <group title="MOA Configuration">
        <package name="at.gv.egovernment.moa.spss.server.config"/>
        <package name="at.gv.egovernment.moa.spss.server.iaik.config"/>
      </group>
      <group title="Web Service Handling">
        <package name="at.gv.egovernment.moa.spss.server.service"/>
        <package name="at.gv.egovernment.moa.spss.server.transaction"/>
      </group>
      <group title="Mapping MOA API calls to the IAIK API"
             packages="at.gv.egovernment.moa.spss.server.invoke">
      </group>
      <group title="Implementations of IAIK interfaces"
             packages="at.gv.egovernment.moa.spss.server.iaik.*">
      </group>
      <group title="Utilities">
        <package name="at.gv.egovernment.moa.util"/>
        <package name="at.gv.egovernment.moa.spss.server.util"/>
      </group>
      <group title="Logging">
        <package name="at.gv.egovernment.moa.logging"/>
        <package name="at.gv.egovernment.moa.spss.server.logging"/>
      </group>
      <group title="External Tools"
             packages="at.gv.egovernment.moa.spss.server.tools">
      </group>
      <link offline="false" href="http://java.sun.com/j2se/1.3/docs/api/"/>
      <doctitle><![CDATA[<h1>MOA SP/SS Server Internal API</h1>]]></doctitle>
      <classpath refid="compile.classpath"/>
    </javadoc>
  </target>
  
  <target name="api-doc" depends="init">
    <description>create JavaDoc for the SP/SS API</description>
    <javadoc defaultexcludes="yes"
           destdir="${api-doc}"
           author="false"
           version="false"
           use="true"
           Overview="${src}/at/gv/egovernment/moa/spss/overview.htm"
           windowtitle="MOA SP/SS API">
      <packageset dir="src">
        <include name="at/gv/egovernment/moa/spss/**"/>
        <exclude name="at/gv/egovernment/moa/spss/server/**"/>
        <exclude name="at/gv/egovernment/moa/spss/api/impl/**"/>
        <exclude name="test/**"/>
      </packageset>
      <packageset dir="${prj.common}/src">
        <exclude name="test/**"/>
      </packageset>
      <group title="API Factory and Services">
        <package name="at.gv.egovernment.moa.spss.api"/>
      </group>
      <group title="Exceptions">
        <package name="at.gv.egovernment.moa.spss"/>
      </group>
      <group title="API Objects for Signature Creation">
        <package name="at.gv.egovernment.moa.spss.api.xmlsign"/>
      </group>
      <group title="API Objects for CMS Signature Verification">
        <package name="at.gv.egovernment.moa.spss.api.cmsverify"/>
      </group>
      <group title="API Objects for XML Signature Verification">
        <package name="at.gv.egovernment.moa.spss.api.xmlverify"/>
      </group>
      <group title="Common API Objects">
        <package name="at.gv.egovernment.moa.spss.api.common"/>
      </group>
      <group title="Builders and Parsers to convert API Objects to and from XML">
        <package name="at.gv.egovernment.moa.spss.api.xmlbind"/>
      </group>
      <group title="Utilities">
        <package name="at.gv.egovernment.moa.util"/>
        <package name="at.gv.egovernment.moa.spss.util"/>
      </group>
      <group title="Logging">
        <package name="at.gv.egovernment.moa.logging"/>
      </group>
      <link offline="false" href="http://java.sun.com/j2se/1.3/docs/api/"/>
      <doclet name="iContract.doclet.Standard" 
              path="${lib.idoclet}/iDoclet.jar">
        <param name="-use"/>
      </doclet>
      <doctitle><![CDATA[<h1>MOA SP/SS API</h1>]]></doctitle>
      <classpath refid="compile.classpath"/>
    </javadoc>
  </target>
  
  <target name="dist-ws" depends="package-ws, package-tools">
    <description>create the webservice distributable</description>
    <copy toDir="${dist.ws}/tomcat">
      <fileset dir="${data}/deploy/tomcat"/>
    </copy>
    <copy toDir="${dist.ws}/conf">
      <fileset dir="${handbook}/conf"/>
    </copy>
    <copy toDir="${dist.ws}/ext13">
      <!--
      <fileset dir="${lib.iaik-moa}" includes="iaik_jce_full.jar, iaik_ecc.jar, iaik_Pkcs11Provider.jar"/>
      -->
      <fileset dir="${lib.jsse}"/>
    </copy>
    <!--
    <copy toDir="${dist.ws}/ext14">
      <fileset dir="${lib.iaik-moa}/signed"/>
    </copy>
    -->
    <copy toDir="${dist.ws}/endorsed14">
      <fileset dir="${lib.xalan}"/>
    </copy>
    <copy toDir="${dist.ws}/tools">
      <fileset dir="${tools}"/>
      <!--
      <fileset dir="${lib.iaik-moa}">
        <include name="iaik_jce_full.jar"/>
        <include name="iaik_moa_full.jar"/>
        <include name="iaik_ecc.jar"/>
      </fileset>
      -->
      <fileset dir="${lib.log4j}"/>
      <fileset dir="${lib.xalan}"/>    	
      <fileset dir="${data}/deploy/tools"/>
    </copy>
    <copy toDir="${dist.ws}/pkcs11">
      <fileset dir="${lib.iaik-moa}" includes="win32/**, linux/**, solaris/**"/>
    </copy>
  	<copy toDir="${dist.ws}/licenses">
  	  <fileset dir="${licenses}"/>
  	</copy>	
  	<copy toDir="${dist.ws}">
  	  <fileset dir="." includes="readme.inst.txt, history.txt"/>	
  	</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>
    <!-- Handbuch aus dem Projekt spss.handbook -->
  	<copy toDir="${dist.ws}/doc">
      <fileset dir="${handbook}" excludes="bin/** conf/** handbook/common/LogoMoa4c.3148x3545.jpg .project .classpath" />
    </copy>
  </target>
  
  <target name="dist-ws-zip" depends="dist-ws-doc">
    <description>
      create the zipped webservice distributable
    </description>
    <zip zipfile="${dist.ws-zip}/moa-spss-${version}.zip">
      <zipfileset dir="${dist.ws}" prefix="moa-spss-${version}"/>
    </zip>
  </target>
  
  <target name="dist-lib" depends="package-lib">
    <description>create the library distributable</description>
    <copy todir="${dist.lib}" file="${env.MOA_COMMON_JAR}"/>
    <copy todir="${dist.lib}/lib">
      <fileset dir="${lib.jaxp}"/>
      <fileset dir="${lib.jaxen}"/>
      <fileset dir="${lib.xerces}"/>
      <fileset dir="${lib.xalan}"/>
      <fileset dir="${lib.postgres-jdbc}"/>
      <!--
      <fileset dir="${lib.iaik-moa}" excludes="signed/**, iaik_jce_full.jar, iaik_ecc.jar, iaik_Pkcs11Provider.jar"/>
      -->
      <fileset dir="${lib.commons-logging}"/>
      <fileset dir="${lib.log4j}"/>
      <fileset dir="${lib.commons-discovery}"/>
    </copy>
    <copy toDir="${dist.lib}/conf">
      <fileset dir="${handbook}/conf"/>
    </copy>
    <copy toDir="${dist.lib}/ext13">
      <!--
      <fileset dir="${lib.iaik-moa}" includes="iaik_jce_full.jar, iaik_ecc.jar, iaik_Pkcs11Provider.jar"/>
      -->
      <fileset dir="${lib.jsse}"/>
    </copy>
    <!--
    <copy toDir="${dist.lib}/ext14">
      <fileset dir="${lib.iaik-moa}/signed"/>
    </copy>
    -->
    <copy toDir="${dist.lib}/tools">
      <fileset dir="${tools}"/>
      <!--
      <fileset dir="${lib.iaik-moa}">
        <include name="iaik_jce_full.jar"/>
        <include name="iaik_moa_full.jar"/>
        <include name="iaik_ecc.jar"/>
      </fileset>
      -->
      <fileset dir="${lib.log4j}"/>
      <fileset dir="${lib.xalan}"/>
      <fileset dir="${data}/deploy/tools"/>
    </copy>
  	<copy toDir="${dist.lib}/licenses">
  	  <fileset dir="${licenses}"/>
  	</copy>	
  	<copy toDir="${dist.lib}">
  	  <fileset dir="." includes="readme.inst.txt, history.txt"/>	
  	</copy>
    <fixcrlf srcdir="${dist.lib}" includes="**/*.sh" eol="lf" eof="remove"/>
  </target>
  
  <target name="dist-lib-doc" depends="dist-lib, api-doc">
    <description>
      create the library distributable, including all documentation
    </description>
    <copy toDir="${dist.lib}/doc/api-doc">
      <fileset dir="${api-doc}"/>
    </copy>
    <!-- Handbuch aus dem Projekt spss.handbook -->
  	<copy toDir="${dist.lib}/doc">
      <fileset dir="${handbook}" excludes="bin/** conf/** handbook/common/LogoMoa4c.3148x3545.jpg .project .classpath"/>
    </copy>
  </target>
  
  <target name="dist-lib-zip" depends="dist-lib-doc">
    <description>
      create the zipped library distributable
    </description>
    <zip zipfile="${dist.lib-zip}/moa-spss-${version}-lib.zip">
      <zipfileset dir="${dist.lib}" prefix="moa-spss-${version}-lib"/>
    </zip>
  </target>
  
  <target name="dist-src">
    <description>create the source distributable</description>
    <copy toDir="${dist.src}/build">
      <fileset dir="${prj.build}"/>
    </copy>
    <copy toDir="${dist.src}/common">
      <fileset dir="${prj.common}" excludes="tmp/**, bin/**, lib/iaik-jce-3.0.6/**"/>
    </copy>
    <copy toDir="${dist.src}/spss.handbook">
        <fileset dir="${prj.handbook}" excludes="clients/api/lib/iaik-moa-20050623/**"/>
    </copy>
    <copy toDir="${dist.src}/spss.server">
      <fileset dir="." excludes="tmp/**, bin/**, lib/iaik-moa-20050623/**"/>
    </copy>
  	<copy toDir="${dist.src}">
  	  <fileset dir="." includes="readme.src.txt"/>	
  	</copy>
    <fixcrlf srcdir="${dist.src}" includes="**/*.sh" eol="lf" eof="remove"/>
  </target>
  
  <target name="dist-src-doc" depends="dist-src, api-doc-internal">
    <copy toDir="${dist.src}/spss.server/doc/api-doc-internal">
      <fileset dir="${api-doc.internal}"/>
    </copy>
  </target>
  
  <target name="dist-src-zip" depends="dist-src-doc">
    <zip zipfile="${dist.src-zip}/moa-spss-${version}-src.zip">
      <zipfileset dir="${dist.src}" prefix="moa-spss-${version}-src"/>
    </zip>
  </target>
  
  <target name="dist-all" depends="dist-ws-zip, dist-lib-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-spss"/>
    <copy file="${dist.ws}/moa-spss.war" toDir="${env.CATALINA_HOME}/webapps"/>
    <!-- copy endorsed jars -->
    <copy toDir="${env.CATALINA_HOME}/common/endorsed">
      <fileset dir="${dist.ws}/endorsed14"/>
    </copy>
    <!-- copy sample configuration -->
    <copy toDir="${env.CATALINA_HOME}/conf">
      <fileset dir="${deploy.conf}"/>
    </copy>
  </target>
  
  <target name="clean">
    <description>clean temporary files</description>
    <delete dir="${tmp}"/>
  </target>
</project>