<?xml version="1.0" encoding="UTF-8"?>
<!--****************************************************************************
 * This file is part of phpUnderControl.
 *
 * Copyright (c) 2007-2008, Manuel Pichler <mapi@phpundercontrol.org>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   * Neither the name of Manuel Pichler nor the names of his
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * @author    Manuel Pichler <mapi@phpundercontrol.org>
 * @copyright 2007-2008 Manuel Pichler. All rights reserved.
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version   @package_version@
 * @link      http://www.phpundercontrol.org/
 ****************************************************************************-->
<project name="phpundercontrol.org" default="build" basedir=".">

  <!--
  Helper target that initializes the CruiseControl project and creates the base 
  directory structure. 
  -->
  <target name="init">
    <!-- Create the source directory -->
    <mkdir dir="source" />
    
    <!-- Create the different build directories -->
    <mkdir dir="build/logs" />
    <mkdir dir="build/api" />
    <mkdir dir="build/coverage" />
    
    <!-- Checkout phpUnderControl trunk into source -->
    <exec executable="svn">
      <arg line="co svn://svn.phpunit.de/phpunit/phpUnderControl/trunk source" />
    </exec>
  </target>
    
  <!--
  The clean target is used to remove build artifacts of previous builds. Otherwise
  CruiseControl will present old, maybe successful result, even if your build 
  process fails.
  -->
  <target name="clean">
  	<!-- Remove old log files -->
    <delete>
      <fileset dir="${basedir}/build/logs" includes="**.*" />
    </delete>
  	<!-- Remove old api documentation -->
    <delete>
      <fileset dir="${basedir}/build/api" includes="**.*" />
    </delete>
  	<!-- Remove old coverage report -->
    <delete>
      <fileset dir="${basedir}/build/coverage" includes="**.*" />
    </delete>
  </target>

  <!--
  The default build target for this project. It simply depends on all sub tasks
  that perform the project build. The sub targets are executed in the listed 
  order.
  
  1. 'clean' Clean old project build artifacts
  2. 'checkout' Update project working copy
  3. 'php-documentor' Generate api documentation
  4. 'php-codesniffer' Check for coding violations.
  5. 'phpunit' Execute unit tests, generate metrics, coverage etc. 
  -->
  <target name="build" 
          depends="clean,checkout,php-documentor,php-codesniffer,phpunit" />

  <!--
  Performs an 'svn up' for the working copy.
  -->
  <target name="checkout">
    <exec executable="svn" dir="${basedir}/source">
      <arg line="up" />
    </exec>
  </target>

  <!--
  Generates the project documentation into the <project>/build/api directory.
  phpUnderControl uses the command line output of PhpDocumentor that is logged
  by CruiseControl.
  -->
  <target name="php-documentor">
    <exec executable="phpdoc" dir="${basedir}/source">
      <arg line="-ct type -ue on -t ${basedir}/build/api 
      	         -tb ...PATH TO YOUR PHPUC DATA.../phpdoc -o HTML:Phpuc:phpuc
    	         -d src/"/>
    </exec>
  </target>

  <!--
  Execute code sniffer. This demo uses the PEAR standard the is bundled with
  PHP_CodeSniffer, but phpUnderControl doesn't follow this standard. CodeSniffer
  uses the Checkstyle report generator that is supported by CruiseControl. The
  'output' attribute for the exec element pipes the command line output into the 
  <project>/build/logs/checkstyle.xml file.
  
  You should always declare the optional @error attribute for the codesniffer 
  task. Otherwise all errors will be logged in the checkstyle.xml file, which
  results in an invalid xml document.
  -->
  <target name="php-codesniffer">
    <exec executable="phpcs" 
          dir="${basedir}/source" 
          error="/dev/null"
          output="${basedir}/build/logs/checkstyle.xml">
      <arg line="--report=checkstyle 
                 --standard=PEAR
                 --ignore=src/autoload src/"/>
    </exec>
  </target>
  
  <!--
  Executes the project unit tests and stores the different logs in the 
  <project>/build/logs directory. Furthermore it generates the coverage report
  under <project>/build/coverage.
  -->
  <target name="phpunit">
    <exec executable="phpunit" dir="${basedir}/source" failonerror="on">
      <arg line="--log-xml ${basedir}/build/logs/phpunit.xml 
                 --log-pmd ${basedir}/build/logs/phpunit.pmd.xml  
                 --log-metrics ${basedir}/build/logs/phpunit.metrics.xml 
                 --coverage-xml  ${basedir}/build/logs/phpunit.coverage.xml 
                 --coverage-html ${basedir}/build/coverage
                 phpucAllTests tests/AllTests.php" />
    </exec>
  </target>
</project>