<!-- ObJectBridge build configuration. Author: Thomas Mahler-->
<project name="ObJectRelationalBridge" default="all" basedir=".">
	<!-- Initialize path names and other constants -->
	<target name="init">
		<available property="junit.present" classname="junit.framework.TestCase"/>
		<property name="source" value="src"/>
		<property name="ojb" value="${source}/ojb"/>
		<property name="etc" value="${source}/etc"/>
		<property name="build" value="build"/>
		<property name="classes" value="${build}/classes"/>
		<property name="examples" value="${build}/examples"/>
		<property name="test" value="${build}/test"/>
		<property name="dist" value="dist"/>
		<property name="lib" value="lib"/>
		<property name="doc" value="doc"/>
		<property file="${etc}/VERSION"/>
		<property name="classpath" value="${classpath}:${classes}:${source}:${lib}/antlr_compiletime.jar:${lib}/junit.jar:${lib}/jaxp.jar:${lib}/ejb.jar"/>
		<property name="runtime_classpath" value="${classpath}:${lib}/db2java.zip:${lib}/idb.jar:${lib}/jta-spec1_0_1.jar:${lib}/idbexmpl.jar:${lib}/junit.jar:${lib}/jaxp.jar:${lib}/parser.jar:${lib}/xerces.jar:${lib}/antlr.jar"/>
		<property name="deprecation" value="true"/>
		<property name="archive" value="${project}-${version}"/>
		<property name="excludes" value=""/>
		<property name="testexcludes" value="**/package.html"/>
		<property name="apipackagenames" value="ojb.broker.*,ojb.odmg.*,org.odmg.*"/>
		<property name="allpackagenames" value="examples.*,ojb.*,org.odmg.*,javax.*,test.*"/>
	</target>
	<!-- Display all the targets -->
	<target name="targets" depends="init">
		<echo message=""/>
		<echo message="ANT build for ${name} ${version}"/>
		<echo message=""/>
		<echo message="The following targets are available:"/>
		<echo message="  targets  Lists the build targets"/>
		<echo message="  clean    Cleans the build and distribution directories"/>
		<echo message="  all      Cleans and builds all the packages and examples"/>
		<echo message="  release  Cleans and builds all the release packages"/>
		<echo message="           (JAR, source, doc, tarball) in the dist directory"/>
		<echo message="  main     Builds the main packages (including debugging info)"/>
		<echo message="  examples Builds the example packages (including debugging info)"/>
		<echo message="  junit    Performs JUnit regression tests"/>
		<echo message="  jar      Builds the binary JAR in the dist directory"/>
		<echo message="  doc      Builds the documentation"/>
		<echo message="  api      Builds the API JavaDocs"/>
		<echo message="  javadoc  Builds the full JavaDocs"/>
		<echo message="  source   Builds the source tarball in the dist directory"/>
		<echo message="  tarball  Builds the binary distribution in the dist directory"/>
		<echo message="  cvs      Update the sources from the CVS"/>
		<echo message=""/>
	</target>
	<!-- Prepare target directories -->
	<target name="prepare" depends="init">
		<mkdir dir="${build}"/>
		<mkdir dir="${classes}"/>
		<mkdir dir="${dist}"/>
	</target>
	<!-- Kill all the directories created in prepare -->
	<target name="clean" depends="init">
		<delete dir="${build}" verbose="false"/>
		<delete dir="${dist}" verbose="false"/>
	</target>
	<!-- Build all the sources with debug and deprecation -->
	<target name="main" depends="prepare">
		<javac srcdir="${source}" destdir="${classes}" excludes="${excludes}" classpath="${classpath}" debug="on" deprecation="${deprecation}"/>
	</target>

	<!-- Same as main, but also cleans and additional targets -->
	<target name="all" depends="clean,oql,main,tests,doc,api,javadoc"/>
	<!-- Same as main, but optimization, no debug and no deprecation -->
	<target name="main-opt" depends="prepare">
		<javac srcdir="${source}" destdir="${classes}" excludes="${excludes}" classpath="${classpath}" debug="off" deprecation="off" optimize="on"/>
	</target>
	<!-- Build everything needed for the JUnit tests -->
	<target name="tests" depends="prepare">
		<mkdir dir="${test}/ojb/broker"/>
		<mkdir dir="${test}/ojb/odmg"/>
		
		<mkdir dir="${test}/setup"/>
		<copy todir="${test}/ojb">
			<fileset dir="${source}/test/ojb" includes="repository.*,*.properties"/>
		</copy>
		<copy todir="${test}/ojb/broker">
			<fileset dir="${source}/test/ojb/broker" excludes="*.java"/>
		</copy>
		<copy todir="${test}/ojb/odmg">
			<fileset dir="${source}/test/ojb/odmg" excludes="*.java"/>
		</copy>
		
		<copy todir="${test}/setup">
			<fileset dir="${source}/test/setup"/>
		</copy>
		<java classname="com.lutris.instantdb.ScriptTool" fork="yes" dir="${test}/setup" maxmemory="128m" classpath="${runtime_classpath}"/>
	</target>
	<!-- Build the JAR file using main-opt -->
	<target name="jar" depends="main-opt">
		<delete file="${dist}/${archive}.jar"/>
		<delete file="${classes}/MANIFEST.MF"/>
		<copy file="${source}/etc/MANIFEST.MF" tofile="${classes}/MANIFEST.MF"/>
		<replace file="${classes}/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
		<copy todir="${classes}">
			<fileset dir="${source}/etc" excludes="MANIFEST.MF"/>
		</copy>
		<jar jarfile="${dist}/${archive}.jar" basedir="${classes}" manifest="${classes}/MANIFEST.MF" includes="LICENSE,README,ojb/**,org/**,test/**"/>
	</target>

	<!-- Build the documentation -->
	<target name="doc" depends="prepare, javadoc, api, htmldoc">
	</target>

	<!-- Build the html-documentation -->
	<target name="htmldoc" depends="prepare">
		<mkdir dir="${build}/doc"/>
		<copy todir="${build}/doc">
			<fileset dir="${source}/doc"/>
		</copy>
		<replace dir="${build}/doc" token="$$FOOTER$$" value="release: ${version}, date: ${versiondate}">
			<include name="**/*.html"/>
		</replace>
	</target>
	<!-- Build the full JavaDocs -->
	<target name="javadoc" depends="prepare">
		<mkdir dir="${build}/doc/javadoc"/>
		<javadoc sourcepath="${source}" destdir="${build}/doc/javadoc" doctitle="${icon}${br}${name} ${version} JavaDoc " windowtitle="${name} ${version} JavaDoc" bottom="${copyright}${br}Version: ${version}, ${versiondate}" package="true" author="true" version="true" noindex="true" packagenames="${allpackagenames}"/>
	</target>
	<!-- Build the API JavaDocs -->
	<target name="api" depends="prepare">
		<mkdir dir="${build}/doc/api"/>
		<javadoc sourcepath="${source}" destdir="${build}/doc/api" doctitle="${icon}${br}${name} ${version} API" windowtitle="${name} ${version} API" bottom="${copyright}${br}Version: ${version}, ${versiondate}" public="true" author="true" packagenames="${apipackagenames}"/>
	</target>
	<!-- Build the docs, API and full JavaDocs, doc archives -->
	<target name="docs" depends="doc">
		<zip zipfile="${dist}/${archive}-doc.zip" basedir="${build}" includes="doc/**"/>
		<tar tarfile="${dist}/${archive}-doc.tar" basedir="${build}" includes="doc/**"/>
		<gzip src="${dist}/${archive}-doc.tar" zipfile="${dist}/${archive}-doc.tgz"/>
		<delete file="${dist}/${archive}-doc.tar"/>
	</target>

	<!-- Build the website -->
	<target name="website" depends="doc">
		<tar tarfile="${dist}/${archive}-website.tar" basedir="${build}/doc" includes="**"/>
		<gzip src="${dist}/${archive}-website.tar" zipfile="${dist}/${archive}-website.tgz"/>
		<delete file="${dist}/${archive}-website.tar"/>
	</target>
	

	<!-- Build the source distribution -->
	<target name="source" depends="prepare,oql">
		<delete file="${dist}/${archive}-src.tgz"/>
		<delete file="${dist}/${archive}-src.zip"/>
		<delete dir="${build}/${archive}"/>
		<mkdir dir="${build}/${archive}"/>
		<mkdir dir="${build}/${archive}/src"/>
		<copy todir="${build}/${archive}/src">
			<fileset dir="${source}"/>
		</copy>
		<mkdir dir="${build}/${archive}/lib"/>
		<copy todir="${build}/${archive}/lib">
			<fileset dir="${lib}"/>
		</copy>
		
		<copy todir="${build}/${archive}">
			<fileset dir="." includes="*.sh,*.bat,*.xml,*.html,*.txt"/>
		</copy>
		<tar includes="${archive}/**" basedir="${build}" tarfile="${dist}/${archive}-src.tar"/>
		<gzip src="${dist}/${archive}-src.tar" zipfile="${dist}/${archive}-src.tgz"/>
		<delete file="${dist}/${archive}-src.tar"/>
		<zip zipfile="${dist}/${archive}-src.zip" basedir="${build}" includes="${archive}/**"/>
	</target>
	<!-- Build a full release including JAR, zip/tarball, source and documentation -->
	<target name="release" depends="jar,source,docs,tarball,website"/>
	<!-- Build the tarball including JAR and all dependent packages -->
	<target name="tarball" depends="prepare,jar,doc">
		<delete file="${dist}/${archive}.tgz"/>
		<delete file="${dist}/${archive}.zip"/>
		<delete dir="${build}/${archive}"/>
		<mkdir dir="${build}/${archive}"/>
		<copy todir="${build}/${archive}">
			<fileset dir="${etc}" includes="README,LICENSE,CHANGELOG"/>
		</copy>
		<copy todir="${build}/${archive}">
			<fileset dir="${dist}" includes="${archive}.jar,${archive}-xml.jar"/>
		</copy>
		<copy todir="${build}/${archive}">
			<fileset dir="${lib}" includes="jdbc-se2.0.jar,jndi.jar,jta1.0.1.jar,xerces.jar,ldapjdk.jar,xslp.jar"/>
		</copy>
		<copy todir="${build}/${archive}/doc">
			<fileset dir="${build}/doc"/>
		</copy>
		<delete dir="${build}/${archive}/doc/javadoc"/>
		<tar tarfile="${build}/${archive}/examples.tar" basedir="${source}" includes="examples/**" defaultexcludes="true"/>
		<gzip src="${build}/${archive}/examples.tar" zipfile="${build}/${archive}/examples.tgz"/>
		<tar tarfile="${dist}/${archive}.tar" basedir="${build}" includes="${archive}/**" excludes="${archive}/*.tar,${archive}/*.zip"/>
		<gzip src="${dist}/${archive}.tar" zipfile="${dist}/${archive}.tgz"/>
		<delete file="${dist}/${archive}.tar"/>
		<zip zipfile="${build}/${archive}/examples.zip" basedir="${source}" includes="examples/**" defaultexcludes="true"/>
		<zip zipfile="${dist}/${archive}.zip" basedir="${build}" includes="${archive}/**" excludes="${archive}/*.tar,${archive}/*.tgz"/>
	</target>
	<!-- Perform JUnit Tests -->
	<target name="junit" depends="main, tests" if="junit.present">
		<!-- This is the broker module test-->
		<echo message="Using classpath: ${runtime_classpath}"/>
		<java fork="yes" classname="junit.textui.TestRunner" dir="${test}/ojb" taskname="junit" failonerror="true" classpath="${runtime_classpath}">
			<arg value="test.ojb.broker.AllTests"/>
			<!--jvmarg value="-Xrunhprof:cpu=samples,file=broker.hprof.txt" /-->
			</java>
		<!-- This is the odmg module test-->
		<java fork="yes" classname="junit.textui.TestRunner" dir="${test}/ojb" taskname="junit" failonerror="true" classpath="${runtime_classpath}">
			<arg value="test.ojb.odmg.AllTests"/>
			<!--jvmarg value="-Xrunhprof:cpu=samples,file=odmg.hprof.txt" /-->
		</java>
	</target>


	<!-- Performance tests -->
	<target name="performance" depends="main-opt, tests" if="junit.present">
		<echo message="Using classpath: ${runtime_classpath}"/>
		<java fork="yes" classname="junit.textui.TestRunner" dir="${test}/ojb" taskname="junit" failonerror="true" classpath="${runtime_classpath}">
			<arg value="test.ojb.broker.PerformanceTest"/>
			<!--jvmarg value="-Xrunhprof:cpu=times,file=perf.hprof.txt" /-->
		</java>
	</target>

	<!-- Browse Demo Database -->
	<target name="browse_db" depends="init">
		<java fork="yes" classname="com.lutris.instantdb.DBBrowser" dir="${test}/setup" taskname="browse" failonerror="false" classpath="${runtime_classpath}">
			<arg value="jdbc:idb:demo.prp"/>
			
		</java>
	</target>


	<!-- run broker examples -->
	<target name="run_broker_example" depends="main, tests" if="junit.present">
		<java fork="yes" classname="junit.textui.TestRunner" dir="${test}/ojb" taskname="junit" failonerror="true" classpath="${runtime_classpath}">
			<arg value="test.ojb.broker.BrokerExamples"/>
		</java>
		<java fork="yes" classname="junit.textui.TestRunner" dir="${test}/ojb" taskname="junit" failonerror="true" classpath="${runtime_classpath}">
			<arg value="test.ojb.broker.ProxyExamples"/>
		</java>
	</target>
	<!-- run odmg examples -->
	<target name="run_odmg_example" depends="main, tests" if="junit.present">
		<java fork="yes" classname="junit.textui.TestRunner" dir="${test}/ojb" taskname="junit" failonerror="true" classpath="${runtime_classpath}">
			<arg value="test.ojb.odmg.OdmgExamples"/>
		</java>
	</target>
	<!-- run all examples -->
	<target name="run_examples" depends="run_broker_example, run_odmg_example" if="junit.present"/>
	
	<!-- build OQL Parser classes from oql-ojb.g grammar -->
	<target name="oql" depends="init">
		<java fork="yes" classname="antlr.Tool" dir="${source}/ojb/odmg/oql" taskname="build oql parser" failonerror="true" classpath="${classpath}:${lib}/antlr_compiletime.jar">
			<arg value="oql-ojb.g" />
		</java>
	</target>
	
	
	<!-- checkout from the CVS -->
	<target name="cvs">
		<echo message="give cvs passwd:"/>
		<cvs command="-z3 co objectbridge" dest=".."/>
	</target>
</project>


