<?xml version="1.0" encoding="UTF-8"?>
<project name="OpenCart" default="build" basedir=".">
    <property name="source" value="upload"/>

    <target name="clean" description="Cleanup build artifacts">
        <delete dir="${basedir}/tests/docs"/>
        <delete dir="${basedir}/tests/logs"/>
        <delete dir="${basedir}/tests/testresults"/>
    </target>

    <target name="prepare" depends="clean" description="Prepare for build">
        <mkdir dir="${basedir}/tests/docs"/>
        <mkdir dir="${basedir}/tests/logs"/>
        <mkdir dir="${basedir}/tests/testresults"/>
    </target>

    <target name="lint" description="Perform syntax check of source code files">
        <apply executable="php" failonerror="true">
            <arg value="-l"/>
            <fileset dir="${basedir}/upload">
                <include name="**/*.php"/>
                <modified/>
            </fileset>
        </apply>
    </target>

    <target name="csslint" description="Run the CSSLint tool on CSS files">
        <fileset dir="${basedir}/upload" id="cssfiles.raw">
            <include name="**/*.css" />
        </fileset>
        <pathconvert pathsep=" " property="cssfiles.clean" refid="cssfiles.raw" />
        <exec executable="csslint" output="${basedir}/tests/csslint.xml">
            <arg line="--warnings=box-model,floats --errors=ids,important --format=lint-xml ${cssfiles.clean}" />
        </exec>
    </target>

    <target name="phploc" description="Measure project size using PHPLOC">
        <exec executable="phploc">
            <arg value="--log-csv"/>
            <arg value="${basedir}/tests/logs/phploc.csv"/>
            <arg path="${basedir}/upload"/>
        </exec>
    </target>

    <target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer">
        <exec executable="phpcs">
            <arg line="--report=checkstyle --report-file=${basedir}/tests/checkstyle.xml --standard=tests/phpcs/OpenCart/ruleset.xml --extensions=php ${source}/"/>
        </exec>
    </target>

    <target name="build" depends="prepare,phpcs,lint,phploc,csslint"/>
</project>