<!-- ===========================================================================
Ant congfiguration for building SDX 2.3

Interesting targets are :

	package				creates the SDX jar
	webapp				creates the SDX war
	clean				cleans the build directory
	dist-src-zip		creates a distribution and zips it
	dist-src-tgz		creates a distribution and targzips it
	dist-clean			cleans the dist directory
	docs-java			creates the javadocs
	docs-html			creates the SDX documentation in HTML
	sdx-cocoon-zip		creates a SDX to be installed over cocoon and zips it
	sdx-cocoon-tgz		creates a SDX to be installed over cocoon and targzips it

============================================================================ -->

<project default="all" basedir="." name="SDX">

<!-- =================================================================== -->
<!-- Initialization target -->
<!-- =================================================================== -->


<target name="init">

        <!-- Detecting the current jvm -->
    <condition property="target.vm" value="1.4">
      <equals arg1="1.4" arg2="${ant.java.version}"/>
    </condition>
    <condition property="target.vm" value="1.3">
      <not>
        <equals arg1="1.4" arg2="${ant.java.version}"/>
      </not>
    </condition>

    <condition property="jvm.subpath" value="vm14">
      <equals arg1="1.4" arg2="${target.vm}"/>
    </condition>
    <condition property="jvm.subpath" value="vm13">
      <not>
        <equals arg1="1.4" arg2="${target.vm}"/>
      </not>
    </condition>

	<!--
	Give user a chance to override without editing this file
	(and without typing -D each time he compiles it)
	-->
    <property file="sdx.properties"/>
    <property file=".ant.properties"/>
    <property file="${user.home}/sdx.properties"/>
    <property file="${user.home}/.ant.properties"/>
    <property name="user.framework" value="sdx"/>

	<!-- Default properties -->
    <property name="include.webapp.libs" value="true"/>

	<!-- These are here only for those who use jikes compiler.
	For other developers this part makes no difference. -->
    <property name="build.compiler.emacs" value="on"/>
    <property name="build.compiler.pedantic" value="false"/>
    <property name="build.compiler.depend" value="true"/>
    <property name="build.compiler.fulldepend" value="true"/>
	<!-- end of jikes properties -->

	<property name="docs.misc.dir" value="./src/documentation/misc"/>
    <property name="javacc.dir" value="./lib"/>
    <property name="javacc.zip" value="${javacc.dir}/JavaCC.zip"/>
    <property name="javacc.jar" value="${javacc.dir}/javacc.jar"/>
    <condition property="native-regexp">
      <not>
        <or>
          <equals arg1="${ant.java.version}" arg2="1.2"/>
          <equals arg1="${ant.java.version}" arg2="1.3"/>
        </or>
      </not>
    </condition>
    <available property="javacc2.present" classname="COM.sun.labs.javacc.Main" classpath="${javacc.zip}"/>
    <available property="javacc3.present" classname="javacc" classpath="${javacc.jar}"/>
    <condition property="javacc.present">
		<or>
			<equals arg1="${javacc2.present}" arg2="true"/>
			<equals arg1="${javacc3.present}" arg2="true"/>
		</or>
    </condition>
    <tstamp/>
    <property name="fullname" value="SDX"/>
    <property name="Name" value="SDX"/>
    <property name="name" value="sdx"/>
    <property name="patched.lucene.jar" value="lucene-patched-${DSTAMP}.jar"/>
    <property name="version" value="2.3b1"/>
    <property name="srcpkg.name.prefix" value="${name}-${version}-${jvm.subpath}"/>
    <property name="jar.name.sdx" value="${srcpkg.name.prefix}.jar"/>
    <property name="war.name.sdx" value="${srcpkg.name.prefix}.war"/>

	<!-- Use the second short.version property for developer builds,
	and the first one for public distributions -->
    <property name="short.version" value="2.3-rc1"/>
    <!--property name="short.version" value="2.3-${DSTAMP}"/-->

    <property name="year" value="2000-2003"/>
    <echo message="--------------------------------------------------------------"/>
    <echo message=" ${fullname} ${version} [${year}] "/>
    <echo message="--------------------------------------------------------------"/>
    <echo message="Building with ${ant.version}"/>
    <echo message="using build file ${ant.file}"/>
    <echo message="--------------------------------------------------------------"/>
    <property name="debug" value="on"/>
    <property name="optimize" value="off"/>
    <property name="deprecation" value="on"/>
    <property name="nowarn" value="off"/>
    <property name="build.compiler" value="modern"/>
    <property name="src.dir" value="./src"/>
    <property name="java.dir" value="${src.dir}/java"/>
    <property name="documentation.dir" value="${src.dir}/documentation"/>
    <property name="lib.dir" value="./lib"/>
    <property name="lib.dir.core" value="${lib.dir}/core"/>
    <property name="lib.dir.optional" value="${lib.dir}/optional"/>
    <property name="tools.dir" value="./tools"/>
    <property name="docs.dir" value="${src.dir}/documentation"/>
    <property name="webapp.dir" value="${src.dir}/webapp"/>
    <property name="packages" value="fr.gouv.culture.*,org.apache.*"/>
    <property name="build.root" value="./build"/>
    <property name="build.dir" value="${build.root}"/>
    <property name="build.lib.dir" value="${build.root}/lib"/>
    <property name="build.src" value="${build.dir}/src"/>
    <property name="build.docs" value="${build.dir}/docs"/>
    <property name="build.dest" value="${build.dir}/classes"/>
    <property name="build.war" value="${build.dir}/webapp"/>
    <property name="build.javadocs" value="${build.docs}/apidocs"/>
    <property name="dist.root" value="./dist"/>
    <property name="dist.name" value="${name}-${version}"/>
    <property name="dist.dir" value="${dist.root}/${dist.name}"/>
    <property name="dist.src.dir" value="${dist.root}/source/${dist.name}"/>
    <property name="dist.bin.dir" value="${dist.root}/bin/${dist.name}"/>
    <property name="dist.target" value="${dist.root}"/>
    <property name="site" value="../xml-site/targets/${name}"/>

	<!-- Properties for SDX documentation -->
	<!-- TODO: do we need that? -->
	<!-- Destinations -->
    <property name="build.docs.fr" value="${build.docs}/fr"/>
    <property name="build.docs.en" value="${build.docs}/fr"/>

	<!-- Sources -->
    <property name="docs.dir.src.fr" value="${docs.dir}/src/xml/fr"/>
    <property name="docs.dir.src.en" value="${docs.dir}/src/xml/en"/>

	<!-- Bins -->
    <property name="docs.dir.bin" value="${docs.dir}/bin"/>

	<!-- The location of tools.jar, relative to the JAVA_HOME home.	-->
    <property name="tools.jar" value="${java.home}/../lib/tools.jar"/>
	<!-- end of SDX documentation properties -->


	<!-- =================================================================== -->
	<!-- Identify Classpath -->
	<!-- =================================================================== -->

	<!-- Classpath for librairies -->
	<path id="classpath">
		<fileset dir="${lib.dir.core}">
			<include name="*.jar"/>
			<exclude name="lucene*.jar"/>
		</fileset>
		<fileset dir="${lib.dir.optional}">
			<include name="*.jar"/>
        </fileset>
		<!-- convenience location for third-party librairies -->
		<fileset dir="${lib.dir}">
			<include name="*.jar"/>
		</fileset>
	</path>

	<!-- Classpath for XSLT processing -->
    <path id="xslt.classpath">
		<fileset dir="./tools/lib">
			<include name="*.jar"/>
		</fileset>
	</path>


	<!-- =================================================================== -->
	<!-- Database configuration -->
	<!-- =================================================================== -->

	<!-- set databases needs -->
    <property name="want.hsql" value="true"/>
    <property name="want.mysql" value="true"/>
    <property name="want.oracle" value="false"/>
    <property name="want.postgresql" value="true"/>

	<!-- check database availability -->
    <condition property="with.hsql">
		<and>
			<istrue value="${want.hsql}"/>
			<available classname="org.hsqldb.Result" classpathref="classpath"/>
		</and>
    </condition>
    <condition property="with.mysql">
		<and>
			<istrue value="${want.mysql}"/>
			<available classname="org.gjt.mm.mysql.ResultSet" classpathref="classpath"/>
		</and>
    </condition>
    <condition property="with.oracle">
		<and>
			<istrue value="${want.oracle}"/>
			<available classname="oracle.jdbc.OracleResultSet" classpathref="classpath"/>
		</and>
    </condition>
    <condition property="with.postgresql">
		<and>
			<istrue value="${want.postgresql}"/>
			<!-- <available classname="???" classpathref="classpath"/> -->
		</and>
    </condition>

    <!-- TODO : what for? -->
    <available file="${tools.jar}" property="tools.jar.present"/>
    <filter token="Name" value="${fullname}"/>
    <filter token="name" value="${fullname}"/>
    <filter token="year" value="${year}"/>
    <filter token="version" value="${version}"/>
    <filter token="date" value="${TODAY}"/>
    <filter token="log" value="true"/>
    <filter token="verbose" value="true"/>
    <filter token="install.war" value="${install.war}"/>
    <taskdef name="versionupdate" classname="com.ryangrier.ant.VersionUpdate" classpath="./tools/lib/version_tool.jar"/>
    <taskdef name="buildupdate" classname="com.ryangrier.ant.BuildUpdate" classpath="./tools/lib/version_tool.jar"/>
</target>


<!-- =================================================================== -->
<!-- Checks if the JavaCC package is avalaible -->
<!-- =================================================================== -->
<target name="javacc_check" depends="init" unless="javacc.present">
	<fail message="JavaCC NOT found">
		##################################################################
		JavaCC not found.
		Was expected in: ${javacc.dir}

		Please download and install JavaCC 3.0 from:
		http://www.experimentalstuff.com/Technologies/JavaCC/

		Then, put a copy of javacc.jar in the place where it was expected
		or create a sdx.properties file either in your home directory,
		or within the same directory as this build.xml file
		and set the javacc.jar property to the path where javacc.jar
		is located or the set javacc.dir property to the path of the folder
		containing the JavaCC.jar file.
		##################################################################
	</fail>
</target>


<!-- =================================================================== -->
<!-- Prepares the build directory -->
<!-- =================================================================== -->
<target name="prepare" depends="init">
	<echo>+-----------------------------| W A R N I N G |---------------------------------+</echo>
    <echo>               This build is targeted for use with JVM ${target.vm}</echo>
    <echo>          Using this build on a virtual machine other than the one</echo>
    <echo>             it is targeted for may result in runtime errors.</echo>
    <echo>+-------------------------------------------------------------------------------+</echo>
    <mkdir dir="${build.dir}"/>
</target>


<!-- =================================================================== -->
<!-- Creates the build directories -->
<!-- =================================================================== -->
<target name="prepare-src" depends="prepare">
    <mkdir dir="${build.src}"/>
    <mkdir dir="${build.lib.dir}"/>
		<path id="buildClasspath">
			<path refid="classpath"/>
			<fileset dir="${build.lib.dir}">
				<include name="*.jar" />
			</fileset>
		</path>
	<mkdir dir="${build.dest}"/>
</target>


<!-- =================================================================== -->
<!-- Excludes the source code for HSQLRepository.java -->
<!-- =================================================================== -->
<target name="exclude-src-hsql" unless="with.hsql">
	<echo>HSQL support will be skipped</echo>
</target>


<!-- =================================================================== -->
<!-- Excludes the source code for MYSQLRepository.java -->
<!-- =================================================================== -->
<target name="exclude-src-mysql" unless="with.mysql">
	<echo>MySQL support will be skipped</echo>
</target>


<!-- =================================================================== -->
<!-- Excludes the source code for ORACLERepository.java -->
<!-- =================================================================== -->
<target name="exclude-src-oracle" unless="with.oracle">
	<echo>Oracle support will be skipped</echo>
</target>


<!-- =================================================================== -->
<!-- Excludes the source code for POSTGRESQLRepository.java -->
<!-- =================================================================== -->
<target name="exclude-src-postgresql" unless="with.postgresql">
	<echo>PostGreSQL support will be skipped</echo>
</target>


<!-- =================================================================== -->
<!-- Prepares the source code -->
<!-- =================================================================== -->
<target name="prepare-src-main" depends="prepare, prepare-src, exclude-src-hsql, exclude-src-mysql, exclude-src-oracle, exclude-src-postgresql">
    <copy todir="${build.src}" filtering="on">
		<fileset dir="${java.dir}">
			<exclude name="**/utils/jvm/**"/>
			<exclude name="**/HSQLRepository.java" unless="with.hsql"/>
			<exclude name="**/MYSQLRepository.java" unless="with.mysql"/>
			<exclude name="**/ORACLERepository.java" unless="with.oracle"/>
			<exclude name="**/POSTGRESQLRepository.java" unless="with.postgresql"/>
			<exclude name="fr/gouv/culture/sdx/search/lucene/queryparser/*.jj"/>
			<exclude name="fr/gouv/culture/sdx/search/lucene/analysis/Analyzer_ar.java" unless="native-regexp"/>
			<exclude name="fr/gouv/culture/sdx/search/lucene/analysis/Glosser_ar_en.java" unless="native-regexp"/>
			<!-- <exclude name="**/oai/"/> -->
		</fileset>
    </copy>

    <!-- Copying appropriate jvm utils to the jvm dir of build src-->
    <mkdir dir="${build.src}/fr/gouv/culture/sdx/utils/jvm"/>
    <copy todir="${build.src}/fr/gouv/culture/sdx/utils/jvm" flatten="true" filtering="on">
		<fileset dir="${java.dir}">
			<include name="**/jvm/${jvm.subpath}/*.java"/>
		</fileset>
    </copy>

	<!-- Copying patched lucene library -->
    <copy tofile="${build.lib.dir}/${patched.lucene.jar}">
		<fileset dir="${lib.dir.core}">
			<include name="lucene*.jar"/>
		</fileset>
	</copy>
</target>


<!-- =================================================================== -->
<!-- Compiles Lucene files -->
<!-- =================================================================== -->
<target name="compile-lucene" depends="prepare-src-main">
	<echo message="Compiling with Java ${ant.java.version}, debug ${debug}, optimize ${optimize}, deprecation ${deprecation}"/>
	<javac srcdir="${build.src}" destdir="${build.dest}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="${target.vm}" nowarn="${nowarn}">
		<include name="org/apache/lucene/**"/>
		<classpath>
			<fileset dir="${lib.dir.core}">
				<include name="lucene*.jar"/>
			</fileset>
		</classpath>
	</javac>
</target>


<!-- =================================================================== -->
<!-- Patches the lucene.jar file with our specific files -->
<!-- =================================================================== -->
<target name="patch-lucene-jar" depends="compile-lucene">
	<jar destfile="${build.lib.dir}/${patched.lucene.jar}" update="true">
		<fileset dir="${build.dest}">
			<include name="org/apache/lucene/**/*.class"/>
		</fileset>
	</jar>
</target>


<!-- =================================================================== -->
<!-- Compiles the query parser with JavaCC 2.x -->
<!-- =================================================================== -->
<target name="compile-query-parser-JavaCC2" depends="javacc_check,patch-lucene-jar" unless="javacc3.present" if="javacc2.present">
	<mkdir dir="${build.src}/fr/gouv/culture/sdx/search/lucene/queryparser"/>
    <javacc target="${src.dir}/java/fr/gouv/culture/sdx/search/lucene/queryparser/DefaultQueryParser.jj" javacchome="${javacc.dir}" outputdirectory="${build.src}/fr/gouv/culture/sdx/search/lucene/queryparser"/>
    <javacc target="${src.dir}/java/fr/gouv/culture/sdx/search/lucene/queryparser/ZeroPositionIncrementTokenQueryParser.jj" javacchome="${javacc.dir}" outputdirectory="${build.src}/fr/gouv/culture/sdx/search/lucene/queryparser"/>
</target>


<!-- =================================================================== -->
<!-- Compiles the query parser with JavaCC 3.x -->
<!-- =================================================================== -->
<target name="compile-query-parser-JavaCC3" depends="javacc_check,patch-lucene-jar" if="javacc3.present">
    <mkdir dir="${build.src}/fr/gouv/culture/sdx/search/lucene/queryparser"/>

	<!-- Hack until Ant is ready to cope with JavaCC 3.0 -->
    <java classname="javacc" fork="true" failonerror="true">
		<arg value="-OUTPUT_DIRECTORY=${build.src}/fr/gouv/culture/sdx/search/lucene/queryparser"/>
		<arg value="${java.dir}/fr/gouv/culture/sdx/search/lucene/queryparser/DefaultQueryParser.jj"/>
		<classpath>
			<pathelement path="${javacc.jar}"/>
		</classpath>
    </java>

    <java classname="javacc" fork="true" failonerror="true">
		<arg value="-OUTPUT_DIRECTORY=${build.src}/fr/gouv/culture/sdx/search/lucene/queryparser"/>
		<arg value="${java.dir}/fr/gouv/culture/sdx/search/lucene/queryparser/ZeroPositionIncrementTokenQueryParser.jj"/>
		<classpath>
			<pathelement path="${javacc.jar}"/>
		</classpath>
	</java>
</target>


<!-- =================================================================== -->
<!-- Patches the build number -->
<!-- =================================================================== -->
<target name="build-number" depends="prepare-src-main">
	<buildupdate srcdir="${build.src}" classname="fr.gouv.culture.sdx.framework.Framework" variablename="BUILD"/>
</target>


<!-- =================================================================== -->
<!-- Compiles the source directory -->
<!-- =================================================================== -->
<target name="compile" depends="build-number,compile-query-parser-JavaCC3,compile-query-parser-JavaCC2">
	<copy todir="${build.dest}">
		<fileset dir="${build.src}">
			<!-- TODO : clean up -->
			<include name="**/Manifest.mf"/>
			<include name="**/*.xsl"/>
			<include name="**/*.roles"/>
			<include name="**/*.xml"/>
			<include name="**/*.properties"/>
			<include name="META-INF/**"/>
		</fileset>
    </copy>

    <echo message="Compiling with Java ${ant.java.version}, debug ${debug}, optimize ${optimize}, deprecation ${deprecation}"/>
    <javac srcdir="${build.src}" destdir="${build.dest}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="${target.vm}" nowarn="${nowarn}">
		<include name="fr/gouv/culture/**"/>
		<classpath refid="buildClasspath" />
    </javac>
    <rmic classname="fr.gouv.culture.sdx.search.lucene.query.RemoteIndex" base="${build.dest}">
		<classpath refid="buildClasspath" />
    </rmic>
</target>


<!-- =================================================================== -->
<!-- Creates the jar file -->
<!-- =================================================================== -->
<target name="all" depends="package" description="Default target" />

<target name="package" depends="compile" description="Generates the SDX jar package">
	<jar jarfile="${build.dir}/${jar.name.sdx}" manifest="${build.src}/Manifest.mf">
		<fileset dir="${build.dest}">
			<include name="fr/**"/>
			<include name="org/**"/>
			<include name="META-INF/**"/>
			<exclude name="org/apache/lucene/**"/>
		</fileset>
    </jar>
</target>

<target name="copy-jar" depends="package">
	<copy file="${build.dir}/${jar.name.sdx}" tofile="${user.webapps}/${user.framework}/WEB-INF/lib/${name}-${jvm.subpath}.jar"/>
</target>


<!-- =================================================================== -->
<!-- Copies the tools.jar to javac.jar in web-inf/lib -->
<!-- =================================================================== -->
<target name="prepare-tools-lib" depends="package" if="tools.jar.present" unless="pizza.present">
	<!-- NOTE: java.home is normally set by the JVM to the /jre directory  -->
    <copy file="${tools.jar}" tofile="${build.war}/WEB-INF/lib/javac.jar"/>
</target>


<!-- =================================================================== -->
<!-- Compiles a loader for Jetty -->
<!-- =================================================================== -->
<target name="compile-jetty-loader">
	<mkdir dir="tools/loader" />
    <javac srcdir="tools/src/loader" destdir="tools/loader" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="1.3" nowarn="${nowarn}" />
</target>


<!-- =================================================================== -->
<!-- Creates the distribution war file including the documentation -->
<!-- =================================================================== -->
<target name="dist-war" depends="copy-webapp, prepare-webapp-libs, prepare-xsp, docs-java, docs-html">
	<!-- copy the documentation, it's already prepared in the build context dir -->
	<mkdir dir="${build.war}/sdx/documentation"/>
	<copy todir="${build.war}/sdx/documentation">
		<fileset dir="${build.docs}">
			<exclude name="apidocs"/>
		</fileset>
	</copy>
	<!-- correct the image references -->
	<!-- <replace dir="${build.war}/documentation/svg" token="context://images" value="context://documentation/images"/> -->
    <jar jarfile="${build.dir}/${war.name.sdx}" basedir="${build.war}" includes="**"/>
</target>


<!-- =================================================================== -->
<!-- Prepares the libraries for the war package -->
<!-- =================================================================== -->
<target name="prepare-xsp" depends="package" if="build.precompile">
	<java classname="org.apache.cocoon.Main" fork="yes" failonerror="true">
		<arg line="-P -C ${build.war}/WEB-INF/cocoon.xconf -w ${build.war}/WEB-INF/classes -c ${build.war}"/>
		<classpath>
			<path refid="buildClasspath"/>
			<pathelement location="${build.war}/WEB-INF/classes"/>
			<pathelement location="${build.dir}/${name}-${jvm.subpath}.jar"/>
			<pathelement location="${tools.jar}"/>
		</classpath>
	</java>
</target>


<!-- ======================================================================= -->
<!-- Creates the war file -->
<!-- ======================================================================= -->
<target name="webapp" depends="compile-jetty-loader, copy-webapp, prepare-webapp-libs, prepare-xsp" description="Generates the SDX war package">
    <jar jarfile="${build.dir}/${war.name.sdx}" basedir="${build.war}" includes="**"/>
    <echo message="--------------------------------------------------------------"/>
    <echo message=""/>
    <echo message="Use the 'create-docs.bat' command line"/>
    <echo message="to create the documentation of the project."/>
    <echo message=""/>
    <echo message="Utilisez la commande 'create-docs.bat'"/>
    <echo message="pour générer la documentation du projet."/>
    <echo message="--------------------------------------------------------------"/>
</target>


<!-- =================================================================== -->
<!-- Removes existing uncompressed webapp -->
<!-- =================================================================== -->
<target name="remove-webapp" if="remove.webapp" depends="init">
	<delete dir="${install.war}/${name}"/>
</target>


<!-- =================================================================== -->
<!-- Set a variable if javadoc is already up-to-date. -->
<!-- =================================================================== -->
<target name="javadocs_check">
	<uptodate property="javadocs.notrequired" targetfile="${build.javadocs}/packages.html">
		<srcfiles dir="${build.src}" includes="**/*.java"/>
    </uptodate>
</target>


<!-- =================================================================== -->
<!-- If javadoc is already up-to-date, print a message saying so. -->
<!-- =================================================================== -->
<target name="javadocs_done" if="javadocs.notrequired">
	<echo message="-------------------------------------------------------------"/>
    <echo message="Not rebuilding Javadocs, as they are up-to-date:"/>
    <echo message=" ${build.javadocs}/packages.html is more recent than"/>
    <echo message=" ${build.src}/**/*.java"/>
    <echo message="-------------------------------------------------------------"/>
</target>


<!-- =================================================================== -->
<!-- Creates the API documentation -->
<!-- =================================================================== -->
<target name="docs-java" depends="compile, javadocs_check, javadocs_done" unless="javadocs.notrequired" description="Generates the API documentation">
	<mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" classpathref="buildClasspath"
		author="true" version="true" use="false" noindex="false" windowtitle="${Name} ${version} API" doctitle="${Name} ${version}"
		bottom="Copyright &#169; ${year} Ministere de la culture et de la communication / AJLSM. All Rights Reserved.">
    </javadoc>
</target>


<!-- =================================================================== -->
<!-- Creates the source distribution -->
<!-- =================================================================== -->
<target name="dist-src" depends="docs-java, docs-html">
	<!-- Simply copy all and add the html docs -->
    <mkdir dir="${dist.root}"/>
    <mkdir dir="${dist.src.dir}"/>
    <mkdir dir="${dist.src.dir}/bin"/>
    <mkdir dir="${dist.src.dir}/lib"/>
    <mkdir dir="${dist.src.dir}/src"/>
    <mkdir dir="${dist.src.dir}/src/java"/>
    <mkdir dir="${dist.src.dir}/src/documentation"/>
    <mkdir dir="${dist.src.dir}/src/webapp"/>
    <mkdir dir="${dist.src.dir}/src/documentation"/>
    <mkdir dir="${dist.src.dir}/docs"/>
    <mkdir dir="${dist.src.dir}/docs/apidocs"/>
    <mkdir dir="${dist.src.dir}/tools"/>
    <copy todir="${dist.src.dir}/tools">
		<fileset dir="${tools.dir}"/>
    </copy>
    <copy todir="${dist.src.dir}/lib">
		<fileset dir="${lib.dir}"/>
    </copy>
    <copy todir="${dist.src.dir}/src/java" filtering="on">
		<fileset dir="${java.dir}"/>
    </copy>
    <copy todir="${dist.src.dir}/src/documentation" filtering="off">
		<fileset dir="${docs.dir}"/>
    </copy>
    <copy todir="${dist.src.dir}/src/webapp" filtering="on">
		<fileset dir="${webapp.dir}">
			<exclude name="**/*.gif"/>
			<exclude name="**/*.jpg"/>
			<exclude name="**/*.png"/>
		</fileset>
    </copy>
    <copy todir="${dist.src.dir}/src/webapp" filtering="off">
		<fileset dir="${webapp.dir}">
			<include name="**/*.gif"/>
			<include name="**/*.jpg"/>
			<include name="**/*.png"/>
		</fileset>
    </copy>
	<!-- All the documentation -->
    <copy todir="${dist.src.dir}/docs">
		<fileset dir="${build.docs}"/>
    </copy>
    <copy todir="${dist.src.dir}">
		<fileset dir="${docs.dir}">
			<include name="changes.xml, todo.xml"/>
		</fileset>
    </copy>
    <copy todir="${dist.src.dir}" filtering="on">
		<fileset dir=".">
			<include name="README"/>
			<include name="INSTALL"/>
			<include name="LICENSE"/>
			<include name="legal/*"/>
			<include name="*.bat"/>
			<include name="*.sh"/>
			<include name="*.xml"/>
		</fileset>
    </copy>
    <fixcrlf srcdir="${dist.src.dir}" includes="**.sh" eol="lf"/>
    <fixcrlf srcdir="${dist.src.dir}" includes="antRun" eol="lf"/>
    <fixcrlf srcdir="${dist.src.dir}" includes="**.bat" eol="crlf"/>
    <chmod perm="+x" file="${dist.src.dir}/run.sh"/>
    <chmod perm="+x" file="${dist.src.dir}/build.sh"/>
    <chmod perm="+x" file="${dist.src.dir}/tools/bin/antRun"/>
</target>


<!-- =================================================================== -->
<!-- Packages the source distribution as .zip -->
<!-- =================================================================== -->
<target name="dist-src-zip" depends="dist-src" description="Generates the source distribution as a .zip file">
	<zip zipfile="${dist.target}/${dist.name}-src.zip" basedir="${dist.root}/source"/>
</target>

<!-- =================================================================== -->
<!-- Packages the source distribution with .tar.gzip -->
<!-- =================================================================== -->
<target name="dist-src-tgz" depends="dist-src" description="Generates the source distribution as a .tar.gz file">
	<tar tarfile="${dist.target}/${dist.name}-src.tar" basedir="${dist.root}/source" longfile="gnu"/>
    <gzip zipfile="${dist.target}/${dist.name}-src.tar.gz" src="${dist.target}/${dist.name}-src.tar"/>
</target>


<!-- =================================================================== -->
<!-- Build all distributions -->
<!-- =================================================================== -->
<target name="dist" depends="dist-src-tgz, dist-src-zip"/>

<!-- =================================================================== -->
<!-- Clean targets -->
<!-- =================================================================== -->
<!-- local cleanup -->
<target name="clean" depends="init" description="Cleans the build directories">
	<delete dir="${build.dir}"/>
</target>

<!-- distant cleanup -->
<target name="distclean" depends="clean" description="Cleans everything to the original state">
	<delete dir="${build.root}"/>
    <delete file="${dist.target}/${Name}-${version}.tar.gz"/>
    <delete file="${dist.target}/${Name}-${version}.tar"/>
    <delete file="${dist.target}/${Name}-${version}.zip"/>
    <delete file="${dist.target}/${Name}-${version}-src.tar.gz"/>
    <delete file="${dist.target}/${Name}-${version}-src.tar"/>
    <delete file="${dist.target}/${Name}-${version}-src.zip"/>
    <delete file="${dist.target}/${Name}-${version}-bin.tar.gz"/>
    <delete file="${dist.target}/${Name}-${version}-bin.tar"/>
    <delete file="${dist.target}/${Name}-${version}-bin.zip"/>
    <delete dir="${dist.root}"/>
</target>


<!-- =================================================================== -->
<!--
About this target :

		Building the documentation for SDX involves mainly transformations
		using XSLT, with the Website publishing system. This process is done in
        tow steps, the first will build autolayout files from the layout files
        manually created, and the second step will process this autolayout
        file to create all the HTML files with links, figures and navigation
        properly organized.

        For figures, we simply copy them from the source directories to the
        target directories.

        In this build file, we currently support french and english documentation.
-->
<!-- =================================================================== -->
<target name="docs-html" depends="init" description="Build the SDX documentation">
	<!--
	Please note :
        It seems that using the classpath or classpathref attribute doesn't
        work with the style task.
	-->

	<!-- First step : build autolayout files -->
    <style style="${docs.dir.bin}/layout/autolayout.xsl" in="${docs.dir.src.fr}/layout.xml" out="${docs.dir.src.fr}/autolayout.xml" processor="trax"/>
    <style style="${docs.dir.bin}/layout/autolayout.xsl" in="${docs.dir.src.en}/layout.xml" out="${docs.dir.src.en}/autolayout.xml" processor="trax"/>

	<!-- Second step : process the files using autolayout.xml -->
	<!-- We will define properties to be consistent between languages -->
    <property name="path-to-resources" value=".."/>
    <property name="xmlDir" value="${docs.dir}/src/xml"/>
    <property name="output-root" value="${build.docs}"/>
    <property name="navbgcolor" value="#6287C4"/>
    <property name="toc.spacer.image" value="${path-to-resources}/graphics/blank.png"/>
    <property name="toc.pointer.image" value="${path-to-resources}/graphics/blank.png"/>
    <property name="toc.blank.image" value="${path-to-resources}/graphics/blank.png"/>
    <property name="nav.icon.path" value="${path-to-resources}/graphics/navicons/"/>
    <property name="suppress.homepage" value="1"/>
    <property name="footer.hr" value="0"/>
    <property name="navig.graphics.extension" value=".png"/>
    <property name="admon.graphics.extension" value=".png"/>
    <property name="nav.icon.extension" value=".png"/>
    <property name="rebuild-all" value="1"/>

	<!-- We process the french documentation -->
    <style style="${docs.dir.bin}/html/chunk-tabular-driver.xsl" in="${docs.dir.src.fr}/autolayout.xml" out="${build.docs}/temp.xml" processor="trax">
		<param name="xmlDir" expression="${xmlDir}/fr"/>
		<param name="output-root" expression="${output-root}/fr"/>
		<param name="navbgcolor" expression="${navbgcolor}"/>
		<param name="toc.spacer.image" expression="${toc.spacer.image}"/>
		<param name="toc.pointer.image" expression="${toc.pointer.image}"/>
		<param name="toc.blank.image" expression="${toc.blank.image}"/>
		<param name="nav.icon.path" expression="${nav.icon.path}"/>
		<param name="suppress.homepage" expression="${suppress.homepage}"/>
		<param name="footer.hr" expression="${footer.hr}"/>
		<param name="navig.graphics.extension" expression="${navig.graphics.extension}"/>
		<param name="admon.graphics.extension" expression="${admon.graphics.extension}"/>
		<param name="nav.icon.extension" expression="${nav.icon.extension}"/>
		<param name="rebuild-all" expression="1"/>
    </style>

	<!-- We process the english documentation -->
    <delete file="${build.docs}/temp.xml"/>
    <style style="${docs.dir.bin}/html/chunk-tabular-driver.xsl" in="${docs.dir.src.en}/autolayout.xml" out="${build.docs}/temp.xml" processor="trax">
		<param name="xmlDir" expression="${xmlDir}/en"/>
		<param name="output-root" expression="${output-root}/en"/>
		<param name="navbgcolor" expression="${navbgcolor}"/>
		<param name="toc.spacer.image" expression="${toc.spacer.image}"/>
		<param name="toc.pointer.image" expression="${toc.pointer.image}"/>
		<param name="toc.blank.image" expression="${toc.blank.image}"/>
		<param name="nav.icon.path" expression="${nav.icon.path}"/>
		<param name="suppress.homepage" expression="${suppress.homepage}"/>
		<param name="footer.hr" expression="${footer.hr}"/>
		<param name="navig.graphics.extension" expression="${navig.graphics.extension}"/>
		<param name="admon.graphics.extension" expression="${admon.graphics.extension}"/>
		<param name="nav.icon.extension" expression="${nav.icon.extension}"/>
		<param name="rebuild-all" expression="1"/>
    </style>

	<!-- copy the schemas -->
    <copy todir="${build.docs}/schemas" filtering="off">
		<fileset dir="${docs.dir}/src/xml/schemas"/>
    </copy>

	<!-- copy the sample documents -->
    <copy todir="${build.docs}/samples" filtering="off">
		<fileset dir="${docs.dir}/src/xml/samples"/>
    </copy>

	<!-- Copy the resources -->
    <copy todir="${build.docs}" filtering="off">
		<fileset dir="${docs.dir}/resources/html"/>
    </copy>

	<!-- Copy non-xml files from the source directories -->
    <copy todir="${build.docs}/fr" filtering="off">
		<fileset dir="${docs.dir.src.fr}">
			<exclude name="**/*.xml"/>
		</fileset>
    </copy>
    <copy todir="${build.docs}/en" filtering="off">
		<fileset dir="${docs.dir.src.en}">
			<exclude name="**/*.xml"/>
		</fileset>
    </copy>

	<!-- Delete temporary files -->
    <delete file="${docs.dir.src.fr}/autolayout.xml"/>
    <delete file="${docs.dir.src.en}/autolayout.xml"/>
    <delete file="${build.docs}/temp.xml"/>
</target>


<!-- =================================================================== -->
<!-- Copies the webapp directories -->
<!-- =================================================================== -->
<target name="copy-webapp" depends="prepare, compile">
	<mkdir dir="${build.war}"/>
	<mkdir dir="${build.war}/WEB-INF/classes"/>
    <copy todir="${build.war}/WEB-INF/classes" filtering="off">
		<fileset dir="${build.dest}" includes="org/apache/cocoon/samples/**"/>
		<fileset dir="${build.src}" includes="org/apache/cocoon/samples/**"/>
    </copy>
    <!-- first launch warning fix -->
    <mkdir dir="${build.war}/WEB-INF/logs"/>

    <copy todir="${build.war}" filtering="on">
		<fileset dir="${webapp.dir}">
			<exclude name="**/*.gif"/>
			<exclude name="**/*.jpg"/>
			<exclude name="**/*.png"/>
			<exclude name="**/i18n/**"/>
			<exclude name="**/db/*"/>
		</fileset>
    </copy>
    <copy todir="${build.war}" filtering="off">
		<fileset dir="${webapp.dir}">
			<include name="**/*.gif"/>
			<include name="**/*.jpg"/>
			<include name="**/*.png"/>
			<include name="**/i18n/**"/>
			<include name="**/db/*"/>
			<include name="**/CatalogManager.properties"/>
		</fileset>
    </copy>
</target>


<!-- =================================================================== -->
<!-- Prepares the libraries for the war package -->
<!-- =================================================================== -->
<target name="prepare-webapp-libs" depends="package,prepare-tools-lib" if="include.webapp.libs">
	<copy todir="${build.war}/WEB-INF/lib">
		<fileset dir="${lib.dir.core}">
			<include name="*.jar"/>
			<exclude name="servlet*.jar"/>
			<exclude name="lucene*.jar"/>
		</fileset>
    </copy>
    <copy todir="${build.war}/WEB-INF/lib">
		<fileset dir="${lib.dir.optional}">
			<include name="*.jar"/>
			<exclude name="servlet*.jar"/>
		</fileset>
    </copy>
    <copy todir="${build.war}/WEB-INF/lib">
		<fileset dir="${build.lib.dir}">
			<include name="*.jar"/>
			<exclude name="servlet*.jar"/>
		</fileset>
    </copy>
    <copy file="${build.dir}/${jar.name.sdx}" tofile="${build.war}/WEB-INF/lib/${jar.name.sdx}"/>
</target>


<!-- =================================================================== -->
<!-- Install SDX over an existing cocoon webapp -->
<!-- =================================================================== -->
<target name="sdx-cocoon" depends="prepare, compile, prepare-xsp">

	<!-- Copy the needed jar to the cocoon lib dir -->
	<copy todir="${build.war}/WEB-INF/lib">
		<fileset dir="${lib.dir.core}">
			<include name="ArabicAnalyzer.jar"/>
			<include name="cocoon-portal-fw-block.jar"/>
			<include name="excalibur-concurrent-20020820.jar"/>
			<include name="jtidy-sdx.jar"/>
		</fileset>
    </copy>
    <copy todir="${build.war}/WEB-INF/lib">
		<fileset dir="${lib.dir.optional}">
			<include name="javac.jar"/>
			<include name="mm.mysql-2.0.11-bin.jar"/>
			<include name="saxon-6.5.3.jar"/>
		</fileset>
    </copy>
    <copy todir="${build.war}/WEB-INF/lib">
		<fileset dir="${build.lib.dir}">
			<include name="*.jar"/>
			<exclude name="servlet*.jar"/>
		</fileset>
    </copy>
    <copy file="${build.dir}/${jar.name.sdx}" tofile="${build.war}/WEB-INF/lib/${jar.name.sdx}"/>

    <copy todir="${build.war}" filtering="on">
		<fileset dir="${webapp.dir}">
			<exclude name="**/*.gif"/>
			<exclude name="**/*.jpg"/>
			<exclude name="**/*.png"/>
			<exclude name="**/i18n/**"/>
			<exclude name="**/db/*"/>
		</fileset>
    </copy>
    <copy todir="${build.war}" filtering="off">
		<fileset dir="${webapp.dir}">
			<include name="**/*.gif"/>
			<include name="**/*.jpg"/>
			<include name="**/*.png"/>
			<include name="**/i18n/**"/>
			<include name="**/db/*"/>
			<include name="**/CatalogManager.properties"/>
		</fileset>
    </copy>

	<!-- rename configuration files -->
	<move file="${build.war}/WEB-INF/cocoon.xconf" tofile="${build.war}/WEB-INF/cocoon.xconf.sdx"/>
	<move file="${build.war}/WEB-INF/logkit.xconf" tofile="${build.war}/WEB-INF/logkit.xconf.sdx"/>
	<move file="${build.war}/WEB-INF/web.xml" tofile="${build.war}/WEB-INF/web.xml.sdx"/>

	<!-- copy install documentation -->
    <copy todir="${build.war}" filtering="off">
		<fileset dir="${docs.misc.dir}" includes="*.txt"/>
    </copy>

</target>


<!-- =================================================================== -->
<!-- Creates a SDX to be installed over cocoon and zips it -->
<!-- =================================================================== -->
<target name="sdx-cocoon-zip" depends="sdx-cocoon" description="Creates a SDX to be installed over cocoon and zips it">
	<zip zipfile="${build.dir}/${name}-cocoon.zip" basedir="${build.war}"/>
</target>


<!-- =================================================================== -->
<!-- Creates a SDX to be installed over cocoon and targzips it -->
<!-- =================================================================== -->
<target name="sdx-cocoon-tgz" depends="sdx-cocoon" description="Creates a SDX to be installed over cocoon and targzips it">
	<tar tarfile="${build.dir}/${name}-cocoon.tar" basedir="${build.war}" longfile="gnu"/>
    <gzip zipfile="${build.dir}/${name}-cocoon.tar.gz" src="${build.dir}/${name}-cocoon.tar"/>
</target>


</project>
<!-- End of file -->
