<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="XEMELIOS-web" default="usage" basedir=".">
    <description>Builds, tests, and runs the project XEMELIOS xemelios-web</description>
    <property file="${user.home}/.ant.properties"/>
    <property name="compile.debug" value="true"/>
    <property file="build.properties"/>
    <target name="usage">
        <echo>
      Using ${ant.version}

      These are targets supported by this ANT build script:

      compile       - compile all .java files, except
                      thoses in ./tmp folder.
      clean         - deletes all compiled and generated
                      files and resources.

      Do not call this script directly, use the one located
              at root of projet (in ../..) instead.
        </echo>
    </target>
    
    <target name="compile" depends="mk-output-dirs">
        <javac srcdir="java" destdir="${build.classes.dir}" debug="${compile.debug}" encoding="ISO-8859-1" target="1.5">
            <classpath>
                <fileset dir="${GWT_1_5_HOME}">
                    <include name="**/gwt-servlet*"/>
                    <include name="**/gwt-client*"/>
                </fileset>
                <pathelement path="../starter/build/classes"/>
                <pathelement path="../xml-marshall/build/classes"/>
                <pathelement path="../core/build/classes"/>
                <pathelement path="../mysql-persistence/build/classes"/>
                <pathelement path="../batch/build/classes"/>
                <pathelement path="../auth-std-db/build/classes"/>
                <fileset dir="../core/lib" includes="*.jar"/>
                <fileset dir="lib" includes="*.jar"/>
                <fileset dir="../xemelios-core/lib" includes="*.jar"/>
            </classpath>
        </javac>
        <copy todir="${build.classes.dir}">
            <fileset dir="resources"/>
        </copy>
    </target>

    <target name="jars" depends="compile">
        <property file="component.properties"/>
        <jar destfile="${build.lib.dir}/${component.name}_${component.release}.jar" basedir="${build.classes.dir}">
            <manifest>
                <attribute name="Jar-Version" value="${component.release}"/>
                <attribute name="Jar-Content" value="${component.name}"/>
                <attribute name="Built-By" value="${user.name}"/>
            </manifest>
        </jar>
        <delete dir="${build.classes.dir}"/>
    </target>
    
    <target name="gwtCompile" depends="mk-output-dirs">
        <echo>GWT compilation, GWT_HOME is : ${GWT_1_5_HOME}</echo>
        <java maxmemory="512m" classname="com.google.gwt.dev.GWTCompiler" fork="true" failonerror="true">
            <classpath>
                <fileset dir="${GWT_1_5_HOME}" includes="*.jar"/>
                <pathelement path="java"/>
                <pathelement path="../starter/build/classes"/>
                <pathelement path="../xml-marshall/build/classes"/>
                <pathelement path="../core/build/classes"/>
                <pathelement path="../auth-std-db/build/classes"/>
            </classpath>
            <arg value="-out"/>
            <arg value="${build.web.dir}"/>
            <arg value="-style"/>
            <arg value="OBF"/>
            <!--arg value="DETAILED"/-->
            <arg value="-logLevel"/>
            <arg value="INFO"/>
            <arg value="fr.gouv.finances.dgfip.xemelios.web.gwt.Main"/>
        </java>
    </target>
    
    <target name="gwtDebug" depends="compile">
        <java maxmemory="512m" classname="com.google.gwt.dev.GWTShell" fork="true" failonerror="true">
            <jvmarg value="-Xdebug"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,address=8001,suspend=n"/>
            <classpath>
                <fileset dir="${GWT_1_5_HOME}" includes="*.jar"/>
                <pathelement path="../starter/build/classes"/>
                <pathelement path="../xml-marshall/build/classes"/>
                <pathelement path="../core/build/classes"/>
                <fileset dir="../core/lib" includes="*.jar"/>
                <fileset dir="lib" includes="*.jar"/>
                <pathelement path="${build.classes.dir}"/>
                <pathelement path="java"/>
            </classpath>
            <arg value="-noserver"/>
            <arg value="-out"/>
            <arg value="${build.web.dir}"/>
            <arg value="http://localhost:8080/xemeliosWeb"/>
            <!--arg value="fr.gouv.finances.dgfip.xemelios.web.gwt.Main/gwtTest.html"/-->
        </java>
    </target>

    <target name="updateWebSource">
        <copy todir="${build.web.dir}">
            <fileset dir="web"/>
        </copy>
        <copy todir="${build.web.dir}/WEB-INF/resources/">
            <fileset dir="../xemelios-core/res"/>
        </copy>
    </target>

    <target name="makeExplodedWar" depends="updateWebSource, compile, gwtCompile">
        <delete dir="${build.lib.dir}" includes="*.jar"/>
        <copy todir="${build.lib.dir}">
            <fileset dir="../starter/build/jars" includes="*.jar"/>
            <fileset dir="../xml-marshall/build/jars" includes="*.jar"/>
            <fileset dir="../core/build/jars" includes="*.jar"/>
            <fileset dir="../core/lib" includes="*.jar"/>
        	<fileset dir="../xemelios-core/lib" includes="commons-codec*.jar"/>
            <fileset dir="../mysql-persistence/build/jars" includes="*.jar"/>
            <fileset dir="../mysql-persistence/lib" includes="*.jar" excludes="mysql-je*"/>
            <fileset dir="../cfg-paye/build/jars" includes="*.jar"/>
            <fileset dir="../cg-colloc/build/jars" includes="*.jar"/>
            <fileset dir="../cg-etat/build/jars" includes="*.jar"/>
            <fileset dir="../erar/build/jars" includes="*.jar"/>
            <fileset dir="../pes-aller/build/jars" includes="*.jar"/>
            <fileset dir="../auth-aphm/build/jars" includes="*.jar"/>
            <fileset dir="../auth-basic/build/jars" includes="*.jar"/>
            <fileset dir="../auth-dgcp/build/jars" includes="*.jar"/>
            <fileset dir="../auth-ldap/build/jars" includes="*.jar"/>
            <fileset dir="../auth-std-db/build/jars" includes="*.jar"/>
            <fileset dir="../batch/build/jars" includes="*.jar"/>
            <fileset dir="../import-batch/build/jars" includes="*.jar"/>
            <!-- temporairement -->
            <fileset dir="../xemelios-core/build/jars" includes="*.jar"/>
            <!-- fin temporairement -->
            <fileset dir="${GWT_1_5_HOME}">
                <include name="**/gwt-servlet*"/>
            </fileset>
            <fileset dir="lib">
                <exclude name="**/servlet-api*"/>
                <exclude name="**/jsp-api-*"/>
            </fileset>
            <!-- pour le auth-dgcp -->
            <fileset dir="../xemelios-core/lib">
                <include name="forms-1.0.5.jar"/>
            </fileset>
        </copy>
        <touch file="${build.webxml.path}"/>
    </target>
    <target name="makeExplodedWar-noGwtCompile" depends="updateWebSource, compile">
        <delete dir="${build.lib.dir}" includes="*.jar"/>
        <copy todir="${build.lib.dir}">
            <fileset dir="../starter/build/jars" includes="*.jar"/>
            <fileset dir="../xml-marshall/build/jars" includes="*.jar"/>
            <fileset dir="../core/build/jars" includes="*.jar"/>        	
            <fileset dir="../core/lib" includes="*.jar"/>
        	<fileset dir="../xemelios-core/lib" includes="commons-codec*.jar"/>
            <fileset dir="../mysql-persistence/build/jars" includes="*.jar"/>
            <fileset dir="../mysql-persistence/lib" includes="*.jar" excludes="mysql-je*"/>
            <fileset dir="../cfg-paye/build/jars" includes="*.jar"/>
            <fileset dir="../cg-colloc/build/jars" includes="*.jar"/>
            <fileset dir="../erar/build/jars" includes="*.jar"/>
            <fileset dir="../pes-aller/build/jars" includes="*.jar"/>
            <fileset dir="../auth-aphm/build/jars" includes="*.jar"/>
            <fileset dir="../auth-basic/build/jars" includes="*.jar"/>
            <fileset dir="../auth-dgcp/build/jars" includes="*.jar"/>
            <fileset dir="../auth-ldap/build/jars" includes="*.jar"/>
            <fileset dir="../auth-std-db/build/jars" includes="*.jar"/>
            <fileset dir="../batch/build/jars" includes="*.jar"/>
            <fileset dir="${GWT_1_5_HOME}">
                <include name="**/gwt-servlet*"/>
            </fileset>
            <fileset dir="lib">
                <exclude name="**/servlet-api*"/>
                <exclude name="**/jsp-api-*"/>
            </fileset>
        </copy>
        <touch file="${build.webxml.path}"/>
    </target>
    
    <target name="clean">
        <delete dir="build"/>
    </target>
    
    <target name="mk-output-dirs">
        <mkdir dir="${build.classes.dir}"/>
        <mkdir dir="${build.lib.dir}"/>
    </target>
    
</project>