<project name="BUNDLEVIEWER" default="dist">


  <!-- set global properties for this build -->
  <property environment="env" />

  <!-- the property groupid should be set on the command line-->
  <property name="author1" value="Jean-Marie;Favre" />
  <property name="author2" value="Ioannis;Parissis" />
  <property name="authoremail" value="jmfavre@imag.fr" />
  <property name="mailhost" value="${env.MAILHOST}" />

  <property name="clientemail" value="Jean-Marie.Favre@imag.fr" />
  <property name="junit.home" value="${env.JUNIT_HOME}" />
  <property name="checkstyle.home" value="${env.CHECKSTYLE_HOME}" />
  <property name="checkstyle.jar" value="${env.CHECKSTYLE_JAR}" />
  <!-- property name="checkstyle.configurationfile" value="" /-->

  <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="foreignapps.results" value="tests/foreignapps/results/" />


  <property name="authors" value="${author1};${author2}" />
  <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="checkstyle.path">
    <pathelement location="${checkstyle.jar}"/>
  </path>

  <taskdef resource="checkstyletask.properties"
           classpath="${checkstyle.jar}"/>


    
  <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}" debug="on">
      <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}" debug="on">
      <src path="${tests.src}"/>
      <classpath refid="tests.path"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile" depends="compileapp,compiletests">
  </target>

  <target name="checkstyle" depends="compile">
    <mkdir dir="${build}/checkstyle" />
    <checkstyle 
          config="${checkstyle.configurationfile}"
          failureProperty="checkstyle.failure"
          failOnViolation="false">
      <fileset dir="${src}" includes="**/*.java"/>
      <property key="checkstyle.cache.file" file="${build}/checkstyle/cachefile"/>
      <!-- formatter type="plain"/ -->
      <formatter type="xml" toFile="${build}/checkstyle/errors.xml"/>
    </checkstyle>
  </target>


  <target name="report" depends="checkstyle">
     <xslt basedir="${build}/checkstyle" 
           destdir="${build}/checkstyle"
           includes="errors.xml"
           style="../../checkstyle-report.xsl" />
  </target>
  
  <target name="testconformance" depends="compiletests">
    <mkdir dir="${tests.results}"/>
    <junit printsummary="yes" fork="yes" haltonfailure="yes">
       <classpath refid="tests.path" />
       <formatter type="plain"/>
       <batchtest todir="${tests.results}">
           <fileset dir="${tests.build}">
               <include name="**/*ConformanceTest.class"/>
           </fileset>
       </batchtest>
    </junit>
  </target>

  <target name="test" depends="testconformance" />

  
  <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="**"/>
       </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="testforeignappgid" depends="compiletests">
    <mkdir dir="${foreignapps.results}/${gid}/" />
    <junit
           fork="yes"
           haltonfailure="no"
           dir="."
           filtertrace="on"
           printsummary="off">
      <classpath>
         <pathelement location="${tests.build}" />
         <path refid="junit.path"/>
         <pathelement location="${public_tests.home}/${gid}/bundleviewer.jar" />
      </classpath>
      <batchtest todir="${foreignapps.results}/${gid}/">
         <fileset dir="${tests.build}">
            <include name="**/*ConformanceTest.class"/>
         </fileset>
      </batchtest>
    </junit>
  </target>

  <available property="foreignapp01" file="${public_tests.home}/01/bundleviewer.jar" />
  <target name="testforeignapp01" if="foreignapp01">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="01"/>
    </antcall>
  </target>

  <available property="foreignapp02" file="${public_tests.home}/02/bundleviewer.jar" />
  <target name="testforeignapp02" if="foreignapp02">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="02"/>
    </antcall>
  </target>


  <available property="foreignapp03" file="${public_tests.home}/03/bundleviewer.jar" />
  <target name="testforeignapp03" if="foreignapp03">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="03"/>
    </antcall>
  </target>


  <available property="foreignapp04" file="${public_tests.home}/04/bundleviewer.jar" />
  <target name="testforeignapp04" if="foreignapp04">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="04"/>
    </antcall>
  </target>


  <available property="foreignapp05" file="${public_tests.home}/05/bundleviewer.jar" />
  <target name="testforeignapp05" if="foreignapp05">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="05"/>
    </antcall>
  </target>


  <available property="foreignapp06" file="${public_tests.home}/06/bundleviewer.jar" />
  <target name="testforeignapp06" if="foreignapp06">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="06"/>
    </antcall>
  </target>


  <available property="foreignapp07" file="${public_tests.home}/07/bundleviewer.jar" />
  <target name="testforeignapp07" if="foreignapp07">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="07"/>
    </antcall>
  </target>


  <available property="foreignapp08" file="${public_tests.home}/08/bundleviewer.jar" />
  <target name="testforeignapp08" if="foreignapp08">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="08"/>
    </antcall>
  </target>


  <available property="foreignapp09" file="${public_tests.home}/09/bundleviewer.jar" />
  <target name="testforeignapp09" if="foreignapp09">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="09"/>
    </antcall>
  </target>


  <available property="foreignapp10" file="${public_tests.home}/10/bundleviewer.jar" />
  <target name="testforeignapp10" if="foreignapp10">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="10"/>
    </antcall>
  </target>


  <available property="foreignapp11" file="${public_tests.home}/11/bundleviewer.jar" />
  <target name="testforeignapp11" if="foreignapp11">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="11"/>
    </antcall>
  </target>

  <available property="foreignapp12" file="${public_tests.home}/12/bundleviewer.jar" />
  <target name="testforeignapp12" if="foreignapp12">
    <antcall target="testforeignappgid" >   
      <param name="gid" value="12"/>
    </antcall>
  </target>

  <target name="testforeignapps">
    <antcall target="testforeignapp01"/>
    <antcall target="testforeignapp02"/>
    <antcall target="testforeignapp03"/>
    <antcall target="testforeignapp04"/>
    <antcall target="testforeignapp05"/>
    <antcall target="testforeignapp06"/>
    <antcall target="testforeignapp07"/>
    <antcall target="testforeignapp08"/>
    <antcall target="testforeignapp09"/>
    <antcall target="testforeignapp10"/>
    <antcall target="testforeignapp11"/>
    <antcall target="testforeignapp12"/>
  </target>

  <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>

  <available property="foreigntest09" file="${public_tests.home}/09/tests" />
  <target name="foreigntest09" if="foreigntest09">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="09"/>
    </antcall>
  </target>

  <available property="foreigntest10" file="${public_tests.home}/10/tests" />
  <target name="foreigntest10" if="foreigntest10">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="10"/>
    </antcall>
  </target>

  <available property="foreigntest11" file="${public_tests.home}/11/tests" />
  <target name="foreigntest11" if="foreigntest11">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="11"/>
    </antcall>
  </target>

  <available property="foreigntest12" file="${public_tests.home}/12/tests" />
  <target name="foreigntest12" if="foreigntest12">
    <antcall target="foreigntestgid" >   
      <param name="gid" value="12"/>
    </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"/>
    <antcall target="foreigntest09"/>
    <antcall target="foreigntest10"/>
    <antcall target="foreigntest11"/>
    <antcall target="foreigntest12"/>
  </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}" />
    <delete dir="${foreignapps.results}" />
  </target>
</project>