<?xml version="1.0" encoding="UTF-8"?>
<project name="php-on-couch" default="build">
    <target name="travis" depends="tests-parallel,show-test-results" />
    <target name="clean" description="Cleanup build artifacts">
        <delete dir="${basedir}/build"/>
    </target>
    
    <target name="prepare" depends="clean" description="Prepare for build">
        <mkdir dir="${basedir}/build/test-results"/>
        <mkdir dir="${basedir}/build/logs"/>
        <mkdir dir="${basedir}/build/cov"/>
        <!--
        <mkdir dir="${basedir}/build/cs-results"/>
        -->
    </target>

    <!--
    <target name="get-cs-fixer" depends="clean" description="Get coding standards fixer">
        <get src="http://cs.sensiolabs.org/get/php-cs-fixer.phar" dest="${basedir}/php-cs-fixer.phar"/>
    </target>
    -->

    <target name="composer-install" description="Installs dependencies via composer install">
        <sequential>
            <exec executable="composer" failonerror="true">
                <arg value="self-update" />
            </exec>
            <exec executable="composer" failonerror="true">
                <arg value="--version" />
            </exec>
            <exec executable="composer" failonerror="true">
                <env key="COMPOSER_ROOT_VERSION" value="dev-master"/>
                <arg value="install" />
                <arg value="--dev" />
                <arg value="--prefer-source" />
            </exec>
        </sequential>
    </target>
    <!-- 
           depends="prepare,composer-install,get-cs-fixer" -->
    <target
            name="tests-parallel"
           depends="prepare,composer-install"
            description="Run tests for the various components in parallel"
        >
        <parallel threadCount="1">
            <test-macro />
            <!--
            <check-cs/>
            -->
        </parallel>
    </target>

    <target name="show-test-results" description="Display logged test results">
        <concat>
            <!--
            <fileset dir="${basedir}/build/cs-results/"/>
            -->
            <fileset dir="${basedir}/build/test-results/"/>
        </concat>
    </target>

    <macrodef name="test-macro">
        <sequential>
            <echo output="${basedir}/build/test-results/log.log" level="debug">

                php-on-couch

            </echo>
            <exec
                executable="${basedir}/vendor/bin/phpunit"
                output="${basedir}/build/test-results/log.log"
                error="${basedir}/build/test-results/log.log"
                failonerror="true"
                append="true"
            >
                <arg value="--coverage-clover" />
                <arg value="${basedir}/build/logs/clover.xml" />
                <arg value="-c" />
                <arg value="${basedir}/tests/phpunit.xml.dist" />
                <arg value="${basedir}/tests/" />
            </exec>
        </sequential>
    </macrodef>
<!--
    <macrodef name="check-cs">
        <sequential>
            <echo output="${basedir}/build/cs-results/check-cs.log" level="debug">

                Coding standards

            </echo>
            <exec
                executable="${basedir}/bin/check-cs.sh"
                output="${basedir}/build/cs-results/check-cs.log"
                error="${basedir}/build/cs-results/check-cs.log"
                failonerror="true"
                append="true"
            />
        </sequential>
    </macrodef>
    -->
</project>
