<project name="PRESENTATION DE L'OFFRE DE FORMATION" basedir="." default="prepareWeb">

	<!-- Definition des proprietes utilisees pour les regles -->
	<property file="web-config.properties" />
	<property file="build.properties" />
	<property name="app.src.home" value="source" />
	<property name="app.dist.home" value="${app.name}" />
	<property name="app.war" value="${app.name}.war" />
	<property name="app.dist.home.classes" value="${app.dist.home}/WEB-INF/classes" />
	<property name="app.dist.home.lib" value="${app.dist.home}/WEB-INF/lib" />
	<property name="app.dist.home.properties" value="${app.dist.home}/properties" />
	<property name="lib.dir" value="lib" />
	<property name="app.webpages" value="webpages" />
	<property name="app.webpages.xsl" value="stylesheets" />
	<property name="app.javadoc.home" value="javadoc" />

	<!-- chargement du uniform-config.xml -->
	<xmlproperty file="properties/uniform-config.xml" />
	<xmlproperty file="properties/uniform-config.${cdmfr-release}.sample.xml" />
	<property name="uniform.data-base(name)" value="" />
	<property name="uniform.data-base.init-base(path)" value="" />
	<property name="uniform.data-base.init-base.constants-name" value="" />
	<property name="uniform.data-base.init-base.orgUnit-name" value="" />
	<property name="db.init" value="${uniform.data-base.init-base(path)}" />
	<property name="db.name" value="${uniform.data-base(name)}" />
	<property name="orgunit.name" value="${uniform.data-base.init-base.orgUnit-name}" />
	<property name="constants.name" value="${uniform.data-base.init-base.constants-name}" />
	<!-- fin chargement du uniform-config.xml -->

	<available property="properties" file="build.properties" type="file" />
	<available property="searchEngineConfig" file="properties/search-engine-config.xml" type="file" />
	<available property="profilDir" file="webpages/stylesheets/${profil}" type="dir" />

	<available property="stylesheets.variablesExt" file="properties/variablesExt.xml" type="file" />

	<!-- Constitution du CLASSPATH pour la compilation -->
	<path id="compile.classpath">
		<fileset dir="${lib.dir}">
			<include name="*.jar" />
		</fileset>
	</path>


	<target name="clean" description="Supprime le dossier web">
		<delete dir="${app.dist.home}" />
		<delete file="properties/uniform-config.xml"/>
	</target>


	<!-- suppression du war -->
	<target name="veryclean" depends="clean" description="">
		<delete file="${app.war}" />
	</target>


	<!-- copie conditionnelle du build.properties -->
	<target name="setProperties" unless="properties" description="copie conditionnelle du build.properties">
		<copy file="build.${cdmfr-release}.sample.properties" tofile="build.properties" />
	</target>

	<!-- copie conditionnelle du document constantes -->
	<target name="setConstants" depends="setProperties" description="copie conditionnelle du document constantes">
		<copy file="${db.init}/constantes.${cdmfr-release}.sample.xml" tofile="${db.init}/${db.name}/${constants.name}.xml" />
	</target>
	<!-- copie conditionnelle du document customoai -->
	<target name="setCustomoai" depends="setProperties" description="copie conditionnelle du document customoai">
		<copy overwrite="true" file="webpages/stylesheets/xml2xml/${cdmfr-release}/${customoai}.xsl" tofile="webpages/stylesheets/xml2xml/${cdmfr-release}/customoai.xsl" />
	</target>

	<!-- copie conditionnelle du document orgUnit -->
	<target name="setOrgUnit" depends="setProperties" description="copie conditionnelle du document orgUnit">
		<copy file="${db.init}/orgunit-universite.${cdmfr-release}.sample.xml" tofile="${db.init}/${db.name}/${orgunit.name}.xml" />
	</target>

	<!-- copie conditionnelle du fichier de configuration -->
	<target name="setConfigFile" depends="setProperties" description="copie du fichier de configuration d'uniform">
		<copy tofile="properties/uniform-config.xml" overwrite="true">
			<fileset dir="properties" includes="uniform-config.${cdmfr-release}.sample.xml" />
			<filterchain>
				<replacetokens begintoken="[" endtoken="]">
					<token key="PROFIL" value="${profil}" />
					<token key="DBPATH" value="${db.path}" />
					<token key="DBNAME" value="${db.name}" />
					<token key="URL" value="${url}" />
					<token key="M-URL" value="${m-url}" />
				</replacetokens>
			</filterchain>
		</copy>
		
	</target>

	<!-- copie conditionnelle du search-engine-config.xml -->
	<target name="setSearchEngineConfig" depends="setProperties" unless="searchEngineConfig" description="copie conditionnelle du search-engine-config.xml">
		<copy file="properties/search-engine-config.${cdmfr-release}.sample.xml" tofile="properties/search-engine-config.${cdmfr-release}.xml" />
	</target>
	
	<!-- copie conditionnelle de urlrewrite.xml -->
		<target name="setUrlRewrite" depends="setProperties" unless="searchEngineConfig" description="copie conditionnelle de urlrewrite.xml">
			<copy file="properties/urlrewrite.${cdmfr-release}.sample.xml" tofile="properties/urlrewrite.xml" />
		</target>

	<!-- copie conditionnelle du variablesExt.xml -->
	<target name="setVariablesExt" depends="setProperties" unless="stylesheets.variablesExt" description="copie conditionnelle du variablesExt.xml">
		<copy file="properties/variablesExt.${cdmfr-release}.sample.xml" tofile="properties/variablesExt.xml" />
	</target>

	<!-- Creation des donnees de l'uv -->
	<target name="prepareData" depends="setCustomoai, setConfigFile, setConstants, setOrgUnit, setSearchEngineConfig, setUrlRewrite, setVariablesExt" description="Creation des donnees de l'uv">
	</target>

	<!-- Creation du dossier web -->
	<target name="prepareWeb" description="Creation du dossier web" depends="prepareData">
		<delete file="${app.dist.home.classes}/log4j.properties" />
		<delete file="${app.dist.home.classes}/properties/oaicat.properties" />
		<copy file="webpages/media/css/${cdmfr-release}.sample.css" tofile="webpages/media/css/main.css" overwrite="true"/>
		<mkdir dir="${app.dist.home}" />
		<copy todir="${app.dist.home}">
			<fileset dir="${app.webpages}" excludes="${app.webpages.xsl}/**" />
		</copy>
		<mkdir dir="${app.dist.home.classes}" />
		<mkdir dir="${app.dist.home.lib}" />
		<copy todir="${app.dist.home.lib}">
			<fileset dir="lib">
				<include name="**/*.jar" />
				<exclude name="servlet-api.jar" />
			</fileset>
		</copy>
		<copy todir="${app.dist.home.classes}/properties">
			<fileset dir="properties" includes="**/*" excludes="log4j.properties, 
															oaicat.properties,
          													uniform-config.cdmfr-*.sample.xml, 
															search-engine-config.cdmfr-*.sample.xml,
      														variablesExt.sample.xml,
															urlrewrite.cdmfr-*.xml,
 															variablesExt.xml" />
				
		</copy>
		<copy todir="${app.dist.home.classes}">
			<fileset dir="properties" includes="log4j.properties" />
			<filterchain>
				<replacetokens begintoken="[" endtoken="]">
					<token key="LOG_FILE" value="${log.file}" />
					<token key="STAT_FILE" value="${stat.file}" />
				</replacetokens>
			</filterchain>
		</copy>
		<copy todir="${app.dist.home.classes}/properties">
			<fileset dir="properties" includes="oaicat.properties" />
			<filterchain>
				<replacetokens begintoken="[" endtoken="]">
					<token key="ADMIN.EMAIL" value="${admin.email}" />
					<token key="WS.BASE" value="${ws.base}" />
					<token key="RNE" value="${rne}" />
				</replacetokens>
			</filterchain>
		</copy>
		<copy todir="${app.dist.home}/WEB-INF/" file="properties/urlrewrite.xml"/>
		<!-- xsl -->
		<mkdir dir="${app.dist.home.classes}/xsl" />
		<copy todir="${app.dist.home.classes}/xsl">
			<fileset dir="${app.webpages}/${app.webpages.xsl}" />
		</copy>
		<copy file="properties/variablesExt.xml" todir="${app.dist.home.classes}/xsl/commun" />
	</target>

	<!-- preparation archive de distribution -->
	<target name="zip" description="creation du fichier de deploiement">
		<delete file="${package.name}.zip" />
		<mkdir dir="${package.name}" />
		<copy todir="${package.name}">
			<fileset dir="." excludes="build.properties, web-config.properties, *.zip, *.log, *.log.*,*.war,
										cdm/**,dbs/**,log/**,initdb/**,.classpath, .project,
										properties/uniform-config.xml,
										webpages/stylesheets/xm2xml/customoai.xml,
										properties/search-engine-config.${cdmfr-release}.xml,
										properties/variablesExt.xml,
										${package.name}" />
		</copy>
		<mkdir dir="${package.name}/dbs"/>
		<mkdir dir="${package.name}/log"/>
		<copy todir="${package.name}/${db.init}">
			<fileset dir="${db.init}" includes="*.sample.xml"/>
		</copy>
		<zip zipfile="${package.name}.zip" basedir="." includes="${package.name}/**" />
		<delete dir="${package.name}" />
	</target>

	<!-- compilation des sources -->
	<target name="compile" depends="prepareWeb" description="Compilation des classes java">
		<javac srcdir="${app.src.home}" destdir="${app.dist.home.classes}" debug="off" optimize="on" deprecation="off">
			<classpath refid="compile.classpath" />
		</javac>
	</target>


	<!-- creation du fichier de deploiement -->
	<target name="dist" depends="compile" description="Creation du fichier de deploiement">
		<jar jarfile="${app.war}" basedir="${app.dist.home}" />
	</target>


	<!-- deploiement de l'archive (pas d'autodeploy sur le serveur) -->
	<target name="deploy" depends="undeploy,compile,validate" description="Deployement de l'archive">
		<copy todir="${deploy.home}/${app.name}">
			<fileset dir="${app.dist.home}" />
		</copy>
	</target>

	<!-- creation de la documentation -->
	<target name="javadoc" description="Creation de la documentation">
		<mkdir dir="${app.javadoc.home}" />
		<javadoc sourcepath="${app.src.home}" destdir="${app.javadoc.home}" classpath="compile.classpath" access="private" author="true" doctitle="Documentation d' esupUniform" packagenames="fr.ustl.uniform.provider.ws,fr.ustl.uniform.ant,fr.ustl.uniform.config.digester,fr.ustl.uniform.lucene.search,fr.ustl.uniform.config,fr.ustl.uniform.catalogue,fr.ustl.uniform.servlets.actions,fr.ustl.uniform.utils,fr.ustl.uniform.document,fr.ustl.uniform.constants,fr.ustl.uniform.lucene,fr.ustl.uniform.stats,fr.ustl.uniform.document.element,fr.ustl.uniform.provider.oai.catalog,fr.ustl.uniform.provider.connection,fr.ustl.uniform.servlets,fr.ustl.uniform.provider.oai.crosswalk,fr.ustl.uniform.lucene.index">
			<package name="fr.ustl.uniform.*" />
		</javadoc>
	</target>


	<!-- undeploy -->
	<target name="undeploy" description="Suppression de l'archive deployee">
		<delete dir="${deploy.home}/${app.name}" />
	</target>

	<!-- Webservice monitoring -->
	<target name="deploySOAPMONITOR" depends="compile">
		<java dir="" classname="org.apache.axis.client.AdminClient" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="-l${ws.base}/services/AdminService" />
			<arg value="${app.webpages}/WEB-INF/soap-monitor.wsdd" />
		</java>
	</target>
	<!-- Activation du webservice SOF -->
	<target name="deployWSSOF" depends="deploySOAPMONITOR" description="Activation du webservice SOF">

		<java dir="" classname="org.apache.axis.client.AdminClient" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="-l${ws.base}/services/AdminService" />
			<arg value="${app.webpages}/WEB-INF/sof.wsdd" />
		</java>
	</target>

	<target name="import_dir" description="Importation des formations (stockage,indexation,pdf)" depends="compile">
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="import_dir" />
			<arg value="${codAnu}" />
		</java>
	</target>

	<target name="prepare" description="Preparation des repertoires de la base CDM" depends="compile,validate">
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="prepare" />
		</java>
	</target>

	<target name="initdb" depends="create_profil, prepare" description="Affecte les constantes et orgUnit Univ a la Base CDM">
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="init" />
		</java>
	</target>

	<target name="cleandb" description="Vide la base CDM" depends="compile,validate">
		<delete file="${db.init}/orgunit-universite.${cdmfr-release}.xml"/>
		<delete file="${db.init}/constantes.${cdmfr-release}.xml"/>
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="clean" />
		</java>
	</target>

	<target name="import_program" description="Importe une formation en specifiant le nom du fichier" depends="compile,validate">
		<property name="file" value="" />
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="import_program" />
			<arg value="${file}" />
			<arg value="${codAnu}" />
		</java>
	</target>

	<target name="remove_program" description="Supprime une formation spec par id et codAnu" depends="compile,validate">
		<property name="id" value="" />
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="remove_program" />
			<arg value="${id}" />
			<arg value="${codAnu}" />
		</java>
	</target>

	<target name="remove_codAnu" description="Supprime toutes les formations dont codAnu est specifie" depends="compile,validate">
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="remove_codAnu" />
			<arg value="${codAnu}" />
		</java>
	</target>

	<target name="import_orgunit" description="Fabrique l'orgUnit depuis un fichier de formation [rep import]" depends="compile,validate">
		<property name="file" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="import_orgunit" />
			<arg value="${file}" />
		</java>
	</target>


	<target name="indexdb" description="Indexation de la base" depends="compile,validate">
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="indexdb" />
		</java>
	</target>

	<target name="validate" description="Validation du contenu du fichier uniform-config.xml" depends="compile">
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="validate" />
		</java>
	</target>

	<target name="create_oai" description="Creation des enregistrements oai pour un codAnu" depends="compile">
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="create_oai" />
			<arg value="${codAnu}" />
		</java>
	</target>
	<target name="import_fromdb" description="ReImportation des documents pour un codAnu" depends="compile">
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="import_fromdb" />
			<arg value="${codAnu}" />
		</java>
	</target>
	<target name="create_pdf" description="Creation des documents pdf pour un codAnu" depends="compile">
		<property name="codAnu" value="" />
		<java dir="" classname="fr.ustl.uniform.ant.Emulator" fork="true">
			<classpath>
				<pathelement path="${app.dist.home.classes}" />
				<path refid="compile.classpath" />
			</classpath>
			<arg value="create_pdf" />
			<arg value="${codAnu}" />
		</java>
	</target>
	<target name="create_release" description="Creation d'une nouvelle configuration en vue d'une adaptation locale a partir d'une configuration deja existante" >
		<property name="my-cdmfr-release" value="cdmfr-annee-editeur" />
		<property name="my-profil" value="profil" />
		<echo>Creation d'une nouvelle configuration (${my-cdmfr-release}) </echo>
		<copy tofile="properties/uniform-config.${my-cdmfr-release}.sample.xml"  overwrite="true">
			<fileset dir="." includes="properties/uniform-config.sample.xml" />
			<filterchain>
				<replacetokens begintoken="[" endtoken="]">
					<token key="CDMFR-RELEASE" value="${my-cdmfr-release}" />
				</replacetokens>
			</filterchain>
		</copy>
		<copy file="properties/urlrewrite.sample.xml" tofile="properties/urlrewrite.${my-cdmfr-release}.sample.xml"  overwrite="true"/>
		<copy file="properties/variablesExt.sample.xml" tofile="properties/variablesExt.${my-cdmfr-release}.sample.xml"  overwrite="true"/>
		<copy file="properties/search-engine-config.sample.xml" tofile="properties/search-engine-config.${my-cdmfr-release}.sample.xml"  overwrite="true"/>
		<copy file="${db.init}/constantes.sample.xml" tofile="${db.init}/constantes.${my-cdmfr-release}.sample.xml"  overwrite="true"/>
		<copy file="${db.init}/orgUnit-universite.sample.xml" tofile="${db.init}/orgUnit-universite.${my-cdmfr-release}.sample.xml"  overwrite="true"/>
		<copy file="build.sample.properties" tofile="build.${my-cdmfr-release}.sample.properties"  overwrite="true"/>
		<copy file="webpages/media/css/sample.css" tofile="webpages/media/css/${my-cdmfr-release}.sample.css" overwrite="true"/>
		<mkdir dir="webpages/stylesheets/xml2xml/${my-cdmfr-release}"/>
		<copy todir="webpages/stylesheets/xml2xml/${my-cdmfr-release}" overwrite="true">
			<fileset dir="webpages/stylesheets/xml2xml/cdmfr-default.sample" />
		</copy>
		<mkdir dir="import/${my-cdmfr-release}"/>
		<copy tofile="build.${my-cdmfr-release}.sample.properties" overwrite="true">
			<fileset dir="." includes="build.sample.properties" />
			<filterchain>
				<replacetokens begintoken="[" endtoken="]">
					<token key="CDMFR-RELEASE" value="${my-cdmfr-release}" />
					<token key="PROFIL" value="${my-profil}" />
				</replacetokens>
			</filterchain>
		</copy>
	</target>
	<target name="init_release" depends="setConfigFile, create_profil" description="lancement de la configuration" >
	</target>
	<target name="create_profil" if="profilDir" description="Creation du profil par defaut" >
		<property name="profil" value="profil" />
		<echo>Creation du profil (${profil}) </echo>
		<copy todir="webpages/stylesheets/${profil}" overwrite="true">
			<fileset dir="webpages/stylesheets/sample" />
		</copy>
	</target>
	<target name="delete_release" description="Efface une configuration" >
		<property name="my-cdmfr-release" value="cdmfr-annee-editeur" />
		<echo>Efface la  configuration (${my-cdmfr-release})</echo>
		<delete file="properties/uniform-config.${my-cdmfr-release}.sample.xml" />
		<delete file="properties/urlrewrite.${my-cdmfr-release}.sample.xml"/>
		<delete file="properties/variablesExt.${my-cdmfr-release}.sample.xml"/>
		<delete file="properties/search-engine-config.${my-cdmfr-release}.sample.xml"/>
		<delete file="${db.init}/constantes.${my-cdmfr-release}.sample.xml" />
		<delete file="${db.init}/orgUnit-universite.${my-cdmfr-release}.sample.xml" />
		<delete dir="${db.init}/${my-cdmfr-release}" />
		<delete file="build.${my-cdmfr-release}.sample.properties" />
		<delete file="webpages/media/css/${my-cdmfr-release}.sample.css"/>
		<delete dir="webpages/stylesheets/xml2xml/${my-cdmfr-release}"/>
		<delete dir="import/${my-cdmfr-release}"/>
	</target>

</project>
