<project name="BUNDLEVIEWER" default="compile">

  <!-- set global properties for this build -->
  <property environment="env" />

  <property name="groupid" value="${env.GROUPID}" />
  <property name="authors" value="${env.AUTHORS}" />
  <property name="authoremail" value="${env.AUTHOREMAIL}" />
  <property name="clientemail" value="${env.CLIENTEMAIL}" />
  <property name="mailhost" value="${env.MAILHOST}" />
  <property name="junit.home" value="${env.JUNIT_HOME}" />
  <property name="public_tests.home" value="${env.PUBLIC_TESTS_HOME}" />
  <property name="public_tests.group_home" value="${public_tests.home}/${groupid}" />
  <property name="public_tests.logfile" value="${public_tests.home}/log.txt" />
  <property name="foreigntests.results" value="tests/results/" />


  <property name="src" value="src"/>
  <property name="build" value="build"/>
  <property name="dist"  value="dist"/>
  <property name="lib" value="lib"/>
  <property name="tests" value="tests" />
  <property name="tests.src" value="tests/src" />
  <property name="tests.data" value="tests/data" />
  <property name="tests.build" value="tests/build" />
  <property name="tests.results" value="tests/results" />
  <property name="tests.work" value="tests/work" />



  
  <path id="grappa.path">
    <pathelement location="../GRAPPA/grappa1_2.jar"/>
  </path>

  <path id="junit.path">
    <pathelement location="${junit.home}/junit.jar"/>
  </path>


    
  <path id="app.path">
    <path refid="grappa.path"/>
    <pathelement location="${build}"/>
  </path>

  <path id="tests.path">
    <pathelement location="${tests.build}"/>
    <path refid="junit.path"/>
    <path refid="app.path"/>
  </path>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>
  

  <target name="compileapp">
    <mkdir dir="${build}"/>
    <!-- Compile the java code from ${src} into ${build} -->
    <javac destdir="${build}">
      <src path="${src}"/>
      <classpath refid="app.path"/>
      <include name="fr/imag/reflect/bundle/**/*.java"/>
      <!--exclude name="fr/imag/reflect/*.java"/-->
      <!--exclude name="**/*ObjectStore*"/-->
    </javac>
  </target>

  <target name="compiletests" depends="compileapp">
    <!-- Compile the tests from ${src.tests} into ${build.tests} -->
    <mkdir dir="${tests.build}" />
    <javac destdir="${tests.build}">
      <src path="${tests.src}"/>
      <classpath refid="tests.path"/>
      <include name="fr/imag/reflect/bundle/**/*.java"/>
    </javac>
  </target>

  <target name="compile" depends="compileapp,compiletests">
  </target>
  
  <target name="test" depends="compiletests">
    <mkdir dir="${tests.results}"/>
    <junit printsummary="yes" fork="yes" haltonfailure="yes">
       <classpath refid="tests.path" />
       <formatter type="plain"/>
       <test name="fr.imag.reflect.bundle.NamingTest"
             todir="${tests.results}"/>
    </junit>
  </target>
  
  <target name="dist" depends="compile">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>
    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <!--jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/-->
    <jar jarfile="${dist}/lib/bundleviewer.jar" basedir="${build}" />
  </target>

  <target name="disttests" depends="compile">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>
    <jar jarfile="${dist}/lib/bundleviewertests.jar" basedir="${tests}"> 
       <fileset dir="${tests.build}">
          <include name="fr/imag/reflect/**"/>
       </fileset>
       <fileset dir="${tests.data}">
          <include name="**"/>
       </fileset>
    </jar>
  </target>

  <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> 
  <target name="distsrc" depends="dist,disttests">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>
    <jar jarfile="${dist}/lib/bundleviewersrc.jar" 
         basedir="."
         excludes="${dist}/lib/bundleviewersrc.jar"> 
    </jar>
  </target>

  <target name="publishtests" depends="disttests">
    <!-- Create the directory for the current group -->
    <mkdir dir="${public_tests.group_home}"/>
    <delete dir="${public_tests.group_home}/${tests}" />

    <copy file="${dist}/lib/bundleviewertests.jar" 
          todir="${public_tests.group_home}"/>
    <unjar src="${public_tests.group_home}/bundleviewertests.jar" 
           dest="${public_tests.group_home}/${tests}"/>
    <tstamp/>
    <echo file="${public_tests.logfile}" 
          append="true"
          message="${DSTAMP}:${TSTAMP} tests published : ${groupid}">
</echo>
  </target>

  <target name="publishapp" depends="dist">
    <!-- Create the directory for the current group -->
    <mkdir dir="${public_tests.group_home}"/>

    <copy file="${dist}/lib/bundleviewer.jar" 
          todir="${public_tests.group_home}"/>
    <tstamp/>
    <echo file="${public_tests.logfile}" 
          append="true"
          message="${DSTAMP}:${TSTAMP} app published   : ${groupid}">
</echo>
  </target>

  <target name="publish" depends="publishapp,publishtests" />

  <target name="foreigntestgid" depends="compiletests">
    <mkdir dir="${foreigntests.results}/${gid}/"/>
    <junit  
           fork="yes" 
           haltonfailure="no"
           dir="${public_tests.home}/${gid}/"
           filtertrace="on"
           printsummary="off">
       <classpath>
           <pathelement location="${public_tests.home}/${gid}/bundleviewertests.jar"/>
           <path refid="junit.path"/>
           <path refid="app.path"/>
       </classpath>
       <formatter type="plain"/>
       <batchtest todir="${foreigntests.results}/${gid}/">
           <fileset dir="${public_tests.home}/${gid}/${tests.build}">
               <include name="**/*ConformanceTest.class"/>
           </fileset>
       </batchtest>
    </junit>
  </target>

  <available property="foreigntest01" file="${public_tests.home}/01/tests" />
  <target name="foreigntest01" if="foreigntest01">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="01"/>
    </antcall>
  </target>

  <available property="foreigntest02" file="${public_tests.home}/02/tests" />
  <target name="foreigntest02" if="foreigntest02">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="02"/>
    </antcall>
  </target>

  <available property="foreigntest03" file="${public_tests.home}/03/tests" />
  <target name="foreigntest03" if="foreigntest03">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="03"/>
    </antcall>
  </target>

  <available property="foreigntest04" file="${public_tests.home}/04/tests" />
  <target name="foreigntest04" if="foreigntest04">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="04"/>
    </antcall>
  </target>

  <available property="foreigntest05" file="${public_tests.home}/05/tests" />
  <target name="foreigntest05" if="foreigntest05">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="05"/>
    </antcall>
  </target>

  <available property="foreigntest06" file="${public_tests.home}/06/tests" />
  <target name="foreigntest06" if="foreigntest06">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="06"/>
    </antcall>
  </target>

  <available property="foreigntest07" file="${public_tests.home}/07/tests" />
  <target name="foreigntest07" if="foreigntest07">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="07"/>
    </antcall>
  </target>

  <available property="foreigntest08" file="${public_tests.home}/08/tests" />
  <target name="foreigntest08" if="foreigntest08">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="08"/>
    </antcall>
  </target>

 <target name="foreigntest">
    <antcall target="foreigntest01"/>
    <antcall target="foreigntest02"/>
    <antcall target="foreigntest03"/>
    <antcall target="foreigntest04"/>
    <antcall target="foreigntest05"/>
    <antcall target="foreigntest06"/>
    <antcall target="foreigntest07"/>
    <antcall target="foreigntest08"/>
  </target>

  <target name="release" depends="clean,distsrc">
    <mkdir dir="${tests.results}"/>
    <mail mailhost="${mailhost}" 
          from="${authoremail}"
          subject="[PRI] ${groupid}:${authors}"
          tolist="${clientemail}"
          cclist="${authoremail}"
          files="${dist}/lib/bundleviewersrc.jar" />
  </target>

  <target name="clean">
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${tests.build}"/>
    <delete dir="${tests.results}"/>
    <delete dir="${dist}"/>
    <delete dir="${public_tests.group_home}" />
  </target>
</project>
