<project name="testng-spring" default="both" basedir=".">

  <target name="init">
    <tstamp />
    <property file="../build.properties" />
    <property file="build.properties" />
    <!-- Settings -->
    <property name="jdk" value="jdk14" />
    <property name="optimize" value="false" />
    <property name="debug" value="true" />
    
    <!--  Directories -->
    <property name="src.dir" location="src" />
    <property name="topbuild.dir" location="build" />
    <property name="build.dir" location="${topbuild.dir}/${jdk}" />
    <property name="classes.dir" location="${build.dir}/classes" />      
    <property name="dependencies.dir" location="lib" />
    <property name="topjavadocs.dir" location="javadocs" />
    <property name="javadocs.dir" location="${topjavadocs.dir}/${jdk}" />
    
      <property name="testng.spring.jar" location="testng-spring-${jdk}.jar" />

    <condition property="source.version" value="1.4"><equals arg1="${jdk}" arg2="jdk14"/></condition>
    <condition property="source.version" value="1.5"><equals arg1="${jdk}" arg2="jdk15"/></condition>
  </target>
  
  <target name="paths" depends="init">
    <path id="src.path">
      <pathelement path="${src.dir}/common" />
      <pathelement path="${src.dir}/${jdk}" />
    </path>
    <path id="compile.path">
      <fileset dir="${dependencies.dir}">
        <include name="*.jar" />
      </fileset>
      <pathelement path="../testng-${testng.version}-${jdk}.jar" />
    </path>
  </target>
  
  <target name="compile" depends="paths" description="compile sources">
    <echo message="                                 -- Compiling ${jdk} sources --" />
    <mkdir dir="${classes.dir}"/>
    <javac   source="${source.version}" target="${source.version}"
        debug="${debug}" optimize="${optimize}" 
            destdir="${classes.dir}">
      <src refid="src.path" />
      <classpath refid="compile.path" />
    </javac>
  </target>

  <target name="jar" depends="compile">
    <echo message="                                 -- Creating ${jdk} jar --" />
    <jar destfile="${testng.spring.jar}">
      <fileset dir="${classes.dir}" />
    </jar>
  </target>

  <target name="javadoc" depends="paths" description="generate api documentation">
    <echo message="                                 -- Generating javadocs for ${jdk} --" />
    <mkdir dir="${javadocs.dir}" />
      <javadoc destdir="${javadocs.dir}" source="${source.version}" windowtitle="TestNG Spring Support" classpathref="compile.path">
      <fileset dir="${src.dir}/common" defaultexcludes="yes" includes="**/*.java" />
          <fileset dir="${src.dir}/${jdk}" defaultexcludes="yes" includes="**/*.java" />
      </javadoc>
  </target>
  
  <target name="both">
    <property name="target" value="jar"/>
    <antcall target="${target}">
      <param name="jdk" value="jdk14"/>
    </antcall>
    <antcall target="${target}">
      <param name="jdk" value="jdk15"/>
    </antcall>
  </target>
  
  <target name="dist" description="builds both jdk14 and jdk15 variants">
    <antcall target="both"><param name="target" value="jar"/></antcall>
  </target>
  
  <target name="javadocs" description="builds both jdk14 and jdk15 javadocs">
    <antcall target="both"><param name="target" value="javadoc"/></antcall>
  </target>
  
  <target name="all" depends="dist,javadocs" description="build jar files and javadocs" />
  
  <target name="clean" depends="paths" description="cleans all">
    <delete dir="${topbuild.dir}" />
    <delete dir="${topjavadocs.dir}" />
    <delete file="testng-spring-jdk14.jar" />
    <delete file="testng-spring-jdk15.jar" />
  </target>
  
</project>
