dev.stuconnolly.com / svn / sites

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <!--
  4. *
  5. *  $Id: build.xml 170 2012-03-17 14:12:03Z stuart $
  6. *  
  7. *  stuconnolly.com
  8. *
  9. *  Copyright (c) 2011 Stuart Connolly. All rights reserved.
  10. *
  11. *  This program is free software: you can redistribute it and/or modify
  12. *  it under the terms of the GNU General Public License as published by
  13. *  the Free Software Foundation, either version 3 of the License, or
  14. *  (at your option) any later version.
  15. *
  16. *  This program is distributed in the hope that it will be useful,
  17. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. *  GNU General Public License for more details.
  20. *
  21. *  You should have received a copy of the GNU General Public License
  22. *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. -->
  25.  
  26. <project name="stuconnolly.com" basedir="." default="build">
  27.        
  28.     <property name="coverage.enabled" value="1" />
  29.     <property name="test.output" value="phpunit.tests.xml" />
  30.     <property name="build.dir" value="${project.basedir}/build" />
  31.     <property name="coverage.database" value="${build.dir}/test.coverage.db" />
  32.    
  33.     <target name="prepare" depends="clean">
  34.         <mkdir dir="${build.dir}" />
  35.     </target>
  36.    
  37.     <target name="clean">
  38.         <delete dir="${build.dir}" />
  39.     </target>
  40.    
  41.     <target name="build" description="Run all build steps" depends="prepare">
  42.         <phingcall target="test.with.coverage" />
  43.         <phingcall target="test.summary" />
  44.  
  45.         <if>
  46.             <equals arg1="${coverage.enabled}" arg2="1" />
  47.             <then>
  48.                 <phingcall target="code.coverage" />
  49.             </then>
  50.         </if>
  51.  
  52.         <phingcall target="pdepend" />
  53.     </target>
  54.    
  55.     <target name="test.with.coverage" description="Run all tests with code coverage">
  56.  
  57.         <coverage-setup database="${coverage.database}">
  58.             <fileset dir="${project.basedir}">
  59.                 <patternset>
  60.                     <include name="**/system/core/*.php" />
  61.                     <include name="**/system/user/classes/*.php" />
  62.                 </patternset>              
  63.             </fileset>
  64.         </coverage-setup>
  65.  
  66.         <phpunit
  67.             bootstrap="${project.basedir}/tests/bootstrap.php"
  68.             haltonerror="true"
  69.             haltonfailure="true"
  70.             codecoverage="true"
  71.             printsummary="true">
  72.            
  73.             <formatter type="plain" usefile="false" />
  74.             <formatter type="xml" todir="${build.dir}" outfile="${test.output}" />
  75.                
  76.             <batchtest>
  77.                 <fileset dir="tests">
  78.                     <include name="**/*tests.php" />
  79.                 </fileset>
  80.             </batchtest>
  81.         </phpunit>
  82.        
  83.         <if>
  84.             <equals arg1="${host.name}" arg2="xenon" />
  85.             <then>
  86.                 <echo message="##teamcity[importData type='junit' path='${build.dir}/${test.output}']" />
  87.             </then>
  88.         </if>
  89.        
  90.     </target>
  91.  
  92.     <target name="test" description="Run all tests">
  93.        
  94.         <phpunit
  95.             bootstrap="${project.basedir}/tests/bootstrap.php"
  96.             haltonerror="true"
  97.             haltonfailure="true"
  98.             printsummary="true">
  99.            
  100.             <formatter type="plain" usefile="false" />
  101.                
  102.             <batchtest>
  103.                 <fileset dir="tests">
  104.                     <include name="**/*tests.php" />
  105.                 </fileset>
  106.             </batchtest>
  107.         </phpunit>
  108.  
  109.     </target>
  110.  
  111.     <target name="test.summary" description="Produces a test summary report">
  112.  
  113.         <phpunitreport infile="${build.dir}/${test.output}" todir="${build.dir}" />
  114.  
  115.     </target>
  116.  
  117.     <target name="code.coverage" description="Calculates code coverage">
  118.        
  119.         <mkdir dir="${build.dir}/coverage" />
  120.        
  121.         <property name="coverage.dir" value="${build.dir}/coverage" />
  122.        
  123.         <coverage-report outfile="${build.dir}/test.coverage.xml">
  124.             <report todir="${coverage.dir}" title="stuconnolly.com" usesorttable="true" />
  125.         </coverage-report>
  126.        
  127.         <zip destfile="${build.dir}/code.coverage.zip" basedir="${coverage.dir}"/>
  128.        
  129.         <delete file="${build.dir}/test.coverage.xml" />
  130.         <delete file="${coverage.database}" />
  131.         <delete dir="${coverage.dir}" />
  132.        
  133.     </target>
  134.  
  135.     <target name="style" description="Checks coding style">
  136.        
  137.         <phpcodesniffer
  138.             standard="PHPCS"
  139.             showsniffs="true"
  140.             showwarnings="true"
  141.             skipversioncheck="true"
  142.             docgenerator="html"
  143.             docfile="${build.dir}/style.doc.html">
  144.        
  145.             <fileset dir="${project.basedir}">
  146.                 <include name="**/*.php" />
  147.             </fileset>
  148.          
  149.             <formatter type="summary" usefile="false" />
  150.             <formatter type="checkstyle" outfile="${build.dir}/code.style.xml" />
  151.         </phpcodesniffer>
  152.        
  153.     </target>
  154.    
  155.     <target name="pdepend" description="Code analysis">
  156.    
  157.         <exec dir="${project.basedir}" executable="pdepend" output="${build.dir}/pdepend.log" error="${build.dir}/pdepend.log">
  158.             <arg line="--suffix=php" />
  159.             <arg line="--jdepend-chart=${build.dir}/pdepend.jdepend.chart.svg" />
  160.             <arg line="--jdepend-xml=${build.dir}/pdepend.jdepend.xml" />
  161.             <arg line="--overview-pyramid=${build.dir}/pdepend.overview.pyramid.svg" />
  162.             <arg line="--phpunit-xml=${build.dir}/pdepend.phpunit.xml" />
  163.             <arg line="--summary-xml=${build.dir}/pdepend.summary.xml" />
  164.             <arg line="--coderank-mode=inheritance,property,method" />
  165.             <arg line="${project.basedir}"/>
  166.         </exec>
  167.            
  168.     </target>
  169.  
  170. </project>