<?xml version="1.0" encoding="UTF-8"?>
<project name="api" default="unit-lint"
    xmlns:if="ant:if" xmlns:unless="ant:unless">
    <target name="unit-lint" depends="parallelPHPTasks"/>

    <property name="exclusionlist"
              value="../vendor,../library/Zend"/>
    <property name="execdir" value="${basedir}/../vendor/bin"/>

    <target name="parallelPHPTasks"
            description="Run code analysis tasks in parallel">
        <parallel threadCount="3">
            <antcall target="lint-delta"/>
            <antcall target="phpcs"/>
            <antcall target="phpunit"/>
        </parallel>
    </target>

    <target name="lint-delta">
        <exec executable="${execdir}/parallel-lint" failonerror="true">
            <arg line='${basedir}/../' />
            <arg line='--exclude ${basedir}/../library/Zend/' />
            <arg line='--exclude ${basedir}/../build/' />
            <arg line='--exclude ${basedir}/../vendor/' />
        </exec>
    </target>
    <target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer">
        <exec executable="${execdir}/phpcs" failonerror="false">
            <arg value="--extensions=php"/>
            <arg value="-p"/>
            <arg value="-n"/>
            <arg value="--report=checkstyle"/>
            <arg value="--report-file=${basedir}/logs/checkstyle.xml"/>
            <arg value="--standard=PSR2"/>
            <arg value="--ignore=${exclusionlist}"/>
            <arg path="${basedir}/../"/>
        </exec>
    </target>
    <target name="phpunit" description="Run unit tests with PHPUnit">
        <exec executable="${execdir}/phpunit" dir="${basedir}/../tests" failonerror="true">
            <arg value="--coverage-html"/>
            <arg value="${basedir}/coverage"/>
            <arg value="--coverage-clover"/>
            <arg value="${basedir}/logs/phpunit.coverage.xml"/>
            <arg value="--log-junit"/>
            <arg value="${basedir}/logs/phpunit.xml"/>
        </exec>
    </target>
</project>
