<?xml version="1.0"?>
<!-- ant build file for the sinfo@sibarra autobuild process. Comments inline -->
<project name="build" default="full" basedir="d:/classes/src">

  <!-- properties needed for the build -->
	<property name="temp"             value="c:/temp"/>
	<property name="source_root"      value="d:/trabajos/" />
	<property name="source"           value="${source_root}VSS/"/>
	<property name="build"            value="d:/classes"/>
	<property name="src"              value="${build}/src/"/>
	<property name="doc"              value="${build}/docs/api"/>
	<property name="webapps"          value="${source}sinfo/java/webapps/sinfo/"/>
	<property name="apache"           value="d:/apache/" />
	<property name="api_docs"         value="${apache}/docs/api"/>
	<property name="test.results.dir" value="${apache}/docs/test"/>
	<property name="msl"              value="${src}msl/"/>


  <!-- properties needed for running unit tests -->
	<property name="jhome"          value="e:/jdk1.3" />
	<property name="tomcat"         value="d:/jakarta-tomcat-4.0" />
	<property name="tomcat.home.40" value="${tomcat}" />
	<property name="cachedir"       value="d:/info2001/pub/html/D/ENG/re/" />
	<property name="cactus.ant.jar" value="e:/ant/lib/cactus-ant.jar" />
  <property name="cactus.servletRedirectorURL" value="http://127.0.0.1:8080/sinfo/ServletRedirector" />


  <!-- Initialize custom Ant task needed for running the server tests -->
  <taskdef name="runservertests" classname="org.apache.cactus.ant.RunServerTestsTask">
    <classpath>
      <pathelement location="${cactus.ant.jar}"/>
      <pathelement path="${java.class.path}"/>
    </classpath>
  </taskdef>

  <!-- calls doc; regardless of whether this works or not will call mail -->
  <target name="full">
    <antcall target="preclean" />
    <antcall target="vss" />
    <antcall target="doc" />
    <!--<antcall target="mail" />-->
  </target>


  <!-- wipes everything - the old vss directory structure, the old copies, classes... everything -->
	<target name="preclean">
		<tstamp/>
		<delete dir="${build}"/>
		<mkdir dir="${build}"/>
		<mkdir dir="${src}"/>
		<mkdir dir="${test.results.dir}"/>
		<delete dir="${source}" />
		<mkdir dir="${source}" />
	</target>

  <!-- gets the source from source safe. This gets *everything* -->
  <target name="vss">
    <vssget localPath="d:/trabajos/VSS"
            recursive="true"
            login="PC_OSIBARRA,pc_osibarra"
            vsspath="/"/>
  </target>

  <!-- copies most of the source to d:/classes/src, creating the correct directory
       structure in the process -->
	<target name="copy_src">
		<echo>Copying msl 'n DFC source</echo>
		<copy todir="${src}" includeEmptyDirs="no">
			<fileset dir="${source}/common/java/">
				<exclude name="**/DFClient/*.*" />
				<exclude name="**/*.scc"/>
				<exclude name="**/*.bak"/>
				<exclude name="**/*.form"/>
				<exclude name="**/.nbattrs"/>
				<exclude name="**/*.sc"/>
				<exclude name="**/*.h"/>
			</fileset>
			<fileset dir="${source}/common/java/DFClient" />
			<fileset dir="${source}/sinfo/java/" >
				<exclude name="**/*.scc"/>
				<exclude name="**/*.bak"/>
				<exclude name="**/*.form"/>
				<exclude name="**/.nbattrs"/>
				<exclude name="**/*.sc"/>
				<exclude name="**/*.h"/>
				<exclude name="webapps/**"/>
			</fileset>
		</copy>
		<!-- copy the non-source files to build as well -->
		<copy todir="${build}">
			<fileset dir="${src}">
				<exclude name="**/*.java"/>
				<exclude name="**/*TEST*"/>
			</fileset>
		</copy>
	</target>

	<!-- The main compile task -->
  <target name="compile" depends="copy_src">
  	<echo>Compiles all. Let the compiler sort it out.</echo>
		<javac
		       srcdir="${src}"
		      destdir="${build}"
		  deprecation="on"/>
	</target>


	<!-- jars & wars -->
	<target name="distribution" depends="compile">
    <tstamp>
      <format property="TODAY_UK" pattern="yyyy-MM-dd" locale="en"/>
    </tstamp>
		<!-- jar the classes to sinfo -->
		<delete>
		  <fileset dir="${temp}">
		    <include name="sinfo.jar" />
		  </fileset>
		</delete>
		<jar jarfile="${temp}/sinfo.jar" basedir="${build}" excludes="**/*.java,**/src/**"/>
		<copy todir="${webapps}/WEB-INF/lib/">
			<fileset dir="${temp}">
				<include name="sinfo.jar"/>
			</fileset>
		</copy>
		<!-- make .jar available for download -->
		<copy   file="${temp}/sinfo.jar"
		      tofile="${apache}/docs/distribution/sinfo_${TODAY_UK}.jar" />

		<!-- make the web-application (.war) file -->
    <war warfile="${temp}/sinfo.war" webxml="${webapps}WEB-INF/web.xml">
      <fileset dir="${webapps}">
        <exclude name="WEB-INF/lib/**" />
        <exclude name="WEB-INF/classes/**" />
        <exclude name="WEB-INF/web.xml" />
      </fileset>
      <lib dir="${webapps}WEB-INF/lib" />
      <classes dir="${webapps}WEB-INF/classes"/>
    </war>
		<!-- make .war available for download -->
		<copy   file="${temp}/sinfo.war"
		      tofile="${apache}/docs/distribution/sinfo_${TODAY_UK}.war" />
  </target>

  <target name="pabla">
    <apply executable="java">
      <arg value="sinfo.optiontabler.NotifyTables" />
      <fileset dir="d:/trabajos/vss/sinfo/java/sinfo/updater/maps">
        <include name="**/*.map"/>
    	</fileset>
    </apply>
  </target>

  <!-- prepares the system for the tests -->
  <target name="prepare_for_tests" depends="distribution">
    <mkdir dir="${cachedir}/BV" />
    <mkdir dir="${cachedir}/HO" />
    <delete>
      <fileset dir="${cachedir}/BV" />
      <fileset dir="${cachedir}/HO" />
    </delete>
    <copy todir="${cachedir}/BV">
      <fileset dir="d:/trabajos">
        <include name="/holder/testData/BV-008" />
      </fileset>
    </copy>
  </target>

  <!-- runs the tests -->
  <target name="tests" depends="prepare_for_tests" if="tomcat">
    <runservertests testURL="http://localhost:8080"
                    startTarget="start_tomcat"
                    stopTarget="stop_tomcat"
                    testTarget="test_definitions"/>
  </target>


	<!-- javadoc the whole thing -->
	<target name="doc" depends="tests">
		<tstamp/>
		<delete dir="${doc}"/>
		<mkdir dir="${doc}"/>
		<javadoc sourcepath="${src}"
		         packagenames="msl.*, sinfo.*, jmq.*, dfManager.*"
		         destdir="${doc}"
		         package="true"
		         author="true"
		         version="true" use="true" windowtitle="Sinfo API" bottom="&lt;center>Copyright &#169; 2001 ${TODAY} MSL Software S.L. All Rights Reserved.&lt;/center>">
			<group title="MSL (common code) packages" packages="msl.*"/>
			<group title="Sinfo Packages" packages="sinfo.*"/>
			<group title="DF manager packages" packages="dfManager.*" />
			<group title="jmq packages" packages="jmq.*" />
		</javadoc>
		<copy todir="${api_docs}/">
			<fileset dir="${doc}/"/>
		</copy>
	</target>

  <!-- sends the results of the build to everyone in the list -->
  <target name="mail">
    <mail from="<my mail>"
          tolist="<supressed :)>"
          mailhost="<server>"
          subject="daily build: resultados"
          files="${source_root}build.log"/>
  </target>

  <!-- the junit/cactus test definitions -->
  <target name="test_definitions">
		<junit
			printsummary="withOutAndErr"
			fork="no"
			haltonfailure="no">
  		<formatter type="xml" />
  		<test name="sinfo.utils.UtilsTestSuite" />
  		<test name="sinfo.tm.TMTestSuite" />
  		<test name="sinfo.pid.PIDTestSuite" />
  		<test name="sinfo.rrm.RRMTestSuite" />
  		<test name="sinfo.jsp.utils.JSPUtilsTestSuite" />
  		<test name="sinfo.cache.CacheTestSuite" />
  		<test name="sinfo.optiontabler.utils.OptionTablerUtilsTestSuite" />
  		<test name="msl.utils.MSLUtilsTestSuite" />
		</junit>
    <junitreport todir="${test.results.dir}">
      <fileset dir="${src}" includes="TEST-*.xml"/>
      <report format="noframes" todir="${test.results.dir}"/>
    </junitreport>
  </target>


  <!-- start tomcat -->
  <target name="start_tomcat">
    <java classname="org.apache.catalina.startup.Bootstrap" fork="yes">
      <jvmarg value="-Dcatalina.home=${tomcat.home.40}"/>
      <arg value="-config"/>
      <arg value="${tomcat.home.40}/conf/server.xml"/>
      <arg value="start"/>
      <classpath>
        <pathelement location="${java.home}/../lib/tools.jar"/>
        <fileset dir="${tomcat.home.40}">
          <include name="bin/bootstrap.jar"/>
          <include name="server/catalina.jar"/>
        </fileset>
      </classpath>
    </java>
  </target>

  <!-- stop tomcat -->
  <target name="stop_tomcat">
    <java classname="org.apache.catalina.startup.Bootstrap" fork="yes">
      <jvmarg value="-Dcatalina.home=${tomcat.home.40}"/>
      <arg value="stop"/>
      <classpath>
        <fileset dir="${tomcat.home.40}">
          <include name="bin/bootstrap.jar"/>
          <include name="server/catalina.jar"/>
        </fileset>
      </classpath>
    </java>
  </target>
</project>
