<?xml version="1.0"?>

<project name="EasyRdf" default="default">
  <property name="version" value="0.6.2" />
  <property name="shortname" value="easyrdf" />
  <property name="shortdesc" value="PHP library for working with RDF as objects." />
  <property name="homepage" value="http://www.aelius.com/njh/easyrdf/" />

  <property name="reports.dir" value="${project.basedir}/reports" override="true" />
  <property name="docs.dir" value="${project.basedir}/docs" override="true" />
  <property name="dist.dir" value="${project.basedir}/dist" override="true" />
  <property name="logger" value="phing.listener.DefaultLogger" override="true" />

  <includepath classpath="${project.basedir}/lib" />

  <fileset id="source" dir="${project.basedir}">
    <include name="lib/EasyRdf.php" />
    <include name="lib/EasyRdf/*.php" />
    <include name="lib/EasyRdf/**/*.php" />
  </fileset>

  <fileset id="tests" dir="${project.basedir}">
    <include name="test/EasyRdf/*Test.php" />
    <include name="test/EasyRdf/**/*Test.php" />
  </fileset>

  <fileset id="test-support" dir="${project.basedir}">
    <include name="test/TestHelper.php" />
    <include name="test/EasyRdf/TestCase.php" />
    <include name="test/EasyRdf/Http/MockClient.php" />
    <include name="test/fixtures/*" />
  </fileset>

  <fileset id="examples" dir="${project.basedir}">
    <include name="examples/*.php" />
  </fileset>

  <fileset id="docs" dir="${project.basedir}">
    <include name="docs/*" />
    <include name="docs/*/*" />
    <include name="README.md" />
    <include name="LICENSE.md" />
    <include name="CHANGELOG.md" />
  </fileset>

  <target name="test" depends="dir_setup" description="Run all unit tests.">
    <phpunit haltonfailure="true" printsummary="true">
      <batchtest>
        <fileset refid="tests" />
      </batchtest>
      <formatter type="plain" usefile="false" />
      <formatter type="xml" usefile="true" todir="${reports.dir}" outfile="test-results.xml" />
    </phpunit>
    <phpunitreport format="noframes" todir="${reports.dir}/html" infile="${reports.dir}/test-results.xml" />
  </target>

<!-- Can't get this to work on my laptop
  <target name="coverage" description="Run unit tests and create code coverage report">
    <mkdir dir="${reports.dir}" />
    <coverage-setup database="${reports.dir}/coverage.db">
      <fileset refid="source" />
    </coverage-setup>
    <phpunit codecoverage="true">
      <batchtest>
        <fileset refid="tests" />
      </batchtest>
    </phpunit>
    <coverage-report outfile="${reports.dir}/coverage.xml">
      <report todir="${reports.dir}" />
    </coverage-report>
  </target>
 -->

  <target name="coverage" depends="dir_setup">
    <mkdir dir="${reports.dir}/coverage" />
    <exec command="phpunit --coverage-html ${reports.dir}/coverage test" dir="${project.basedir}" passthru="true" />
  </target>

  <target name="docs" description="Create API documentation">
    <echo msg="Creating index.html..." />
    <exec command="php homepage.php > index.html" dir="${project.basedir}" passthru="true" />
    <echo msg="Creating doap.rdf..." />
    <exec command="php doap.php > doap.rdf" dir="${project.basedir}" passthru="true" />
    <phpdoc title="EasyRdf ${version} API Documentation"
      destdir="${docs.dir}"
      sourcecode="no"
      undocumentedelements="yes"
      output="HTML:frames:default">
      <fileset refid="source" />
      <projdocfileset dir="${project.basedir}">
        <include name="README.md" />
        <include name="CHANGELOG.md" />
        <include name="LICENSE.md" />
      </projdocfileset>
    </phpdoc>
  </target>

<!-- Note sure I like the style of the DocBlox documentation at the moment
  <target name="docs" description="Create API documentation">
    <mkdir dir="${docs.dir}" />
    <docblox title="EasyRdf ${version} API Documentation"
      destdir="${docs.dir}">
      <fileset refid="source" />
    </docblox>
  </target>
-->

  <target name="cs">
    <phpcodesniffer standard="Zend" showWarnings="false" haltonerror="true">
      <fileset refid="source" />
      <fileset refid="tests" />
    </phpcodesniffer>
  </target>

  <target name="lint">
    <phplint haltonfailure="true">
      <fileset refid="source" />
      <fileset refid="tests" />
      <fileset refid="examples" />
    </phplint>
  </target>

  <target name="dist" depends="clean,docs">
    <echo msg="Creating archive..." />
    <mkdir dir="${dist.dir}/easyrdf-${version}" />
    <copy todir="${dist.dir}/easyrdf-${version}" >
      <fileset refid="source" />
      <fileset refid="tests" />
      <fileset refid="test-support" />
      <fileset refid="examples" />
      <fileset refid="docs" />
      <fileset dir="${project.basedir}">
        <include name="build.xml" />
        <include name="doap.rdf" />
      </fileset>
    </copy>
    <delete file="easyrdf-${version}.tar.gz" />
    <tar destfile="easyrdf-${version}.tar.gz"
         basedir="${dist.dir}"
         compression="gzip" />
  </target>

  <target name="dir_setup">
    <mkdir dir="${reports.dir}" />
    <mkdir dir="${reports.dir}/html" />
    <mkdir dir="${reports.dir}/coverage" />
  </target>

  <target name="clean">
    <delete dir="${reports.dir}" includeemptydirs="true" verbose="true" />
    <delete dir="${docs.dir}" includeemptydirs="true" verbose="true" />
    <delete dir="${dist.dir}" includeemptydirs="true" verbose="true" />
    <delete file="doap.rdf" verbose="true" />
    <delete file="index.html" verbose="true" />
  </target>

  <target name="fixme" description="Search for code that needs fixing">
    <exec command="git grep -n -E 'FIXME|TODO' lib" dir="${project.basedir}" passthru="true" />
  </target>

  <target name="whitespace" description="Search for trailing whitespace">
    <echo msg="Checking for trailing whitespace..." />
    <exec command="git grep -n -E '[ 	]+$'" dir="${project.basedir}" passthru="true" />
  </target>

  <target name="default" description="Default target" depends="clean,lint,test,cs,docs" />

</project>
