<!-- Ant build file for Swift Mailer (Standard Edition) -->
<project name="Swift Mailer SE" default="bundle">
  
  <!-- Config settings -->
  <property name="path" value="." />
  <property name="builddir" value="${path}/build" />
  <property name="src.versionfile" value="${path}/VERSION" />
  <!-- Generate version info from VERSION file -->
  <loadfile property="bundle.name" srcFile="${src.versionfile}">
    <filterchain>
      <striplinebreaks />
    </filterchain>
  </loadfile>
  <!-- Generate version number -->
  <loadfile property="bundle.version" srcFile="${src.versionfile}">
    <filterchain>
      <striplinebreaks />
      <tokenfilter>
        <replacestring from="Swift-" to=""/>
      </tokenfilter>
    </filterchain>
  </loadfile>
  <property name="src.readmefile" value="${path}/README" />
  <property name="src.changesfile" value="${path}/CHANGES" />
  <property name="src.libdir" value="${path}/lib" />
  <property name="src.testsuite" value="${path}/test-suite" />
  <property name="src.tests" value="${path}/tests" />
  <property name="builddir.package" value="${builddir}/${bundle.name}" />
  <property name="runtests" value="" />
  <filelist id="src.licenses" dir="${path}">
    <file name="LICENSE" />
  </filelist>
  <fileset id="build.simpletest.unneeded"
    dir="${builddir.package}/test-suite/lib/simpletest">
    <include name="docs/" />
    <include name="tutorials/" />
    <include name="extensions/" />
    <include name="test/" />
    <include name="packages/" />
  </fileset>
  
  
  <!-- Bundle all files into a central location -->
  <target name="bundle" depends="prepare, clean, copy-classes">
    <copy file="${src.versionfile}" todir="${builddir.package}" />
    <copy file="${src.changesfile}" todir="${builddir.package}" />
    <copy todir="${builddir.package}">
      <filelist refid="src.licenses" />
    </copy>
    <copy file="${src.readmefile}" todir="${builddir.package}" />
    <move file="${builddir.package}/tests/acceptance.conf.php.default"
      tofile="${builddir.package}/tests/acceptance.conf.php" />
    <move file="${builddir.package}/tests/smoke.conf.php.default"
      tofile="${builddir.package}/tests/smoke.conf.php" />
  </target>
  
  <!-- Copy some *.default files to their required files if needed -->
  <target name="prepare">
    <copy file="${src.tests}/acceptance.conf.php.default"
      tofile="${src.tests}/acceptance.conf.php" />
      <copy file="${src.tests}/smoke.conf.php.default"
        tofile="${src.tests}/smoke.conf.php" />
  </target>
  
  <!-- Clean out the build directory -->
  <target name="clean">
    <delete includeemptydirs="true">
      <fileset dir="${builddir}" includes="**/*" />
    </delete>
  </target>
  
  <!-- Copy all classes from the class path to the bundle -->
  <target name="copy-classes">
    <copy todir="${builddir.package}/lib">
      <fileset dir="${src.libdir}" />
      <filterchain>
        <replacetokens>
          <token key="SWIFT_VERSION_NUMBER" value="${bundle.version}"/>
        </replacetokens>
      </filterchain>
    </copy>
    <copy todir="${builddir.package}/test-suite">
      <fileset dir="${src.testsuite}" />
    </copy>
    <copy todir="${builddir.package}/tests">
      <fileset dir="${src.tests}" />
    </copy>
    <delete includeemptydirs="true">
      <fileset refid="build.simpletest.unneeded" />
    </delete>
  </target>
  
  <!-- Package up the project as a gzip file -->
  <target name="package" depends="test, bundle">
    <tar destfile="${builddir.package}.tar.gz" compression="gzip" longfile="gnu">
      <fileset dir="${builddir}" />
    </tar>
    <delete includeemptydirs="true">
      <fileset dir="${builddir.package}" includes="**" />
    </delete>
  </target>
  
  <!-- Run the included unit tests -->
  <target name="test" depends="prepare, clean, copy-classes">
    <exec executable="php" failonerror="true">
      <env key="_" value="php" />
      <arg value="${builddir.package}/test-suite/run.php" />
      <arg value="${runtests}" />
    </exec>
  </target>
  
</project>
