<?xml version="1.0" encoding="UTF-8"?>
<project name="icingaweb" default="build" basedir=".">

<property name="testdir" value="${basedir}/app/modules" />

<target name="init">
  <record name="antbuild.log" loglevel="verbose" append="false"/>
</target>

 <target name="build"
   depends="prepare,lint,phploc,pdepend,phpcs-ci,phpmd-ci,phpcpd,phpdoc,phpunit,phpcb,init"/>

 <target name="build-parallel"
   depends="init,prepare,lint,tools-parallel,phpunit,phpcb"/>

<target name="tools-parallel"
         description="Run tools in parallel"
 depends="init">
  <parallel threadCount="2">
   <sequential>
    <antcall target="pdepend"/>
    <antcall target="phpmd-ci"/>
   </sequential>
   <antcall target="phpcpd"/>
   <antcall target="phpcs-ci"/>
   <antcall target="phploc"/>
   <antcall target="phpdoc"/>
  </parallel>
 </target>

 <target name="clean"
  description="Clean up and create artifact directories"
 depends="init">
  <delete dir="${basedir}/build/api"/>
  <delete dir="${basedir}/build/code-browser"/>
  <delete dir="${basedir}/build/coverage"/>
  <delete dir="${basedir}/build/logs"/>
  <delete dir="${basedir}/build/pdepend"/>
 </target>

 <target name="prepare" depends="clean"
         description="Prepare for build">
  <mkdir dir="${basedir}/build/api"/>
  <mkdir dir="${basedir}/build/code-browser"/>
  <mkdir dir="${basedir}/build/coverage"/>
  <mkdir dir="${basedir}/build/logs"/>
  <mkdir dir="${basedir}/build/pdepend"/>
  <mkdir dir="${basedir}/build/phpdoc"/>
 </target>

 <target name="lint">
  <apply executable="php" failonerror="true">
   <arg value="-l" />

   <fileset dir="${testdir}">
    <include name="**/*.php" />
    <exclude name="*/cache/*" />
   </fileset>

   <fileset dir="${basedir}/tests">
    <include name="**/*.php" />
   </fileset>
  </apply>
 </target>

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

 <target name="pdepend"
         description="Calculate software metrics using PHP_Depend" >
  <exec executable="pdepend">
   <arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
   <arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
   <arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
   <arg value="--suffix=php" />
   <arg value="--ignore=${basedir}/app/modules/AppKit/lib/context/AppKitApiProviderParser.class.php" />
   <arg path="${testdir}" />
  </exec>
 </target>

 <target name="phpmd"
         description="Perform project mess detection using PHPMD"
 depends="init">
  <exec executable="phpmd">
   <arg line="${testdir} text ${basedir}/tests/phpmd/phpmd.xml" />
 
  </exec>
 </target>

 <target name="phpmd-ci"
         description="Perform project mess detection using PHPMD" >
  <exec executable="phpmd">
   <arg line="${testdir} xml ${basedir}/tests/phpmd/phpmd.xml --suffixes php --reportfile ./build/logs/pmd.xml --exclude */cache/*" />
  </exec>
 </target>

 <!--target name="phpdox"
         description="Generate API documentation using phpDox">
  <exec executable="phpdox"/>
 </target-->

 <target name="phpcs"
         description="Find coding standard violations using PHP_CodeSniffer"
 depends="init">
  <exec executable="phpcs">
   <arg value="--standard=${basedir}/tests/phpcs/YACS" />
   <arg value="--ignore=cache,\.js$" />
   <arg path="${testdir}" />
  </exec>
 </target>

 <target name="phpcs-ci"
         description="Find coding standard violations using PHP_CodeSniffer"
 depends="init">
  <exec executable="phpcs" output="/dev/null">
   <arg value="--report=checkstyle" />
   <arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
   <arg value="--standard=${basedir}/tests/phpcs/YACS" />
   <arg value="--ignore=cache,\.js$" />
   <arg path="${testdir}" />
  </exec>
 </target>

<target name="phpcpd" description="Find duplicate code using PHPCPD"
 depends="init">
  <exec executable="phpcpd">
   <arg value="--log-pmd" />
   <arg value="${basedir}/build/logs/pmd-cpd.xml" />
   <arg path="${testdir}" />
  </exec>
 </target>

 <target name="phpdoc"
          description="Generate API documentation using PHPDocumentor"
 depends="init">
  <exec executable="phpdoc">
   <arg value="--directory" />
   <arg path="${testdir}" />
   <arg value="--target" />
   <arg path="${basedir}/build/api" />
  </exec>
 </target>

<target name="phpunit" depends="init">
  <exec executable="phpunit" failonerror="false">
  <arg line="--configuration ${basedir}/tests/phpunit/suites.xml
             --coverage-clover ${basedir}/build/logs/clover.xml
             --coverage-html ${basedir}/build/coverage
             --exclude-group Database" />
  </exec>
 </target>

 <target name="phpcb"
         description="Aggregate tool output with PHP_CodeBrowser"
 depends="init">
  <exec executable="phpcb">
   <arg value="--log" />
   <arg path="${basedir}/build/logs" />
   <arg value="--source" />
   <arg path="${testdir}" />
   <arg value="--output" />
   <arg path="${basedir}/build/code-browser" />
  </exec>
 </target>

</project>
