<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
System Environment Variables Used By The Build File
JAVA_HOME - Root Directory of the Java Development Kit
-->

<project name="olat" default="Usage" basedir=".">

<!-- ================================= Usage ===================================== -->
	<target name="Usage" description="Displays Usage Help">
		<echo>
	Welcome to the OLAT build and configuration tasks. Setup a new system using 
	the following tasks:

	**  Make sure you copied build.properties.default to build.properties and did **
	**  modify all values accordingly!                                            **
			
	Automatic (recommended):
	ant install             - Do just everything
    ant dbsetup             - Setup DB (MySQL)	    
	ant dbsetup_postgreSQL  - Alternatively: setup DB (PostgreSQL)
			
	Manually: 
    ant clean               - Scrub temporary files
    ant build               - Build whole project (without scrubbing)
    ant config-all          - Configure everything and deploy the configuration
    ant dbsetup             - Setup DB (MySQL)	    
	ant dbsetup_postgreSQL  - Alternatively: setup DB (PostgreSQL)
			
	Deployment: 
	ant deploy				- copies a context.xml file to your 
							  tomcat/conf/Catalina/localhost/ dir
	ant undeploy			- Removes the context descriptor
    
    Note: Use ant -projecthelp to see all targets with a short description.
	    </echo>
	</target>


<!-- ============================ Init Ant  ===================================== -->
	<target name="init-ant" description="Initialize the ant build system.">
		<!-- set project environment -->
		<dirname property="project.home" file="${ant.file}"/>
		<dirname property="project.parentdir" file="${project.home}"/>		
		<record name="${project.home}/build.log" append="no" />
		<tstamp/>		
		<!-- check if build.properties file exists -->
        <available property="build.properties.exists" file="${project.home}/build.properties" />
		<fail message="Did not found the build.properties file at ${project.home}/build.properties, you must copy the ${project.home}/build.properties.default first!">
		     <condition>
		       <not><isset property="build.properties.exists"/></not>
		     </condition>
		</fail>
		
		<!-- load configuration properties -->
		<property file="${project.home}/build.properties" />
		<!-- load layout properties -->
		<property file="${project.home}/layout.properties" />
		<property name="Name" value="OLAT"/>
		<property name="version" value="${build.version}"/>
		<property name="vName" value="${Name}-${version}"/>
		<property name="project.dir" value=".."/>
		<property name="lib.svn" value="/usr/local/opt/ant/lib/commons-lang-2.0.jar:/usr/local/opt/ant/lib/jakarta-regexp-1.3.jar:/usr/local/opt/ant/lib/svnant.jar:/usr/local/opt/ant/lib/svnant.jar:/usr/local/opt/ant/lib/svnClientAdapter.jar:/usr/local/opt/ant/lib/svnjavahl.jar" />
		<!-- check-style properties -->
        <property name="checkstyle.jar.dir" value="${basedir}/test" />
        <property name="checkstyle.config.dir" value="${basedir}/test/checkstyle-config" />
        <property name="checkstyle.jar" value="${checkstyle.jar.dir}/checkstyle-all-4.1.jar" />
        <property name="checkstyle.config" value="${checkstyle.config.dir}/olat-checkstyle.xml" />
		
	</target>

<!-- ============================ Set Classpath  ================================ -->
	<target name="init-classpath" description="Initialize the java classpath.">
 		<mkdir dir="${webapp.dir}/WEB-INF/classes" />

	 	 <!-- classpath properties -->
		<path id="classpath.compile">
			<fileset dir="${webapp.dir}/WEB-INF/lib">
			<include name="**/*.jar" />
			</fileset>
			<pathelement location="${tomcat.home}/common/lib/servlet.jar"/> <!-- tomcat 4.x -->
			<pathelement location="${tomcat.home}/common/lib/servlet-api.jar"/>	<!-- tomcat 5.x -->
			<pathelement location="${tomcat.home}/common/lib/naming-resources.jar"/>
		</path>
	
		<path id="classpath.deploy">
			<path refid="classpath.compile"/>
			<pathelement location="${webapp.dir}/WEB-INF/classes/"/>
		</path>
	</target>
	
<!-- ================================ Init ==================================== -->
	<target name="init" depends="init-ant">
		<record name="${project.home}/build.log" append="no" />
		<tstamp/>
		
		<echo>	
        Build started: ${TSTAMP} on ${TODAY}
        Build:  ${vName}
        
        project.home = ${project.home}
 		</echo>

		<!-- generate directories -->
		<antcall target="init-filesystem" />
	</target>
	
<!-- ================================ Init filesystem ======================== -->
	<target name="init-filesystem" depends="init-ant">
		<mkdir dir="${temp.dir}" />
		<mkdir dir="${build.dir}" />
		<mkdir dir="${userdata.dir}" />
		<mkdir dir="${log.dir}" />
		<mkdir dir="${mrtgbackup.dir}" />
		<chmod dir="${base.dir}/bin" perm="ugo+rx" includes="**/*.sh"/>
	</target>
	

<!-- ================================ Clean ==================================== -->
	<target name="clean" depends="init-ant" description="Clean all build products">
		<delete dir="${build.dir}" /> 
		<delete dir="${dist.dir}" /> 
		<delete dir="${log.dir}" />
		<delete dir="${temp.dir}" /> 
		<delete dir="${doc.api.dir}" />
		<delete dir="${junit.doc.dir}" />
		<mkdir dir="${build.dir}" /> 
		<mkdir dir="${dist.dir}" /> 
		<mkdir dir="${log.dir}" />
		<mkdir dir="${mrtgbackup.dir}" />
		<mkdir dir="${temp.dir}" />
		<mkdir dir="${doc.dir}" />
		<mkdir dir="${doc.api.dir}" />
		<mkdir dir="${junit.doc.dir}" />
	</target>

<!-- ========================== Compile ============================== -->
	<target name="compile" depends="init-ant, init-classpath" description="Compile all">
		<javac srcdir="${source.dir}:${source.patches.dir}"
			destdir="${build.dir}"
			classpathref="classpath.compile"
			includes="**/*.java,**/*.properties"
			debug="on"
			nowarn="on"
			deprecation="off"
			failonerror="${failonerror.compile}"
			compiler="${build.compiler}"
			encoding="UTF-8"
			source="1.5"/>
	</target>

<!-- =========================== Copy non java files =========================== -->
	<target name="copy-resources" depends="init-ant" description="Copy non source files to classes directory">
		<copy toDir="${build.dir}">
			<fileset dir="${source.dir}/" excludes="**/*.java" />
			<fileset dir="${source.patches.dir}/" excludes="**/*.java" />
		</copy>
	</target>

<!-- =========================== CVS update package from HEAD ==================== -->
	<target name="checkout" depends="init-ant" description="Update package from CVS">
		<cvs cvsRsh="${cvs.cvsrsh}" cvsRoot="${cvs.repository}" package="${cvs.package}" dest=".." quiet="yes" /> 
	</target>
	
<!-- =========================== SVN update package from HEAD ==================== -->
	<target name="SVNcheckout" depends="init-ant" description="Update package from SVN">
		<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpath="${lib.svn}" />
	    <svn>
	      <checkout url="${svn.url}" destPath="${svn.dest.path}" />
	    </svn>
	</target>
	
<!-- ================================ Build ==================================== -->
	<target name="build" depends="init-ant,compile,copy-resources" description="Run builds">
	</target>

<!-- ================================ Build Clean ============================== -->
	<target name="build-clean" depends="clean,build">
	</target>

<!-- ======================= Tomcat and OLAT configuration files =========================== -->
	<target name="config-olat" depends="init-ant, init" description="Process all .in files and generate configured files">
		
		<!-- olat_config.xml.in -->
		<echo message="Processing config file ${olatconfig.file}..." />
		<copy overwrite="true" file="${olatconfig.file}.in" tofile="${olatconfig.file}" encoding="utf-8" />
		
		<replace file="${olatconfig.file}" encoding="utf-8" >
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
			<replacefilter token="@server.contextpath@" value="${server.contextpath}"/>
			<replacefilter token="@server.port@" value="${server.port}"/>
			<replacefilter token="@server.port.ssl@" value="${server.port.ssl}"/>

			<replacefilter token="@db.dbms@" value="${db.dbms}"/>
			<replacefilter token="@instance.id@" value="${instance.id}"/>
			<replacefilter token="@adminemail@" value="${adminemail}"/>
			<replacefilter token="@supportemail@" value="${supportemail}"/>
			<replacefilter token="@db.host@" value="${db.host}"/>
			<replacefilter token="@db.name@" value="${db.name}"/>
			<replacefilter token="@db.user@" value="${db.user}"/>
			<replacefilter token="@db.pass@" value="${db.pass}"/>

			<replacefilter token="@db.show_sql@" value="${db.show_sql}"/>
			<replacefilter token="@db.jdbc.url@" value="${db.jdbc.url}"/>

			<replacefilter token="@db.test.user@" value="${db.test.user}"/>
			<replacefilter token="@db.test.pass@" value="${db.test.pass}"/>
			<replacefilter token="@db.test.jdbc.url@" value="${db.test.jdbc.url}"/>
			
			<replacefilter token="@folder.maxulmb@" value="${folder.maxulmb}"/>
			<replacefilter token="@folder.quotamb@" value="${folder.quotamb}"/>
			<replacefilter token="@folder.tmpdir@" value="${folder.tmpdir}"/>
			<replacefilter token="@folder.root@" value="${folder.root}"/>
			<replacefilter token="@defaultlang@" value="${defaultlang}"/>
			<replacefilter token="@defaultcharset@" value="${defaultcharset}"/>
			<replacefilter token="@registration.enableSelfRegistration@" value="${registration.enableSelfRegistration}"/>
			<replacefilter token="@registration.enableNotificationEmail@" value="${registration.enableNotificationEmail}"/>
			<replacefilter token="@registration.notificationEmail@" value="${registration.notificationEmail}"/>
			<replacefilter token="@smtp.host@" value="${smtp.host}"/>
			<replacefilter token="@userdata.dir@" value="${userdata.dir}"/>			
			<replacefilter token="@olat.debug@" value="${olat.debug}"/>	
			<replacefilter token="@localization.cache@" value="${localization.cache}"/>
			<replacefilter token="@user.generateTestUsers@" value="${user.generateTestUsers}"/>	
			<replacefilter token="@velocity.cache.pages@" value="${velocity.cache.pages}"/>
			<replacefilter token="@velocity.input.encoding@" value="${velocity.input.encoding}"/>
			<replacefilter token="@velocity.output.encoding@" value="${velocity.output.encoding}"/>
			<replacefilter token="@shibboleth.enable@" value="${shibboleth.enable}"/>
			<replacefilter token="@shibboleth.providerId@" value="${shibboleth.providerId}"/>
			<replacefilter token="@shibboleth.sites.config@" value="${shibboleth.sites.config}"/>
			<replacefilter token="@shibboleth.aap.config@" value="${shibboleth.aap.config}"/>
			<replacefilter token="@shibboleth.sites.reloadmin@" value="${shibboleth.sites.reloadmin}"/>
			<replacefilter token="@shibboleth.keystore@" value="${shibboleth.keystore}"/>
			<replacefilter token="@shibboleth.keystore.type@" value="${shibboleth.keystore.type}"/>
			<replacefilter token="@shibboleth.keystore.pass@" value="${shibboleth.keystore.pass}"/>
			<replacefilter token="@shibboleth.key.pass@" value="${shibboleth.key.pass}"/>
			<replacefilter token="@shibboleth.truststore@" value="${shibboleth.truststore}"/>
			<replacefilter token="@shibboleth.truststore.type@" value="${shibboleth.truststore.type}"/>
			<replacefilter token="@shibboleth.truststore.pass@" value="${shibboleth.truststore.pass}"/>
			<replacefilter token="@shibboleth.defaultUID@" value="${shibboleth.defaultUID}"/>
			<replacefilter token="@default.auth.provider@" value="${default.auth.provider}"/>
			<replacefilter token="@language.enable@" value="${language.enable}"/>
			<replacefilter token="@language.param@" value="${language.param}"/>
			<replacefilter token="@instantMessaging.enable@" value="${instantMessaging.enable}"/>
			<replacefilter token="@instantMessaging.generateTestUsers@" value="${instantMessaging.generateTestUsers}"/>
			<replacefilter token="@instantMessaging.server.name@" value="${instantMessaging.server.name}"/>
			<replacefilter token="@instantMessaging.admin.username@" value="${instantMessaging.admin.username}"/>
			<replacefilter token="@instantMessaging.admin.password@" value="${instantMessaging.admin.password}"/>
			<replacefilter token="@generate.index.at.startup@" value="${generate.index.at.startup}"/>
			<replacefilter token="@restart.window.start@" value="${restart.window.start}"/>
			<replacefilter token="@restart.window.end@" value="${restart.window.end}"/>
		</replace>
		<echo message="Generated config file available at ${olatconfig.file}" />

		<!-- web.xml.in -->
		<echo message="Processing config file ${tomcat.web.xml.file}..." />
		<copy overwrite="true" file="${tomcat.web.xml.file}.in" tofile="${tomcat.web.xml.file}" />
		<replace file="${tomcat.web.xml.file}">
			<replacefilter token="@webxml.webdav.inbuffer@" value="${webxml.webdav.inbuffer}"/>
			<replacefilter token="@webxml.webdav.outbuffer@" value="${webxml.webdav.outbuffer}"/>
		</replace>
		<echo message="Generated config file available at ${tomcat.web.xml.file}" />

		<!-- server.xml.in -->
		<echo message="Processing config file ${tomcat.server.xml.file}..." />
		<copy overwrite="true" file="${tomcat.server.xml.file}.in" tofile="${tomcat.server.xml.file}" />
		
		<!-- set comment tags for the tomcat connector that is used-->
		<condition property="connector.jk.comment.start" value="">
			<equals arg1="${server.modjk.enabled}" arg2="true" />
		</condition>
		<condition property="connector.jk.comment.start" value="&lt;!--">
			<equals arg1="${server.modjk.enabled}" arg2="false" />
		</condition>
		<condition property="connector.jk.comment.end" value="">
			<equals arg1="${server.modjk.enabled}" arg2="true" />
		</condition>
		<condition property="connector.jk.comment.end" value="--&gt;">
			<equals arg1="${server.modjk.enabled}" arg2="false" />
		</condition>
		<condition property="connector.http.comment.start" value="&lt;!--">
			<equals arg1="${server.modjk.enabled}" arg2="true" />
		</condition>
		<condition property="connector.http.comment.start" value="">
			<equals arg1="${server.modjk.enabled}" arg2="false" />
		</condition>
		<condition property="connector.http.comment.end" value="--&gt;">
			<equals arg1="${server.modjk.enabled}" arg2="true" />
		</condition>
		<condition property="connector.http.comment.end" value="">
			<equals arg1="${server.modjk.enabled}" arg2="false" />
		</condition>

		<replace file="${tomcat.server.xml.file}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
			<replacefilter token="@server.contextpath@" value="${server.contextpath}"/>
			<replacefilter token="@server.port@" value="${server.port}"/>
			<replacefilter token="@server.port.ssl@" value="${server.port.ssl}"/>
			<replacefilter token="@tomcat.docbase@" value="${tomcat.docbase}"/>
			<replacefilter token="@log.dir@" value="${log.dir}"/>
			<replacefilter token="@connector.jk.comment.start@" value="${connector.jk.comment.start}"/>
			<replacefilter token="@connector.jk.comment.end@" value="${connector.jk.comment.end}"/>
			<replacefilter token="@connector.http.comment.start@" value="${connector.http.comment.start}"/>
			<replacefilter token="@connector.http.comment.end@" value="${connector.http.comment.end}"/>
			<replacefilter token="@tomcat.home@" value="${tomcat.home}"/>
		</replace>
		<echo message="Generated config file available at ${tomcat.server.xml.file}" />

		<!-- context.xml.in -->
		<echo message="Processing config file ${tomcat.context.xml.file}..." />
		<copy overwrite="true" file="${tomcat.context.xml.file}.in" tofile="${tomcat.context.xml.file}" />
		<replace file="${tomcat.context.xml.file}">
			<replacefilter token="@server.contextpath@" value="${server.contextpath}"/>
			<replacefilter token="@tomcat.docbase@" value="${tomcat.docbase}"/>
		</replace>
		<echo message="Generated config file available at ${tomcat.context.xml.file}. Use 'ant deploy' to deploy the app usint this context file" />

		
		<!-- log.properties.in -->
		<echo message="Processing config file ${webapp.dir}/WEB-INF/${log.properties.file}..." />
		<copy overwrite="true" file="${webapp.dir}/WEB-INF/${log.properties.file}.in" tofile="${webapp.dir}/WEB-INF/${log.properties.file}" />
		<replace file="${webapp.dir}/WEB-INF/${log.properties.file}">
			<replacefilter token="@log.dir@" value="${log.dir}"/>
		</replace>
		<echo message="Generated config file available at ${webapp.dir}/WEB-INF/${log.properties.file}" />
	</target>
	
	<!-- ======================= Deploy the webapp =========================== -->
	<target name="deploy" depends="init-ant, init" description="Deploy the tomcat context descriptor in the tomcat container">
		<property name="tomcat.context.deployer" value="${tomcat.home}/conf/Catalina/localhost${server.contextpath}.xml"/>
		<copy overwrite="false" file="${tomcat.context.xml.file}" tofile="${tomcat.context.deployer}" />
		<echo message="Webapp deployed using contextpath ${server.contextpath}" />
	</target>

	<!-- ======================= Undeploy the webapp =========================== -->
	<target name="undeploy" depends="init-ant, init" description="Deploy the tomcat context descriptor in the tomcat container">
		<delete file="${tomcat.home}/conf/Catalina/localhost${server.contextpath}.xml"></delete>
		<echo message="Webapp ${server.contextpath} is now undeployed" />
	</target>

	
	<!-- ======================= Apache configuration files =========================== -->
	<target name="config-apache" depends="init-ant, init" description="Generate apache related files">

		<!-- 403error.html -->
		<property name="403error.html" value="${base.dir}/htdocs/403error.html" />
		<copy overwrite="true" file="${403error.html}.in" tofile="${403error.html}" />
		<echo message="Processing file ${403error.html}..." />
		<replace file="${403error.html}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
		</replace>
		<echo message="Adjusted file ${403error.html}" />

		<!-- httpd.conf.in -->
		<property name="httpd.conf" value="${base.dir}/conf/httpd.conf" />
		<echo message="Processing config file ${httpd.conf}..." />
		<copy overwrite="true" file="${httpd.conf}.in" tofile="${httpd.conf}" />
		<replace file="${httpd.conf}">
			<replacefilter token="@base.dir@" value="${base.dir}"/>			
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
			<replacefilter token="@server.contextpath@" value="${server.contextpath}"/>
			<replacefilter token="@server.port@" value="${server.port}"/>
			<replacefilter token="@server.port.ssl@" value="${server.port.ssl}"/>
			<replacefilter token="@adminemail@" value="${adminemail}"/>
			<replacefilter token="@userdata.dir@" value="${userdata.dir}"/>
			<replacefilter token="@log.dir@" value="${log.dir}"/>
		</replace>
		<echo message="Generated config file available at ${httpd.conf}" />

		<!-- apachelogrotate.in -->
		<property name="apachelogrotate" value="${base.dir}/conf/apachelogrotate" />
		<echo message="Processing config file ${apachelogrotate}..." />
		<copy overwrite="true" file="${apachelogrotate}.in" tofile="${apachelogrotate}" />
		<replace file="${apachelogrotate}">
			<replacefilter token="@log.dir@" value="${log.dir}"/>
			<replacefilter token="@tomcat.home@" value="${tomcat.home}"/>
		</replace>
		<echo message="Generated config file available at ${apachelogrotate}" />

		<!-- instant_messaging_database.sql.in -->
		<property name="instant_messaging_database.sql" value="${base.dir}/database/mysql/instant_messaging_database.sql" />
		<echo message="Processing config file ${instant_messaging_database.sql}.in..." />
		<copy overwrite="true" file="${instant_messaging_database.sql}.in" tofile="${instant_messaging_database.sql}" />
		<replace file="${instant_messaging_database.sql}">		
			<replacefilter token="@instantMessaging.server.name@" value="${instantMessaging.server.name}"/>
			<replacefilter token="@instantMessaging.admin.username@" value="${instantMessaging.admin.username}"/>
			<replacefilter token="@instantMessaging.admin.password@" value="${instantMessaging.admin.password}"/>
		</replace>
		<echo message="Generated config file available at ${instant_messaging_database.sql}" />
		
		<!-- wildfire.xml.in -->
		<property name="wildfire.xml" value="${base.dir}/conf/wildfire.xml" />
		<echo message="Processing config file ${wildfire.xml}..." />
		<copy overwrite="true" file="${wildfire.xml}.in" tofile="${wildfire.xml}" />
		<replace file="${wildfire.xml}">		
			<replacefilter token="@db.host.name@" value="${db.host.name}"/>
			<replacefilter token="@db.host.port@" value="${db.host.port}"/>
			<replacefilter token="@instantMessaging.db.name@" value="${instantMessaging.db.name}"/>
			<replacefilter token="@instantMessaging.db.user@" value="${instantMessaging.db.user}"/>
			<replacefilter token="@instantMessaging.db.pass@" value="${instantMessaging.db.pass}"/>
		</replace>
		<echo message="Generated config file available at ${wildfire.xml}" />

	</target>

<!-- ========================= Config Monitoring ============================= -->
	<target name="config-monitoring" depends="init" description="Config OLAT monitoring">
		<!-- mrtg.cfg.in -->
		<property name="mrtg.cfg" value="${monitoring.dir}/conf/mrtg.cfg" />
		<echo message="Processing config file ${mrtg.cfg}..." />
		<copy overwrite="true" file="${mrtg.cfg}.in" tofile="${mrtg.cfg}" />
		<replace file="${mrtg.cfg}">
			<replacefilter token="@userdata.dir@" value="${userdata.dir}"/>
			<replacefilter token="@monitoring.dir@" value="${monitoring.dir}"/>
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
		</replace>
		<echo message="Generated config file available at ${mrtg.cfg}" />

		<!-- monitoring-crontab.in -->
		<property name="monitoring-crontab" value="${monitoring.dir}/conf/monitoring-crontab" />
		<echo message="Processing config file ${monitoring-crontab}..." />
		<copy overwrite="true" file="${monitoring-crontab}.in" tofile="${monitoring-crontab}" />
		<replace file="${monitoring-crontab}">
			<replacefilter token="@mrtg.bin@" value="${mrtg.bin}"/>
			<replacefilter token="@monitoring.dir@" value="${monitoring.dir}"/>
			<replacefilter token="@server.port@" value="${server.port}"/>
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
			<replacefilter token="@server.contextpath@" value="${server.contextpath}"/>
			<replacefilter token="@userdata.dir@" value="${userdata.dir}"/>			
		</replace>
		<echo message="Generated config file available at ${monitoring-crontab}" />
		
		<!-- index.html.in -->
		<property name="index.html" value="${monitoring.dir}/data/index.html" />
		<echo message="Processing config file ${index.html}..." />
		<copy overwrite="true" file="${index.html}.in" tofile="${index.html}" />
		<replace file="${index.html}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>			
		</replace>
		<echo message="Generated config file available at ${index.html}" />
		
		<!-- count_httpd.sh.in -->
		<property name="count_httpd.sh" value="${monitoring.dir}/bin/count_httpd.sh" />
		<echo message="Processing config file ${count_httpd.sh}..." />
		<copy overwrite="true" file="${count_httpd.sh}.in" tofile="${count_httpd.sh}" />
		<replace file="${count_httpd.sh}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
		</replace>
		<echo message="Generated config file available at ${count_httpd.sh}" />
		
		<!-- disk_usage.sh.in -->
		<property name="disk_usage.sh" value="${monitoring.dir}/bin/disk_usage.sh" />
		<echo message="Processing config file ${disk_usage.sh}..." />
		<copy overwrite="true" file="${disk_usage.sh}.in" tofile="${disk_usage.sh}" />
		<replace file="${disk_usage.sh}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
			<replacefilter token="@userdata.dir@" value="${userdata.dir}"/>		
		</replace>
		<echo message="Generated config file available at ${disk_usage.sh}" />
		
		<!-- historizeMRTGStats.sh.in -->
		<property name="historizeMRTGStats.sh" value="${monitoring.dir}/bin/historizeMRTGStats.sh" />
		<echo message="Processing config file ${historizeMRTGStats.sh}..." />
		<copy overwrite="true" file="${historizeMRTGStats.sh}.in" tofile="${historizeMRTGStats.sh}" />
		<replace file="${historizeMRTGStats.sh}">
			<replacefilter token="@mrtgbackup.dir@" value="${mrtgbackup.dir}"/>
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
			<replacefilter token="@mrtg.loginname@" value="${mrtg.loginname}"/>
			<replacefilter token="@mrtg.pwd@" value="${mrtg.pwd}"/>
		</replace>
		<echo message="Generated config file available at ${historizeMRTGStats.sh}" />
		
		<!-- mrtg-cpuusage.pl.in -->
		<property name="mrtg-cpuusage.pl" value="${monitoring.dir}/bin/mrtg-cpuusage.pl" />
		<echo message="Processing config file ${mrtg-cpuusage.pl}..." />
		<copy overwrite="true" file="${mrtg-cpuusage.pl}.in" tofile="${mrtg-cpuusage.pl}" />
		<replace file="${mrtg-cpuusage.pl}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
		</replace>
		<echo message="Generated config file available at ${mrtg-cpuusage.pl}" />

		<!-- mrtg-memusage.pl.in -->
		<property name="mrtg-memusage.pl" value="${monitoring.dir}/bin/mrtg-memusage.pl" />
		<echo message="Processing config file ${mrtg-memusage.pl}..." />
		<copy overwrite="true" file="${mrtg-memusage.pl}.in" tofile="${mrtg-memusage.pl}" />
		<replace file="${mrtg-memusage.pl}">
			<replacefilter token="@server.domainname@" value="${server.domainname}"/>
		</replace>
		<echo message="Generated config file available at ${mrtg-memusage.pl}" />

		<!-- mrtg-ping-probe.pl.in -->
		<property name="mrtg-ping-probe.pl" value="${monitoring.dir}/bin/mrtg-ping-probe.pl" />
		<echo message="Processing config file ${mrtg-ping-probe.pl}..." />
		<copy overwrite="true" file="${mrtg-ping-probe.pl}.in" tofile="${mrtg-ping-probe.pl}" />
		<replace file="${mrtg-ping-probe.pl}">
			<replacefilter token="@userdata.dir@" value="${userdata.dir}"/>
		</replace>
		<echo message="Generated config file available at ${mrtg-ping-probe.pl}" />
		
		<copy overwrite="true" todir="${userdata.dir}/monitoring/mrtg">
			<fileset dir="${monitoring.dir}/data"/>
		</copy>
		<chmod dir="${monitoring.dir}/bin" perm="ugo+rx" includes="**/*.pl"/>
		<chmod dir="${monitoring.dir}/bin" perm="ugo+rx" includes="**/*.sh"/>
	</target>
	
	<!-- ========================= Config css files ============================= -->
	<target name="config-css" depends="init" description="Configure the OLAT layout: processes all *.css.in files project wide and replaces tokens">
		<!-- copy in files to out files -->
		<copy overwrite="true" todir=".">
			<fileset dir="${basedir}">
				<include name="**/*.css.in"/>
			</fileset>
			<mapper from="*.css.in" to="*.css.out" type="glob" />
		</copy>
		<!-- replace tokens -->
		<replace dir="." includes="**/*.css.out">
			<replacefilter token="@color.tone.1@"  	value="${color.tone.1}"/>
			<replacefilter token="@color.tone.2@"  	value="${color.tone.2}"/>
			<replacefilter token="@color.tone.3@"  	value="${color.tone.3}"/>
			<replacefilter token="@color.tone.4@"  	value="${color.tone.4}"/>
			<replacefilter token="@color.tone.5@"  	value="${color.tone.5}"/>
			<replacefilter token="@color.tone.6@"  	value="${color.tone.6}"/>
			<replacefilter token="@color.tone.7@"  	value="${color.tone.7}"/>
			<replacefilter token="@color.tone.8@"  	value="${color.tone.8}"/>
			<replacefilter token="@color.tone.9@"  	value="${color.tone.9}"/>
			<replacefilter token="@color.link@"  	value="${color.link}"/>
			<replacefilter token="@color.navigation@"  	value="${color.navigation}"/>
			<replacefilter token="@color.navigation.active@"  	value="${color.navigation.active}"/>
			<replacefilter token="@color.white@"  	value="${color.white}"/>
			<replacefilter token="@color.grey.1@"  	value="${color.grey.1}"/>
			<replacefilter token="@color.grey.2@"  	value="${color.grey.2}"/>
			<replacefilter token="@color.grey.3@"  	value="${color.grey.3}"/>
			<replacefilter token="@color.grey.4@"  	value="${color.grey.4}"/>
			<replacefilter token="@color.grey.5@"  	value="${color.grey.5}"/>
			<replacefilter token="@color.black@"  	value="${color.black}"/>
			<replacefilter token="@color.attention.1@"  	value="${color.attention.1}"/>
			<replacefilter token="@color.attention.2@"  	value="${color.attention.2}"/>
			<replacefilter token="@color.attention.3@"  	value="${color.attention.3}"/>
			<replacefilter token="@color.attention.4@"  	value="${color.attention.4}"/>
			<replacefilter token="@color.error.1@"  	value="${color.error.1}"/>
			<replacefilter token="@color.error.2@"  	value="${color.error.2}"/>
			<replacefilter token="@color.error.3@"  	value="${color.error.3}"/>
			<replacefilter token="@color.selection@"  	value="${color.selection}"/>
			<replacefilter token="@color.ok@"  	value="${color.ok}"/>
			<replacefilter token="@color.nok@"  	value="${color.nok}"/>
			<replacefilter token="@color.red@"  	value="${color.red}"/>
			<replacefilter token="@color.green@"  	value="${color.green}"/>
			<replacefilter token="@color.blue@"  	value="${color.blue}"/>
			<replacefilter token="@color.ochre@"  	value="${color.ochre}"/>
			<replacefilter token="@image.background.help@"  	value="${image.background.help}"/>
			<replacefilter token="@image.background.top@"  	value="${image.background.top}"/>
			<replacefilter token="@image.background.bottom@"  	value="${image.background.bottom}"/>
			<replacefilter token="@image.background.error@"  	value="${image.background.error}"/>
			<replacefilter token="@fontfamily.variable@"  	value="${fontfamily.variable}"/>
			<replacefilter token="@fontfamily.fixed@"  	value="${fontfamily.fixed}"/>
			<replacefilter token="@server.contextpath@" value="${server.contextpath}"/>
		</replace>
		
		<!-- special treatment of files available in different font sizes -->
		<replace dir="." includes="**/*.css.out" excludes="**/jscalendar.css.out, **/mktree.css.out, **/olat-default.css.out">
			<replacefilter token="@css.font.xsmall@" 	value="${css.normal.xsmall}"/>
			<replacefilter token="@css.font.small@" 	value="${css.normal.small}"/>
			<replacefilter token="@css.font.normal@" 	value="${css.normal.normal}"/>
			<replacefilter token="@css.font.large@" 	value="${css.normal.large}"/>
			<replacefilter token="@css.font.xlarge@" 	value="${css.normal.xlarge}"/>
		</replace>
		
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar.css.out" tofile="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-normal.css" />
		<replace file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-normal.css">		
			<replacefilter token="@css.font.small@" value="${css.normal.small}"/>
			<replacefilter token="@css.font.xsmall@" value="${css.normal.xsmall}"/>
		</replace>
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-normal.css" tofile="${base.dir}/webapp/WEB-INF/classes/org/olat/core/gui/components/form/_static/css/jscalendar-normal.css" />
		
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar.css.out" tofile="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-small.css" />
		<replace file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-small.css">		
			<replacefilter token="@css.font.small@" value="${css.small.small}"/>
			<replacefilter token="@css.font.xsmall@" value="${css.small.xsmall}"/>
		</replace>
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-small.css" tofile="${base.dir}/webapp/WEB-INF/classes/org/olat/core/gui/components/form/_static/css/jscalendar-small.css" />
		
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar.css.out" tofile="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-large.css" />
		<replace file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-large.css">	
			<replacefilter token="@css.font.small@" value="${css.large.small}"/>
			<replacefilter token="@css.font.xsmall@" value="${css.large.xsmall}"/>
		</replace>
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/form/_static/css/jscalendar-large.css" tofile="${base.dir}/webapp/WEB-INF/classes/org/olat/core/gui/components/form/_static/css/jscalendar-large.css" />
		
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree.css.out" tofile="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-normal.css" />
		<replace file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-normal.css">		
			<replacefilter token="@css.font.large@" value="${css.normal.large}"/>
			<replacefilter token="@css.font.small@" value="${css.normal.small}"/>
		</replace>
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-normal.css" tofile="${base.dir}/webapp/WEB-INF/classes/org/olat/core/gui/components/tree/_static/css/mktree-normal.css" />
		
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree.css.out" tofile="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-small.css" />
		<replace file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-small.css">		
			<replacefilter token="@css.font.large@" value="${css.small.large}"/>
			<replacefilter token="@css.font.small@" value="${css.small.small}"/>
		</replace>
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-small.css" tofile="${base.dir}/webapp/WEB-INF/classes/org/olat/core/gui/components/tree/_static/css/mktree-small.css" />
		
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree.css.out" tofile="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-large.css" />
		<replace file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-large.css">	
			<replacefilter token="@css.font.large@" value="${css.large.large}"/>
			<replacefilter token="@css.font.small@" value="${css.large.small}"/>
		</replace>
		<copy overwrite="true" file="${base.dir}/webapp/WEB-INF/src/org/olat/core/gui/components/tree/_static/css/mktree-large.css" tofile="${base.dir}/webapp/WEB-INF/classes/org/olat/core/gui/components/tree/_static/css/mktree-large.css" />
		
		<copy overwrite="true" file="${base.dir}/webapp/static/css/olat-default.css.out" tofile="${base.dir}/webapp/static/css/olat-default-normal.css" />
		<replace file="${base.dir}/webapp/static/css/olat-default-normal.css">		
			<replacefilter token="@css.font.xsmall@" 	value="${css.normal.xsmall}"/>
			<replacefilter token="@css.font.small@" 	value="${css.normal.small}"/>
			<replacefilter token="@css.font.normal@" 	value="${css.normal.normal}"/>
			<replacefilter token="@css.font.large@" 	value="${css.normal.large}"/>
			<replacefilter token="@css.font.xlarge@" 	value="${css.normal.xlarge}"/>
			<replacefilter token="@css.size.toolbox@" 	value="${css.normal.toolbox}"/>
		</replace>
		
		<copy overwrite="true" file="${base.dir}/webapp/static/css/olat-default.css.out" tofile="${base.dir}/webapp/static/css/olat-default-small.css" />
		<replace file="${base.dir}/webapp/static/css/olat-default-small.css">		
			<replacefilter token="@css.font.xsmall@" 	value="${css.small.xsmall}"/>
			<replacefilter token="@css.font.small@" 	value="${css.small.small}"/>
			<replacefilter token="@css.font.normal@" 	value="${css.small.normal}"/>
			<replacefilter token="@css.font.large@" 	value="${css.small.large}"/>
			<replacefilter token="@css.font.xlarge@" 	value="${css.small.xlarge}"/>
			<replacefilter token="@css.size.toolbox@" 	value="${css.small.toolbox}"/>
		</replace>
		
		<copy overwrite="true" file="${base.dir}/webapp/static/css/olat-default.css.out" tofile="${base.dir}/webapp/static/css/olat-default-large.css" />
		<replace file="${base.dir}/webapp/static/css/olat-default-large.css">	
			<replacefilter token="@css.font.xsmall@" 	value="${css.large.xsmall}"/>
			<replacefilter token="@css.font.small@" 	value="${css.large.small}"/>
			<replacefilter token="@css.font.normal@" 	value="${css.large.normal}"/>
			<replacefilter token="@css.font.large@" 	value="${css.large.large}"/>
			<replacefilter token="@css.font.xlarge@" 	value="${css.large.xlarge}"/>
			<replacefilter token="@css.size.toolbox@" 	value="${css.large.toolbox}"/>
		</replace>
		
		<!-- rename all generated files to css -->
		<copy overwrite="true" toDir=".">
			<fileset dir="${basedir}">
				<include name="**/*.css.out"/>
			</fileset>
			<mapper from="*.css.out" to="*.css" type="glob" />
		</copy>
		<!-- special treatment of colortest file -->
		<copy overwrite="true" file="${basedir}/webapp/static/css/css-colortest.css" tofile="${basedir}/webapp/static/css/css-colortest.html" />
		
		<!-- delete all temp files-->
		<delete>
			<fileset dir="${basedir}">
				<include name="**/*.css.out"/>
			</fileset>
		</delete>
	</target>

<!-- ========================= Deploy Config ============================= -->
	<target name="config-all" depends="init,config-olat,config-css,config-apache,config-monitoring,copy-jsmath" description="Configure OLAT and deploy all config files of OLAT.">
	</target>
	
<!-- ========================= DBSetup ============================= -->
	<!-- setup for MySQL -->
	<target name="dbsetup" depends="init-ant" description="DBSetup for OLAT using MySQL.">
		<input message="All data is going to be deleted from DB. Continue?"
			validargs="y,n" addproperty="do.delete" />
		<condition property="do.abort">
			<equals arg1="n" arg2="${do.delete}"/>
		</condition>
		<fail if="do.abort">Build aborted by user.</fail>
		<antcall target="executesql">
			<param name="sqlfile" value="${base.dir}/database/mysql/deleteDatabase.sql" />
		</antcall>
		<antcall target="executesql">
			<param name="sqlfile" value="${base.dir}/database/mysql/setupDatabase.sql" />
		</antcall>
	</target>
		
	<!-- setup for PostgreSQL -->
		<target name="dbsetup_postgreSQL" depends="init-ant" description="DBSetup for OLAT using PostgreSQL.">
			<input message="All data is going to be deleted from DB. Continue?"
				validargs="y,n" addproperty="do.delete" />
			<condition property="do.abort">
				<equals arg1="n" arg2="${do.delete}"/>
			</condition>
			<fail if="do.abort">Build aborted by user.</fail>
			<antcall target="executesql">
				<param name="sqlfile" value="${base.dir}/database/postgresql/deleteDatabase.sql" />
			</antcall>
			<antcall target="executesql">
				<param name="sqlfile" value="${base.dir}/database/postgresql/setupDatabase.sql" />
			</antcall>
		</target>

	<!-- setup test db for MySQL -->
	<target name="dbsetuptestdb" depends="init-ant" description="DBSetup for OLAT test cases (MySQL).">
		<input message="All data is going to be deleted from DB test instance. Continue?"
			validargs="y,n" addproperty="do.delete" />
		<condition property="do.abort">
			<equals arg1="n" arg2="${do.delete}"/>
		</condition>
		<fail if="do.abort">Build aborted by user.</fail>
		<antcall target="executesqltestdb">
			<param name="sqlfile" value="${base.dir}/database/mysql/deleteDatabase.sql" />
		</antcall>
		<antcall target="executesqltestdb">
			<param name="sqlfile" value="${base.dir}/database/mysql/setupDatabase.sql" />
		</antcall>
	</target>
	
	<!-- setup test db for PostgreSQL -->
		<target name="dbsetuptestdb_postgreSQL" depends="init-ant" description="DBSetup for OLAT test cases (PostgreSQL).">
			<input message="All data is going to be deleted from DB test instance. Continue?"
				validargs="y,n" addproperty="do.delete" />
			<condition property="do.abort">
				<equals arg1="n" arg2="${do.delete}"/>
			</condition>
			<fail if="do.abort">Build aborted by user.</fail>
			<antcall target="executesqltestdb">
				<param name="sqlfile" value="${base.dir}/database/postgresql/deleteDatabase.sql" />
			</antcall>
			<antcall target="executesqltestdb">
				<param name="sqlfile" value="${base.dir}/database/postgresql/setupDatabase.sql" />
			</antcall>
		</target>

<!-- ========================= delete olatdata dir ============================= -->
	<target name="deletedatadir" depends="init-ant">
		<input message="All data is going to be deleted from olatdata directory. Continue?"
			validargs="y,n" addproperty="do.delete" />
		<condition property="do.abort">
			<equals arg1="n" arg2="${do.delete}"/>
		</condition>
		<fail if="do.abort">Build aborted by user.</fail>
		<delete includeemptydirs="true" dir="${userdata.dir}" />
		<antcall target="init-filesystem" />
	</target>

<!-- ========================= Check DB connection ============================= -->
	<target name="checkdb" depends="init-ant" description="Do a quick call to see wether the DB is up and running.">
		<sql driver="${db.jdbc.driver}" url="${db.jdbc.url}" userid="${db.user}"
			password="${db.pass}" print="${db.showresults}">
			<classpath><pathelement	location="${db.jdbc.jar}"></pathelement></classpath>
			${db.sqlquery}
		</sql>
	</target>

<!-- =============================== CVS Nightly =================================== -->
	<target name="nightly" depends="init-ant,clean,checkout,build,junit,checkdb,javadoc">
		<echo>
		**********************
		* Running nightly... *
		**********************
		</echo>

		<!-- setup test sequence -->
		<!--
		<antcall target="dbsetup"/>
		-->

		<!-- modify build information -->
		<propertyfile file="${build.info}" comment="Build properties">
			<entry key="build.date" type="date" value="now" pattern="dd.MM.yyyy HH:mm:ss"/>
			<entry key="build.number" type="int" default="${build.buildnr.default}" operation="+" pattern="${build.buildnr.pattern}"/>
			<entry key="build.version" value="${build.version}"/>
		</propertyfile>
		<cvs cvsRsh="${cvs.cvsrsh}" cvsRoot="${cvs.repository}" quiet="yes"
			command="ci -m 'Build number modified by ant' ${build.info}"/>
		<property file="${build.info}"/>

		<!-- modify Version.java file -->
		<replaceregexp file="${build.version.javafile}" match="(VERSION = .)(.*)(.;.*)" replace="\1${build.version}\3" byline="false"/>
		<replaceregexp file="${build.version.javafile}" match="(BUILD = .)([0-9]{4})(.;.*)" replace="\1${build.number}\3" byline="false"/>
		<cvs cvsRsh="${cvs.cvsrsh}" cvsRoot="${cvs.repository}" quiet="yes"
			command="ci -m 'Build number modified by ant' ${build.version.javafile}"/>
		<property file="${build.info}"/>

	</target>
	
	
<!-- =============================== SVN Nightly =================================== -->
	<target name="SVNnightly" depends="init-ant,clean,SVNcheckout,build,junit,checkdb,javadoc">
		<echo>
		**********************
		* Running SVNnightly... *
		**********************
		</echo>

		<!-- setup test sequence -->
		<!--
		<antcall target="dbsetup"/>
		-->

		<!-- modify build information -->
		<propertyfile file="${build.info}" comment="Build properties">
			<entry key="build.date" type="date" value="now" pattern="dd.MM.yyyy HH:mm:ss"/>
			<entry key="build.number" type="int" default="${build.buildnr.default}" operation="+" pattern="${build.buildnr.pattern}"/>
			<entry key="build.version" value="${build.version}"/>
		</propertyfile>
		
		<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpath="${lib.svn}" />
	    <svn>
	      <commit file="${svn.dest.path}/${build.info}" message="Build number modified by ant' ${build.info}" />
	    </svn>
	    
		<property file="${build.info}"/>
		<!-- modify Version.java file -->
		<replaceregexp file="${build.version.javafile}" match="(VERSION = .)(.*)(.;.*)" replace="\1${build.version}\3" byline="false"/>
		<replaceregexp file="${build.version.javafile}" match="(BUILD = .)([0-9]{4})(.;.*)" replace="\1${build.number}\3" byline="false"/>
		<svn>
	      <commit file="${svn.dest.path}/${build.version.javafile}" message="Build number modified by ant' ${build.version.javafile}" />
	    </svn>
			
		<property file="${build.info}"/>

	</target>
	
<!-- ============================ Make JAR files =============================== -->
	<target name="jar" depends="init-ant, init-classpath" description="make OLAT jar" >
		<property name="jarTemp" value="${temp.dir}/jar"/>
		<delete dir="${jarTemp}"/>
		<mkdir dir="${jarTemp}"/>
		<javac srcdir="${source.patches.dir}"
			destdir="${jarTemp}"
			classpathref="classpath.compile"
			includes="**/*.java"
			debug="true"
			deprecation="false"
			failonerror="${failonerror.compile}"/> 
		
		<javac 
			srcdir="${source.dir}" 
			destdir="${jarTemp}" 
			classpathref="classpath.compile" includes="**/*.java" 
			debug="true" 
			deprecation="true" 
			failonerror="${failonerror.compile}" 
			compiler="${build.compiler}"
			encoding="UTF-8"
			source="1.4" /> 
		<copy toDir="${jarTemp}">
			<fileset dir="${source.dir}/" excludes="**/*.java" />
		</copy>
		<jar jarfile="${webapp.dir}/WEB-INF/lib/olat.jar">
			<fileset dir="${jarTemp}"/> 
		</jar>
	</target>
	
<!-- ========================= Build Javadoc ============================= -->
	<target name="javadoc" depends="init-ant, init-classpath" description="Build Code Documentation">
		<delete dir="${doc.api.dir}" /> 
		<mkdir dir="${doc.api.dir}" /> 
		<javadoc
			failonerror="${failonerror.javadoc}"
			classpathref="classpath.compile"
			destdir="${doc.api.dir}"
			packagenames="org.olat.*"
			verbose="false"
			Use = "true" 
			source="1.5"
			encoding="UTF-8"
			additionalparam="-breakiterator"
			windowtitle="${doc.api.windowtitle}"
			maxmemory="256m"
			includenosourcepackages="true"
			header="${javadoc.header}"
			bottom="${javadoc.footer}">
			<sourcepath>
				<pathelement location="${source.dir}" />
				<pathelement location="${source.patches.dir}" />
			</sourcepath>
		</javadoc>
		<echo message="API doc can be found at ${doc.api.dir}"/>
	</target>	

<!-- =========================== JUnit tests =============================== -->
	<target name="junit" depends="init-ant, init-classpath, build" description="Run junit test cases">
		<delete dir="${junit.results.dir}"/>
		<mkdir dir="${junit.results.dir}"/>

		<mkdir dir="${userdata.dir}/bcroot_junittest"/>
		
		<junit printsummary="on" showoutput="false" fork="yes" haltonfailure="${failonerror.junit}" failureproperty="junit.failure">
			<!--jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000" /-->
			<!--jvmarg value="-Xdebug" /-->
			<jvmarg value="-Dolatdir=${base.dir}" />
			<classpath>
				<path refid="classpath.deploy"/>
			</classpath>
			<formatter type="xml"/>
				<batchtest toDir="${junit.results.dir}">
			  		<fileset dir="${source.dir}">
			  			<!-- include all tests but exclude all test suits -->
			  			<include name="**/org/olat/**/*Test.java"/>
			      		<exclude name="**/org/olat/**/AllTests.java"/>
			    	</fileset>
				</batchtest>
		</junit>
		
		<delete dir="${junit.doc.dir}"/>
		<mkdir dir="${junit.doc.dir}"/>
		<junitreport toDir="${junit.aggregation.dir}">
		  <fileset dir="${junit.results.dir}">
		    <include name="TEST-*.xml"/>
		  </fileset>
		  <report format="frames" toDir="${junit.doc.dir}"/>
		</junitreport>
		
		<delete dir="${userdata.dir}/bcroot_junittest"/>
		
		<echo message="JUnit report can be found at ${junit.doc.dir}/test-results/html/index.html"/>

		<fail if="junit.failure" message="JUnit reported a failure. Go check http://${server.domainname}:${server.port}${server.contextpath}/raw/doc/test-results/html/index.html"/>
	</target>
 
<!-- =========================  OLAT Distribution ============================= -->
	<target name="dist-init" description="Prepare path and properties for dist target.">
		<tstamp>
			<format property="built-on" pattern="yyyyMMdd"/>
		</tstamp>
		<echo message="Building Distribution ${vName}-${built-on}." />
		
		<fail unless="release">Please use commandline property: ant -Drelease="DEMO" dist</fail>
		<echo message="Building Release = ${release}" />
		<echo message="basedir = ${basedir}" />
		<property name="dist.name" value="${vName}-${release}-${built-on}"/>		
		<property name="dist.name.cvs" value="${Name}-${release}-${built-on}" />
		
		<!--cvs cvsRsh="${cvs.cvsrsh}" cvsRoot="${cvs.repository}" quiet="yes"
			command="tag ${dist.name.cvs} ${cvs.package}"/-->
		
	</target>
	
	<target name="dist" depends="init-ant, dist-init, build" description="Make OLAT Distribution: 'ant -Drelease='RC1' dist'">
		<property name="dist.files.dir" value="${dist.dir}/${dist.name}"/>
		<mkdir dir="${dist.files.dir}"/>
			
		<copy todir="${dist.files.dir}">
			<fileset dir="${basedir}">
				<include name="CHANGES.README"/>
				<include name="COPYING"/>
				<include name="INSTALL.README"/>
				<include name="LICENSE.TXT"/>
				<include name="build.info.txt" />
				<include name="build.xml"/>
				<include name="build.properties.default"/>
				<include name="layout.properties"/>
			</fileset>
		</copy>
		
		<copy todir="${dist.files.dir}">
			<fileset dir="${basedir}">
				<include name="webapp/**"/>
				<include name="htdocs/**"/>
				<include name="bin/**"/>
				<include name="conf/**"/>
				<include name="database/**"/>
				<include name="doc/**"/>
				<include name="monitoring/**"/>
				<include name="interfaces/**"/>
				<exclude name="**/CVS"/>
			</fileset>
		</copy>

		<zip destfile="${dist.name}.zip" basedir="${dist.dir}" excludes="readme.txt" />
		<delete dir="${dist.files.dir}" />
	</target>

<!-- ========================= Install ============================= -->
	<target name="install" depends="init,build,checkdb,config-all,readme" description="Install OLAT">
	</target>

<!-- ========================= Readme ========================== -->
	<target name="readme" description="Installation Readme">
		<echo>
		OLAT Installation
		=================
		
		A few manual steps are required to complete the installation...
		
		Database Setup:
		---------------
		- Run target 'dbsetup' to create the necessary tables for OLAT and
		  initialize them with default data. If you are using postgres use the
		  target 'dbsetup_postgreSQL' instead.
		- To recreate the tables, you can call 'dbsetup' again.
		  However: *** YOU WILL LOOSE ALL DATA *** by calling 'dbsetup'
			
		Tomcat configuration:
		---------------------
		Two possibilities:
		1) with a context.xml - recommended when tomcat hosts multiple apps or OLAT's
		  Or when you are a newbie to tomcat
		- Start tomcat. You must have an engine called 'Catalina' and a host 'localhost'.
		  This is the tomcat default setup, in case you have no idea what this means, just 
		  start tomcat, it will most likey run. 
		- Make sure you have permission to tomcat/conf/Catalina/localhost
		- run 'ant deploy' to deploy the OLAT application
		- run 'ant undeploy' to undeploy the OLAT application. 
		- There is no need to restart tomcat, just let it run
		2) with server.xml - recommended when OLAT is the only app that is running in tomcat
		- Check sample configuration for Tomcat (server.xml) in /conf directory.
		- Copy file 'server.xml' to your TOMCAT_HOME/conf/server.xml 
		- If you are not using Tomcat 5 you must copy the files xalan.jar, 
		  xercesImpl.jar and xmlApis.jar to your TOMCAT_HOME/commons/endorsed directory. 
		  We recommend you to upgrade to Tomcat 5!
		- Restart tomcat. 

		Apache configuration (optional, only needed with JK connector):
		---------------------------------------------------------------
		- Check sample configuration for Apache (httpd.conf)
		  in /conf directory if you use the jk connector server xml.
		- If you're using virtual hosts, include the file 'httpd.conf' in
		  your Apache's main httpd.conf or add it to /etc/apache/vhosts.d if 
		  you have such a directory.
		- Remember to restart your Apache with 'apache stop; apache start'.
		- If you enabled SSL support, make sure you replace the demo certificate
		  with a valid certificate for your domain name
			
		Wiki (recommended):
		-------------------
		The included wiki render engine can display math formulas. To do so you you can import
		the fonts into your os (for every client) or you use the image fonst that are serverside
		deployed. Run 'ant jsmath' to unzip the fonts to the folder.

		Monitoring Setup (optional):
		----------------------------
		- Run 'crontab -u olatunixuser ${monitoring.dir}/conf/monitoring-crontab 
		  to install the necessary cronjobs for the mrtg based monitoring
		  This is optional
			
		Jabber Setup (optional):
		------------------------
		- Read the manual what you have to do to setup the Jabber instant messaging
		  server.
		  
		Congratulations! You're just a few steps away from running OLAT.
		</echo>
	</target>

<!-- ========================= DB Executesql ============================= -->
    <target name="executesql" depends="init-ant" description="Execute some SQL from a file">
		<sql driver="${db.jdbc.driver}" url="${db.jdbc.url}" userid="${db.user}"
			password="${db.pass}" print="${db.showresults}">
			<classpath>
				<pathelement location="${db.jdbc.jar}" />
			</classpath>
			<transaction src="${sqlfile}" />
		</sql>
	</target>
	
	<target name="executesqltestdb" depends="init-ant" description="Execute some SQL from a file for the unit test db instance">
		<sql driver="${db.jdbc.driver}" url="${db.test.jdbc.url}" userid="${db.test.user}"
			password="${db.test.pass}" print="${db.showresults}">
			<classpath>
				<pathelement location="${db.jdbc.jar}" />
			</classpath>
			<transaction src="${sqlfile}" />
		</sql>
	</target>
	
<!-- ============================ Checkstyle  ================================ -->
    <target name="init-checkstyle-classpath" description="Initialize the java classpath.">
         <!-- classpath properties -->
        <path id="classpath.checkstyle">
            <pathelement location="${checkstyle.jar}"/>
        </path>
    </target>
    
    <target name="checkstyle" depends="init-ant,init-checkstyle-classpath">
        <!-- This doesn't work when run from netbeans for some reason-->
        <echo message="checkstyle.jar=${checkstyle.jar}"/>
        <echo message="checkstyle.config=${checkstyle.config}"/>
        <mkdir dir="${doc.dir}/reports/" />
        <taskdef name="checkstyle"
                 classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"
                 classpathref="classpath.checkstyle" />
        <property name="translation.severity" value="error"/>
        <checkstyle config="${checkstyle.config}" classpathref="classpath.checkstyle" failOnViolation="false">
            <fileset dir="${source.dir}" 
                     includes="**/*.java,**/*.properties"
                     excludes="**/Generated*.java,**/gui/*,**/transmogrify/*"/>
            <formatter type="xml" toFile="${doc.dir}/reports/checkstyle_report.xml"/>
            <property key="checkstyle.suppressions.file" file="${checkstyle.config.dir}/suppressions.xml"/>
            <property key="checkstyle.header.file" file="${checkstyle.config.dir}/java.header"/>
            <property key="checkstyle.importcontrol.file" file="${checkstyle.config.dir}/import-control.xml"/>
        </checkstyle>
        
        <style in="${doc.dir}/reports/checkstyle_report.xml" out="${doc.dir}/reports/checkstyle_report.html" style="${checkstyle.config.dir}\checkstyle-frames.xsl"/>
    </target>
    
<!-- ============================ jsMath  ================================ -->
	<target name="jsmath" depends="init-ant, init-classpath" description="Unzip the jsMath fonts">
		<unzip overwrite="false" src="${webapp.dir}/WEB-INF/classes/org/olat/core/gui/components/wikiToHtml/_static/js/jsMath/fonts.zip" dest="${source.dir}/org/olat/core/gui/components/wikiToHtml/_static/js/jsMath" />
    </target>
	
<!-- ============================ jsMath  ================================ -->
	<target name="copy-jsmath" depends="init-ant, init-classpath" description="Copy jsMath resources for CP offline reader">
		<copy toDir="${base.dir}/webapp/static/cp_offline_menu_mat/jsMath" >
			<!-- we omit fonts as they are just to big to deliver with every export. -->
			<fileset dir="${source.dir}/org/olat/core/gui/components/wikiToHtml/_static/js/jsMath">
				<include name="**/*.js"/>
			</fileset>
		</copy>
		<copy toDir="${base.dir}/webapp/static/cp_offline_menu_mat">
			<fileset dir="${source.dir}/org/olat/core/gui/components/wikiToHtml/_static/js">
				<include name="wiki.js"/>
			</fileset>
		</copy>
	</target>
	
</project>