<?xml version="1.0"?>
<project name="bdf" default="webinf">

<property name="project.name" value="${ant.project.name}"/>
<property name="project.version" value="dev"/>
<property name="project.repository" value="local"/>
<property name="project.webapp_name" value="bdf"/>
<property name="project.param_auth_sharing" value="false"/>
<property name="project.param_disable_password" value="false"/>
<property name="project.param_conf_file" value="/etc/bdf/bdf-conf.xml"/>
<property name="project.param_smtp_file" value="/etc/bdf/smtp.ini"/>
<property name="project.param_multi_bdf" value="true"/>
<property name="project.param_central_sphere_list" value=""/>
<property name="src.path" location="../.."/>
<property name="deploy.path" location="../.."/>
<property name="build.dir" location="${deploy.path}/build/${project.name}"/>
<property name="dist.dir" location="${deploy.path}/dist/${project.name}-${project.version}"/>
<property name="vendor.lib.dir" location="../../vendor/lib"/>
<tstamp>
    <format property="timestamp.isoformat" pattern="yyyy-MM-dd'T'HH:mm:ss" locale="en"/>
    <format property="date.isoformat" pattern="yyyy-MM-dd" locale="en"/>
</tstamp>
<path id="compile.classpath">
    <pathelement location="${vendor.lib.dir}/servlet-api.jar"/>
    <pathelement location="${vendor.lib.dir}/sac.jar"/>
    <pathelement location="${vendor.lib.dir}/commons-fileupload.jar"/>
	<pathelement location="${vendor.lib.dir}/javax.activation.jar"/>
    <pathelement location="${vendor.lib.dir}/javax.mail.jar"/>
    <pathelement location="${vendor.lib.dir}/jdbm.jar"/>
	<pathelement location="${vendor.lib.dir}/jsoup.jar"/>
</path>
<path id="javax2jakarta.classpath">
    <fileset dir="../jakartaee-migration-1.0.8/lib">
        <include name="**/*.jar"/>
    </fileset>
</path>
<taskdef name="javax2jakarta" classname="org.apache.tomcat.jakartaee.MigrationTask" classpathref="javax2jakarta.classpath"/>

<target name="init">
    <delete dir="${dist.dir}"/>
    <delete dir="${build.dir}"/>
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir}/classes"/>
    <mkdir dir="${dist.dir}/WEB-INF"/>
    <mkdir dir="${dist.dir}/WEB-INF/lib"/>
</target>

<target name="compile" depends="init">
    <javac destdir="${build.dir}/classes" debug="true" debuglevel="lines,vars,source" source="1.8" target="1.8">
        <compilerarg line="-encoding utf-8"/>
        <compilerarg value="-Xlint:deprecation" />
        <src path="${src.path}/UtilLib/src"/>
        <src path="${src.path}/UtilLib_Awt/src"/>
        <src path="${src.path}/UtilLib_Css/src"/>
        <src path="${src.path}/UtilLib_Email/src"/>
		<src path="${src.path}/UtilLib_Html/src"/>
        <src path="${src.path}/UtilLib_Servlet/src"/>
        <src path="${src.path}/UtilLib_Servlet_MultiPart/src"/>
        <src path="${src.path}/OdLib_Elements/src"/>
        <src path="${src.path}/OdLib_Css/src"/>
        <src path="${src.path}/OdLib_Io/src"/>
        <src path="${src.path}/ScrutariDataExport/src"/>
        <src path="${src.path}/FichothequeLib_API/src"/>
        <src path="${src.path}/FichothequeLib_Impl/src"/>
        <src path="${src.path}/FichothequeLib_Srz/src"/>
        <src path="${src.path}/FichothequeLib_Tools/src"/>
        <src path="${src.path}/FichothequeLib_Xml/src"/>
        <src path="${src.path}/FichothequeLib_Import/src"/>
        <src path="${src.path}/BdfServer/src"/>
        <src path="${src.path}/BdfServer_Resources/src"/>
        <src path="${src.path}/BdfServer_DirectoryStorage/src"/>
        <src path="${src.path}/BdfServer_Email/src"/>
        <src path="${src.path}/BdfServer_Commands/src"/>
        <src path="${src.path}/BdfServer_Html/src"/>
        <src path="${src.path}/BdfServer_Get/src"/>
        <src path="${src.path}/BdfServer_JsonProducers/src"/>
        <src path="${src.path}/BdfServer_HtmlProducers/src"/>
		<src path="${src.path}/BdfServer_Multi/src"/>
        <src path="${src.path}/BDF/src"/>
        <classpath refid="compile.classpath"/>
    </javac>
    <copy todir="${build.dir}/classes">
        <fileset dir="${src.path}/UtilLib/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/UtilLib_Awt/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/UtilLib_Css/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/UtilLib_Email/src" excludes="**/*.java"/>
		<fileset dir="${src.path}/UtilLib_Html/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/UtilLib_Servlet/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/UtilLib_Servlet_MultiPart/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/OdLib_Elements/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/OdLib_Css/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/OdLib_Io/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/ScrutariDataExport/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/FichothequeLib_API/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/FichothequeLib_Impl/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/FichothequeLib_Srz/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/FichothequeLib_Tools/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/FichothequeLib_Xml/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/FichothequeLib_Import/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_Resources/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_DirectoryStorage/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_Email/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_Commands/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_Html/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_Get/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_JsonProducers/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BdfServer_HtmlProducers/src" excludes="**/*.java"/>
		<fileset dir="${src.path}/BdfServer_Multi/src" excludes="**/*.java"/>
        <fileset dir="${src.path}/BDF/src" excludes="**/*.java"/>
    </copy>
    <copy todir="${build.dir}/classes/fr/exemole/bdfserver/servlets" overwrite="true">
        <fileset dir="rsc" includes="VERSION"/>
        <filterset>
            <filter token="VERSION" value="${project.version}"/>
            <filter token="DATE" value="${date.isoformat}"/>
            <filter token="REPOSITORY" value="${project.repository}"/>
        </filterset>
    </copy>
    <copy file="${build.dir}/classes/fr/exemole/bdfserver/servlets/VERSION" todir="${build.dir}/classes"/>
</target>

<target name="jar" depends="compile">
    <property name="manifest.mf" location="${build.dir}/manifest.mf"/>
    <manifest file="${manifest.mf}">
        <attribute name="Built-On" value="${timestamp.isoformat}"/>
    </manifest>
    <jar destfile="${dist.dir}/WEB-INF/lib/bdf-${project.version}.jar" duplicate="preserve" compress="true" manifest="${manifest.mf}">
        <fileset dir="${build.dir}/classes"/>
    </jar>
</target>

<target name="copy-file-implementation" if="file.implementation">
    <copy file="${file.implementation}" tofile="${dist.dir}/WEB-INF/implementation.properties" overwrite="true"/>
</target>

<target name="copylib">
    <copy file="${vendor.lib.dir}/sac.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/commons-fileupload.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/commons-io.jar" todir="${dist.dir}/WEB-INF/lib"/>
	<copy file="${vendor.lib.dir}/javax.activation.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/javax.mail.jar" todir="${dist.dir}/WEB-INF/lib"/>
	<copy file="${vendor.lib.dir}/jsoup.jar" todir="${dist.dir}/WEB-INF/lib"/>
</target>

<target name="webinf" depends="jar,copy-file-implementation">
    <copy file="${src.path}/BDF/web/WEB-INF/web.xml" todir="${dist.dir}/WEB-INF" overwrite="true"/>
    <copy file="${vendor.lib.dir}/jdbm.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/sac.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/commons-fileupload.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/commons-io.jar" todir="${dist.dir}/WEB-INF/lib"/>
	<copy file="${vendor.lib.dir}/javax.activation.jar" todir="${dist.dir}/WEB-INF/lib"/>
    <copy file="${vendor.lib.dir}/javax.mail.jar" todir="${dist.dir}/WEB-INF/lib"/>
	<copy file="${vendor.lib.dir}/jsoup.jar" todir="${dist.dir}/WEB-INF/lib"/>
	<copy todir="${dist.dir}/META-INF" overwrite="true">
		<fileset dir="rsc" includes="context.xml"/>
		<filterset>
			<filter token="CONF_FILE" value="${project.param_conf_file}"/>
			<filter token="SMTP_FILE" value="${project.param_smtp_file}"/>
			<filter token="AUTH_SHARING" value="${project.param_auth_sharing}"/>
			<filter token="DISABLE_PASSWORD" value="${project.param_disable_password}"/>
		</filterset>
	</copy>
    <copy todir="${dist.dir}/META-INF" overwrite="true">
		<fileset dir="rsc" includes="bdf-conf.xml"/>
		<filterset>
			<filter token="MULTI_BDF" value="${project.param_multi_bdf}"/>
			<filter token="CENTRAL_SPHERE_LIST" value="${project.param_central_sphere_list}"/>
		</filterset>
	</copy>
    <copy file="rsc/example-smtp.ini" todir="${dist.dir}/META-INF"/>
</target>

<target name="zip">
    <zip destFile="${dist.dir}/../${project.name}-${project.version}-bin.zip" duplicate="preserve">
        <zipfileset dir="${dist.dir}/WEB-INF" prefix="${project.name}-${project.version}/WEB-INF"/>
    </zip>
    <zip destFile="${dist.dir}/../${project.name}-${project.version}-src.zip" duplicate="preserve">
        <zipfileset dir="${src.path}/ant/BDF" prefix="${project.name}-${project.version}/ant/BDF"/>
        <zipfileset dir="${src.path}/UtilLib" prefix="${project.name}-${project.version}/UtilLib"/>
        <zipfileset dir="${src.path}/UtilLib_Awt" prefix="${project.name}-${project.version}/UtilLib_Awt"/>
        <zipfileset dir="${src.path}/UtilLib_Css" prefix="${project.name}-${project.version}/UtilLib_Css"/>
        <zipfileset dir="${src.path}/UtilLib_Email" prefix="${project.name}-${project.version}/UtilLib_Email"/>
		<zipfileset dir="${src.path}/UtilLib_Html" prefix="${project.name}-${project.version}/UtilLib_Html"/>
        <zipfileset dir="${src.path}/UtilLib_Servlet" prefix="${project.name}-${project.version}/UtilLib_Servlet"/>
        <zipfileset dir="${src.path}/UtilLib_Servlet_MultiPart" prefix="${project.name}-${project.version}/UtilLib_Servlet_MultiPart"/>
        <zipfileset dir="${src.path}/OdLib_Elements" prefix="${project.name}-${project.version}/OdLib_Css"/>
        <zipfileset dir="${src.path}/OdLib_Css" prefix="${project.name}-${project.version}/OdLib_Css"/>
        <zipfileset dir="${src.path}/OdLib_Io" prefix="${project.name}-${project.version}/OdLib_Io"/>
        <zipfileset dir="${src.path}/ScrutariDataExport" prefix="${project.name}-${project.version}/ScrutariDataExport"/>
        <zipfileset dir="${src.path}/FichothequeLib_API" prefix="${project.name}-${project.version}/FichothequeLib_API"/>
        <zipfileset dir="${src.path}/FichothequeLib_Impl" prefix="${project.name}-${project.version}/FichothequeLib_Impl"/>
        <zipfileset dir="${src.path}/FichothequeLib_Srz" prefix="${project.name}-${project.version}/FichothequeLib_Srz"/>
        <zipfileset dir="${src.path}/FichothequeLib_Tools" prefix="${project.name}-${project.version}/FichothequeLib_Tools"/>
        <zipfileset dir="${src.path}/FichothequeLib_Xml" prefix="${project.name}-${project.version}/FichothequeLib_Xml"/>
        <zipfileset dir="${src.path}/FichothequeLib_Import" prefix="${project.name}-${project.version}/FichothequeLib_Import"/>
        <zipfileset dir="${src.path}/BdfServer" prefix="${project.name}-${project.version}/BdfServer"/>
        <zipfileset dir="${src.path}/BdfServer_Resources" prefix="${project.name}-${project.version}/BdfServer_Resources"/>
        <zipfileset dir="${src.path}/BdfServer_DirectoryStorage" prefix="${project.name}-${project.version}/BdfServer_DirectoryStorage"/>
        <zipfileset dir="${src.path}/BdfServer_Email" prefix="${project.name}-${project.version}/BdfServer_Email"/>
        <zipfileset dir="${src.path}/BdfServer_Commands" prefix="${project.name}-${project.version}/BdfServer_Commands"/>
        <zipfileset dir="${src.path}/BdfServer_Html" prefix="${project.name}-${project.version}/BdfServer_Html"/>
        <zipfileset dir="${src.path}/BdfServer_Get" prefix="${project.name}-${project.version}/BdfServer_Get"/>
        <zipfileset dir="${src.path}/BdfServer_JsonProducers" prefix="${project.name}-${project.version}/BdfServer_JsonProducers"/>
        <zipfileset dir="${src.path}/BdfServer_HtmlProducers" prefix="${project.name}-${project.version}/BdfServer_HtmlProducers"/>
		<zipfileset dir="${src.path}/BdfServer_Multi" prefix="${project.name}-${project.version}/BdfServer_Multi"/>
        <zipfileset dir="${src.path}/BDF" prefix="${project.name}-${project.version}/BDF"/>
        <zipfileset file="${vendor.lib.dir}/jdbm.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
        <zipfileset file="${vendor.lib.dir}/sac.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
        <zipfileset file="${vendor.lib.dir}/commons-fileupload.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
        <zipfileset file="${vendor.lib.dir}/commons-io.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
		<zipfileset file="${vendor.lib.dir}/javax.activation.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
        <zipfileset file="${vendor.lib.dir}/javax.mail.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
        <zipfileset file="${vendor.lib.dir}/servlet-api.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
		<zipfileset file="${vendor.lib.dir}/jsoup.jar" prefix="${project.name}-${project.version}/vendor/lib"/>
    </zip>
</target>

<target name="war">
	<zip destFile="${dist.dir}/../${project.webapp_name}##${project.version}.war" duplicate="preserve">
		<zipfileset dir="${dist.dir}/WEB-INF" prefix="WEB-INF"/>
		<zipfileset dir="${dist.dir}/META-INF" prefix="META-INF"/>
	</zip>
</target>

<target name="javax2jakarta" depends="war,webinf">
    <javax2jakarta src="${dist.dir}/../${project.webapp_name}##${project.version}.war" dest="${dist.dir}/../${project.webapp_name}##${project.version}-jakarta.war" profile="tomcat"/>
    <javax2jakarta src="${dist.dir}" dest="${dist.dir}-jakarta" profile="tomcat"/>
    <zip destFile="${dist.dir}/../${project.name}-${project.version}-jakarta-bin.zip" duplicate="preserve">
        <zipfileset dir="${dist.dir}-jakarta/WEB-INF" prefix="${project.name}-${project.version}/WEB-INF"/>
    </zip>
</target>

</project>
