
<!-- ANT BUILD FILE FOR THE JADE PROJECT -->

<!-- The following targets are expected to be used by users:
ant jade - to compile JADE
ant lib - to create the JADE libraries i.e. jade.jar and iiop.jar
ant examples - to compile JADE examples demo
ant dist - to create the distribution files
-->

<!-- set properties for this project -->
<project name="JADE" default="jade" basedir=".">
	<description>JADE build file</description>
	<property file="build.properties"/>
	<property environment="env"/>
	<!-- set global properties for this build -->
	<property name="root" location="."/>
	<property name="lib" location="lib"/>
	<property name="src" location="src"/>
	<property name="dist" location=".."/>
	<property name="doc" location="doc"/>
	<property name="build" location="classes"/>
	<property name="demo" location="demo"/>

	<target name="init">
		<!-- Create the time stamp -->
		<tstamp/>

		<!-- Create the directory structure -->
		<mkdir dir="${doc}"/>
		<mkdir dir="${lib}"/>
		<mkdir dir="${build}"/>

		<!-- Initialize properties that will be used to decide whether or not to activate optional targets -->
		<!-- NOTE that the '$' character is used to escape special characters. Therefore $${xxx} becomes ${xxx} and is equals to ${xxx} only if xxx is NOT a property -->

		<!-- Parsers are rebuild IF the rebuildParsers property is set to true in the build.properties file AND the JAVACC_HOME environment variable is set -->
		<condition property="makeParsers">
			<and>
				<equals arg1="${rebuildParsers}" arg2="true"/>
				<not>
					<equals arg1="${env.JAVACC_HOME}" arg2="$${env.JAVACC_HOME}"/>
				</not>
			</and>
		</condition>

		<condition property="jess.home.is.set">
			<not>
				<equals arg1="${env.JESS_HOME}" arg2="$${env.JESS_HOME}"/>
			</not>
		</condition>

		<!-- IDL for IIOP MTP will be recreated IF the EXECidlj property is set in the build.properties file -->
		<condition property="EXECidlj.is.set">
			<equals arg1="${EXECidlj}" arg2="true"/>
		</condition>
	</target>

	<target name="check_javacc" unless="makeParsers">
		<echo>javacc task is being skipped and the pre-built parsers will be used. If you want to rebuild the parsers, set the rebuildParsers property to true in the build.properties file and set the JAVACC_HOME environment variable to the home directory where your javacc program has been installed.</echo>
	</target>
	<target name="check_jess" unless="jess.home.is.set">
		<echo>jess task is being skipped. If you want to compile the examples based on JESS, set the environment variable JESS_HOME to the home directory where your jess program has been installed.</echo>
	</target>
	<target name="check_execIdlj" unless="EXECidlj.is.set">
		<echo>Default behaviour: IDLJ task is being skipped.</echo>
	</target>

	<!--  _______________________________________________
	                            idlj
	      _______________________________________________ -->
	<target name="idlj" depends="init,check_execIdlj" if="EXECidlj.is.set">
		<echo>WARNING: Executing the idlj task might create wrong java files</echo>
		<exec dir="${src}" executable="idlj.exe">
			<arg line="-fall fipa.idl"/>
		</exec>
	</target>

	<!--  _______________________________________________
	                            setWCInfo
	      _______________________________________________ -->
	<condition property="isPresentSUBWCRev">
		<available file="leap/resources/antTasks" type="dir"/>
	</condition>
		  
	<target name="setWCInfo" depends="initSUBWCRev, setSVNInfo, setVersionInfo" />

	<target name="initSUBWCRev" if="isPresentSUBWCRev">
			<taskdef name="SUBWCRev" classname="com.tilab.ant.SUBWCRev">
			<classpath>
				<fileset dir="leap/resources/antTasks">
					<include name="antlr-runtime-3.4.jar"/>
					<include name="sequence-library-1.0.3.jar"/>
					<include name="sqljet-1.1.10.jar"/>
					<include name="svnkit-1.8.8.jar"/>
					<include name="SUBWCRev.jar"/>
				</fileset>
			</classpath>
		</taskdef>  
		<SUBWCRev workingcopypath="." />
	</target>
	
	<target name="setSVNInfo">
		<condition property="WCREV" else="UNKNOWN">
			<isset property="WCREV"/>
		</condition>
		<echo>SVN revision number: ${WCREV}</echo>
		<condition property="WCDATE" else="UNKNOWN">
			<isset property="WCDATE"/>
		</condition>
		<echo>SVN revision date: ${WCDATE}</echo>
	</target>

	<target name="setVersionInfo">
		<condition property="versionType" value="" else="(snapshot)" >
			<equals arg1="${tagThisVersion}" arg2="true"/>
		</condition>
		<condition property="WCVER" value="${version} ${versionType}" else="UNKNOWN">
			<isset property="version"/>
		</condition>
		<echo>JADE version: ${WCVER}</echo>
	</target>

	<!--  _______________________________________________
	                          parser
	      _______________________________________________ -->
	<target name="parser" depends="init, check_javacc, MakeACLParser, MakeSLParser, MakeExtendedSLParser" description="generate parser with javacc"/>
	<target name="MakeACLParser" depends="init, check_javacc" if="makeParsers">
		<javacc jdkversion="1.4" javacchome="${env.JAVACC_HOME}" outputdirectory="src/jade/lang/acl" target="src/jade/lang/acl/ACLParser.jj"/>
	</target>
	<target name="MakeSLParser" depends="init, check_javacc" if="makeParsers">
		<javacc jdkversion="1.4" javacchome="${env.JAVACC_HOME}" outputdirectory="src/jade/content/lang/sl" target="src/jade/content/lang/sl/SLParser.jj"/>
	</target>
	<target name="MakeExtendedSLParser" depends="init, check_javacc" if="makeParsers">
		<javacc jdkversion="1.4" javacchome="${env.JAVACC_HOME}" outputdirectory="src/jade/content/lang/sl" target="src/jade/content/lang/sl/ExtendedSLParser.jj"/>
	</target>

	<!--  _______________________________________________
	                          compile
	      _______________________________________________ -->
	<target name="jade" depends="init,parser,idlj,setWCInfo" description="compile the source ">
		<!-- Compile the java code from ${src} into ${build} -->
		<!--   <delete dir="${build}/examples"/>
	    <delete dir="${build}/demo"/> -->
		<javac srcdir="${src}" 
		       destdir="${build}" 
		       classpath="lib/commons-codec/commons-codec-1.3.jar" 
		       nowarn="on" 
		       optimize="${javac.optimize}" 
		       debug="${javac.debug}" 
		       debuglevel="lines,vars,source" 
		       deprecation="on" 
			   target="1.5"
			   source="1.5"
		       excludes="demo/**,examples/**,test/**" >
		</javac>
		
		<copy todir="${build}">
			<fileset dir="${src}">
				<include name="**/*.png"/>
				<include name="**/*.gif"/>
				<include name="**/*.jpg"/>
			</fileset>
		</copy>
		
		<rmic classname="jade.imtp.rmi.ServiceManagerRMIImpl" base="${build}"/>
		<rmic classname="jade.imtp.rmi.NodeRMIImpl" base="${build}"/>
	</target>

	<!--  ________________________________________________
	                         jar
	      ________________________________________________ -->
	<target name="lib" depends="jade" description="generate jar archive">
		<!-- Create the jade.jar file -->
		<delete file="${lib}/jade.jar" quiet="true"/>
		<jar jarfile="${lib}/jade.jar">
			<manifest>
				<attribute name="Built-By" value="Jade Team (${user.name})"/>
				<attribute name="Build-Date" value="${DSTAMP}-${TSTAMP}"/>
				<section name="Jade Informations">
					<attribute name="Specification-Version" value="${WCVER}"/>
					<attribute name="SVN-Revision" value="${WCREV}"/>
					<attribute name="SVN-Date" value="${WCDATE}"/>
				</section>
			</manifest>
			<fileset dir="${build}">
				<exclude name="**/examples/**"/>
				<exclude name="**/demo/**"/>
				<exclude name="**/test/**"/>
			</fileset>
		</jar>
	</target>
	
	<!--  __________________________________________________
	                        clean
	      __________________________________________________ -->
	<target name="clean" description="clean up">
		<!-- Delete the ${build} directory tree -->
		<delete includeEmptyDirs="true">
			<fileset dir="${build}" excludes="**/*.mf"/>
		</delete>
		<!-- clean the doc/api directory -->
		<delete dir="${doc}/api" excludes="javalogo52x88.gif" includeEmptyDirs="true"/>
	</target>
	
	<!--  __________________________________________________
	                        doc
	      __________________________________________________ -->
	<target name="doc" description="generate javadoc documentation">
		<!-- clean the doc/api directory -->
		<delete dir="${doc}/api" excludes="javalogo52x88.gif" includeEmptyDirs="true"/>
		<!-- generate new javadoc documentation -->
		<javadoc destdir="${doc}/api" author="true" windowtitle="JADE ${version} API Reference" sourcepath="${src}" use="true" packagenames="jade.core, jade.core.behaviours, jade.core.event, jade.lang.acl, jade.domain, jade.domain.FIPAAgentManagement, jade.domain.JADEAgentManagement, jade.domain.mobility, jade.proto, jade.gui, jade.wrapper.gateway, jade.wrapper, jade.domain.DFGUIManagement, jade.domain.introspection, jade.content, jade.content.abs, jade.content.acl, jade.content.lang, jade.content.lang.j, jade.content.lang.leap, jade.content.lang.sl, jade.content.onto, jade.content.onto.basic, jade.content.schema, jade.content.schema.facets, jade.util, jade.util.leap, jade.mtp, jade.mtp.iiop jade.mtp.http jade.mtp.http.https"/>
		<javadoc destdir="${doc}/tools/sniffer/html/jdoc" author="true" windowtitle="JADE ${version} Sniffer Reference" sourcepath="${src}" packagenames="jade.tools.sniffer"/>
	</target>
	
	<!--  _______________________________________________
	                           examples
	      _______________________________________________ -->
	<target name="examples" depends="lib,examples1,jessexamples" description="compile the examples ">
		<jar jarfile="${lib}/jadeExamples.jar">
			<fileset dir="${build}" includes="examples/**"/>
		</jar>
	</target>
	<target name="examples1" depends="lib" description="compile all examples except the JESS-based examples">
		<!-- Compile the java code from ${src} into ${build} -->
		<javac srcdir="${src}" destdir="${build}" nowarn="off" optimize="${javac.optimize}" debug="${javac.debug}" deprecation="off" includes="examples/**" excludes="examples/jess/**,examples/JadeJessProtege/**" classpath="${lib}/jade.jar"/>
	</target>
	
	<!--  _______________________________________________
	                           JESS-based examples
	      _______________________________________________ -->
	<target name="jessexamples" depends="init,check_jess,lib" if="jess.home.is.set" description="compile the JESS-based examples ">
		<!-- Compile the java code from ${src} into ${build} -->
		<echo>Trying to compile the examples based on JESS. If the JESS library is not included into the CLASSPATH, a number of errors will be generated by the compiler but the task will contine.</echo>
		<javac srcdir="${src}" destdir="${build}" nowarn="off" optimize="${javac.optimize}" debug="${javac.debug}" deprecation="off" includes="examples/jess/** examples/JadeJessProtege/**" classpath="${lib}/jade.jar,${env.JESS_HOME}/jess.jar,${env.JESS_HOME}/JessTab.jar" failonerror="false"/>
	</target>
	
	<!--  _______________________________________________
	                           Demo
	      _______________________________________________ -->
	<target name="demo" depends="lib" description="compile the demo">
		<javac srcdir="${src}" destdir="${build}" nowarn="off" optimize="${javac.optimize}" debug="${javac.debug}" deprecation="off" includes="demo/**" classpath="${lib}/jade.jar,${root}/demo/CalendarBean.jar"/>
		<delete file="${demo}/MeetingScheduler.jar" quiet="true"/>
		<jar jarfile="${demo}/MeetingScheduler.jar" manifest="${demo}/demo.mf">
			<fileset dir="${build}" includes="**/demo/**"/>
		</jar>
	</target>
	
	<!--  _______________________________________________
	                           dist
	      _______________________________________________ -->
	<!-- Make distribution zip file and put in ${dist} -->
	<target name="dist" depends="reminder_javadoc,check_javacc,dist_src,dist_examples,dist_doc,dist_bin,dist_all"/>
	<target name="reminder_javadoc">
		<echo>REMINDER!!!!! The official javadoc documentation MUST be generated through the ANT target apidoc of the leap distribution. That target filters out all files and packages for which backward compatibility accross JADE versions is not guaranteed.</echo>
	</target>
	<target name="dist_src" depends="init,parser">
		<delete file="${dist}/JADE-src-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-src-${version}.zip">
			<zipfileset dir="." prefix="jade">
				<include name="src/FIPA/**"/>
				<include name="src/jade/**"/>
				<include name="src/*.idl"/>
				<include name="src/*.html"/>
				<include name="README"/>
				<include name="COPYNG"/>
				<include name="License"/>
				<!--<include name="ChangeLog"/>-->
				<include name="build.xml"/>
				<include name="build.properties"/>
				<include name="classes/*.mf"/>
				<include name="lib/commons-codec/**"/>
			</zipfileset>
			<!--
			<fileset dir="${dist}" includes="jade/src/FIPA/**"/>
			<fileset dir="${dist}" includes="jade/src/jade/**" excludes="jade/src/test/**"/>
			<fileset dir="${dist}" includes="jade/build.xml"/>
			<fileset dir="${dist}" includes="jade/README"/>
			<fileset dir="${dist}" includes="jade/COPYNG"/>
			<fileset dir="${dist}" includes="jade/ChangeLog"/>
			<fileset dir="${dist}" includes="jade/License"/>
			<fileset dir="${dist}" includes="jade/src/*.idl"/>
			<fileset dir="${dist}" includes="jade/src/*.html"/>
			<fileset dir="${dist}" includes="jade/classes/*.mf"/>
			<fileset dir="${dist}" includes="jade/lib/commons-codec/**"/>
			-->
		</zip>
	</target>
	<target name="dist_examples" depends="init">
		<delete file="${dist}/JADE-examples-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-examples-${version}.zip">
			<zipfileset dir="." prefix="jade">
				<include name="lib/jadeExamples.jar"/>
				<include name="src/examples/**"/>
				<include name="src/demo/**"/>
				<include name="demo/**"/>
				<include name="README"/>
				<include name="COPYNG"/>
				<include name="License"/>
				<!--<include name="ChangeLog"/>-->
			</zipfileset>
			<!--
			<fileset dir="${dist}" includes="jade/src/examples/**"/>
			<fileset dir="${dist}" includes="jade/src/demo/**"/>
			<fileset dir="${dist}" includes="jade/demo/**"/>
			<fileset dir="${dist}" includes="jade/README"/>
			<fileset dir="${dist}" includes="jade/COPYNG"/>
			<fileset dir="${dist}" includes="jade/ChangeLog"/>
			<fileset dir="${dist}" includes="jade/License"/>
			-->
		</zip>
	</target>
	
	<target name="dist_doc" depends="init,doc">
		<delete file="${dist}/JADE-doc-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-doc-${version}.zip">
			<zipfileset dir="." prefix="jade">
				<include name="doc/**"/>
				<include name="README"/>
				<include name="COPYNG"/>
				<include name="License"/>
				<!--<include name="ChangeLog"/>-->
			</zipfileset>
			<!--
			<fileset dir="${dist}" includes="jade/doc/**"/>
			<fileset dir="${dist}" includes="jade/README"/>
			<fileset dir="${dist}" includes="jade/COPYNG"/>
			<fileset dir="${dist}" includes="jade/ChangeLog"/>
			<fileset dir="${dist}" includes="jade/License"/>
			-->
		</zip>
	</target>
	
	<target name="dist_bin" depends="init,examples,demo">
		<delete file="demo/MeetingScheduler.jar" quiet="true"/>
		<jar jarfile="demo/MeetingScheduler.jar" manifest="demo/demo.mf">
			<fileset dir="${build}" includes="**/demo/**"/>
		</jar>
		<delete file="${dist}/JADE-bin-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-bin-${version}.zip">
			<zipfileset dir="." prefix="jade">
				<include name="lib/jade.jar"/>
				<include name="README"/>
				<include name="COPYNG"/>
				<include name="License"/>
				<!--<include name="ChangeLog"/>-->
			</zipfileset>
		</zip>
	</target>
	
	<target name="dist_all" depends="init,dist_src,dist_examples,dist_doc,dist_bin">
		<delete file="${dist}/JADE-all-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-all-${version}.zip">
			<fileset dir="${dist}" includes="JADE-src-${version}.zip"/>
			<fileset dir="${dist}" includes="JADE-examples-${version}.zip"/>
			<fileset dir="${dist}" includes="JADE-doc-${version}.zip"/>
			<fileset dir="${dist}" includes="JADE-bin-${version}.zip"/>
		</zip>
	</target>

	
	<!-- This target simply re-create the JADE-doc-x.y.zip (without recreating the javadoc) and the JADE-all-x.y.zip accordingly
	     It is used to create the final JADE distribution after having manually substituted the complete JADE Javadoc API with 
	     the official JADE API generated by the LEAP apidoc target -->
	<target name="dist_redoc" depends="init">
		<delete file="${dist}/JADE-doc-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-doc-${version}.zip">
			<zipfileset dir="." prefix="jade">
				<include name="doc/**"/>
				<include name="README"/>
				<include name="COPYNG"/>
				<include name="License"/>
				<!--<include name="ChangeLog"/>-->
			</zipfileset>
		</zip>
		<delete file="${dist}/JADE-all-${version}.zip" quiet="true"/>
		<zip zipfile="${dist}/JADE-all-${version}.zip">
			<fileset dir="${dist}" includes="JADE-src-${version}.zip"/>
			<fileset dir="${dist}" includes="JADE-examples-${version}.zip"/>
			<fileset dir="${dist}" includes="JADE-doc-${version}.zip"/>
			<fileset dir="${dist}" includes="JADE-bin-${version}.zip"/>
		</zip>
	</target>
</project>
