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

<!-- Exclude/ignore paths -->
 <property name="ignorepaths" value="${basedir}/htdocs/conf,${basedir}/htdocs/core/filemanagerdol,${basedir}/htdocs/includes" />
 <property name="ignoreregexp" value="**/PEAR/*,**/NET/*,**/HTTP/*" />
 
 <target name="clean">
  <!-- Clean up -->
  <delete dir="${basedir}/hudson"/>
  <delete dir="${basedir}/generatedJUnitFiles"/>

  <!-- Create build directories -->
  <mkdir dir="${basedir}/hudson/doxygen"/>
  <mkdir dir="${basedir}/hudson/logs"/>
  <mkdir dir="${basedir}/hudson/coverage"/>
 </target>

 <!-- Run phpmd, phpcpd, phpcs, doxygen and phploc in parallel -->
 <target name="parallelTasks">
  <parallel>
   <!-- <antcall target="phpmd"/> -->
   <antcall target="phpcpd"/>
   <!-- <antcall target="phpcs"/> -->
   <antcall target="doxygen"/>
   <antcall target="phploc"/>
  </parallel>
 </target>

 <!-- Generate pmd.xml -->
<!--
<target name="phpmd">
  <exec executable="phpmd">
   <arg line="htdocs xml codesize,unusedcode
              -\-reportfile '${basedir}/hudson/logs/pmd.xml'
              -\-ignore=${ignorepaths}
              " />
  </exec>
 </target>
-->

 <!-- Generate pmd-cpd.xml -->
 <target name="phpcpd">
  <exec executable="phpcpd">
   <arg line="	--log-pmd '${basedir}/hudson/logs/pmd-cpd.xml'
   				--exclude '${basedir}/htdocs/conf'
   				--exclude '${basedir}/htdocs/core/filemanagerdol'
   				--exclude '${basedir}/htdocs/includes'
   				--exclude '**/PEAR/*,**/NET/*,**/HTTP/*'
   				--min-tokens 70
   				--min-lines 20 
   				htdocs
   				" />
  </exec>
 </target>
 
 <!-- Generate phploc.csv -->
 <target name="phploc">
  <exec executable="phploc">
   <arg line="	--log-csv '${basedir}/hudson/logs/phploc.csv'
   				--exclude '${basedir}/htdocs/conf'
   				--exclude '${basedir}/htdocs/core/filemanagerdol'
   				--exclude '${basedir}/htdocs/includes'
   				--exclude '**/PEAR/*,**/NET/*,**/HTTP/*'
   				htdocs
   				" />
  </exec>
 </target>
   
 <!-- Generate checkstyle.xml -->
 <target name="phpcs">
  <exec executable="phpcs" dir="${basedir}">
    <arg line=" --standard=${basedir}/dev/codesniffer/jenkins_ruleset.xml
    			--report=checkstyle
    			--report-file=${basedir}/hudson/logs/checkstyle.xml
                --ignore=${ignorepaths},${ignoreregexp}
                htdocs
                "/>
  </exec>
 </target>

 <!-- Generate Doxygen documentation -->
 <target name="doxygen" description="Dolibarr documentation" >
  <exec executable="doxygen" dir="${basedir}" failonerror="false">
   <arg value="${basedir}/build/doxygen/jenkins_doxygen.doxyfile"/>
  </exec>
 </target>
 
 <!-- Run unit tests and generate junit.xml and clover.xml -->
 <target name="phpunit">
  <exec executable="phpunit" dir="${basedir}" failonerror="true">
   <arg line="	--configuration ${basedir}/test/phpunit/jenkins_phpunittest.xml
				--log-junit ${basedir}/hudson/logs/junit.xml
				--coverage-clover ${basedir}/hudson/coverage/clover.xml
  				--coverage-html ${basedir}/hudson/coverage/
  				test/phpunit/AllTests.php
  				"/>
  </exec>
 </target>

 <target name="hudson" depends="clean,phpunit,phpcs,parallelTasks"/>
</project>