<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* $Id: build.xml 170 2012-03-17 14:12:03Z stuart $
*
* stuconnolly.com
*
* Copyright (c) 2011 Stuart Connolly. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
-->
<project name="stuconnolly.com" basedir="." default="build">
<property name="coverage.enabled" value="1" />
<property name="test.output" value="phpunit.tests.xml" />
<property name="build.dir" value="${project.basedir}/build" />
<property name="coverage.database" value="${build.dir}/test.coverage.db" />
<target name="prepare" depends="clean">
<mkdir dir="${build.dir}" />
</target>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="build" description="Run all build steps" depends="prepare">
<phingcall target="test.with.coverage" />
<phingcall target="test.summary" />
<if>
<equals arg1="${coverage.enabled}" arg2="1" />
<then>
<phingcall target="code.coverage" />
</then>
</if>
<phingcall target="pdepend" />
</target>
<target name="test.with.coverage" description="Run all tests with code coverage">
<coverage-setup database="${coverage.database}">
<fileset dir="${project.basedir}">
<patternset>
<include name="**/system/core/*.php" />
<include name="**/system/user/classes/*.php" />
</patternset>
</fileset>
</coverage-setup>
<phpunit
bootstrap="${project.basedir}/tests/bootstrap.php"
haltonerror="true"
haltonfailure="true"
codecoverage="true"
printsummary="true">
<formatter type="plain" usefile="false" />
<formatter type="xml" todir="${build.dir}" outfile="${test.output}" />
<batchtest>
<fileset dir="tests">
<include name="**/*tests.php" />
</fileset>
</batchtest>
</phpunit>
<if>
<equals arg1="${host.name}" arg2="xenon" />
<then>
<echo message="##teamcity[importData type='junit' path='${build.dir}/${test.output}']" />
</then>
</if>
</target>
<target name="test" description="Run all tests">
<phpunit
bootstrap="${project.basedir}/tests/bootstrap.php"
haltonerror="true"
haltonfailure="true"
printsummary="true">
<formatter type="plain" usefile="false" />
<batchtest>
<fileset dir="tests">
<include name="**/*tests.php" />
</fileset>
</batchtest>
</phpunit>
</target>
<target name="test.summary" description="Produces a test summary report">
<phpunitreport infile="${build.dir}/${test.output}" todir="${build.dir}" />
</target>
<target name="code.coverage" description="Calculates code coverage">
<mkdir dir="${build.dir}/coverage" />
<property name="coverage.dir" value="${build.dir}/coverage" />
<coverage-report outfile="${build.dir}/test.coverage.xml">
<report todir="${coverage.dir}" title="stuconnolly.com" usesorttable="true" />
</coverage-report>
<zip destfile="${build.dir}/code.coverage.zip" basedir="${coverage.dir}"/>
<delete file="${build.dir}/test.coverage.xml" />
<delete file="${coverage.database}" />
<delete dir="${coverage.dir}" />
</target>
<target name="style" description="Checks coding style">
<phpcodesniffer
standard="PHPCS"
showsniffs="true"
showwarnings="true"
skipversioncheck="true"
docgenerator="html"
docfile="${build.dir}/style.doc.html">
<fileset dir="${project.basedir}">
<include name="**/*.php" />
</fileset>
<formatter type="summary" usefile="false" />
<formatter type="checkstyle" outfile="${build.dir}/code.style.xml" />
</phpcodesniffer>
</target>
<target name="pdepend" description="Code analysis">
<exec dir="${project.basedir}" executable="pdepend" output="${build.dir}/pdepend.log" error="${build.dir}/pdepend.log">
<arg line="--suffix=php" />
<arg line="--jdepend-chart=${build.dir}/pdepend.jdepend.chart.svg" />
<arg line="--jdepend-xml=${build.dir}/pdepend.jdepend.xml" />
<arg line="--overview-pyramid=${build.dir}/pdepend.overview.pyramid.svg" />
<arg line="--phpunit-xml=${build.dir}/pdepend.phpunit.xml" />
<arg line="--summary-xml=${build.dir}/pdepend.summary.xml" />
<arg line="--coderank-mode=inheritance,property,method" />
<arg line="${project.basedir}"/>
</exec>
</target>
</project>