Skip to content

Instantly share code, notes, and snippets.

@marten-cz
Created March 4, 2014 21:56
Show Gist options
  • Save marten-cz/9356634 to your computer and use it in GitHub Desktop.
Save marten-cz/9356634 to your computer and use it in GitHub Desktop.
Ant script for PHP analysis
<!--
This file is for Continuous Integration server
Please don't edit this file if you are not sure what you are doing.
For any change please consult it with appropriate person.
Author: Martin Malek <martin.malek@pagewiser.cz>
-->
<project name="project" default="" basedir=".">
<!-- Define for use with windows -->
<condition property="script-suffix" value=".bat" else="">
<os family="windows" />
</condition>
<!-- Selenium properties -->
<property name="selenium.port" value="4444" />
<property name="selenium.display" value=":0" />
<property name="selenium.path" value="/var/opt/selenium/selenium-server.jar" />
<!-- Load database settings etc. -->
<property file="build.properties" />
<!-- Load ant-contrib library -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath path="${ant.contrib.path}"/>
</taskdef>
<!-- Excluded and included masks for analysis tools -->
<property name="phpextensions" value="*.php" />
<property name="libsdir" value="./" />
<property name="ignorepaths" value="./build/*,./builds/*,./tests/*,${libsdir}/*" />
<property name="ignoredirs" value="build/*,tests/*,${libsdir}/*" />
<property name="ignoremulti" value="--exclude build --exclude tests --exclude ${libsdir}" />
<property name="ignorephploc" value="--exclude build --exclude tests --exclude ${libsdir}" />
<property name="phpdocignorepaths" value="build/,tests/,${libsdir}/" />
<property name="ignorefiletypes" value="*.css,*.js" />
<!-- Delete last build artifacts -->
<target name="cleanbuild">
<!-- Clean up -->
<antcall target="safeCleanDirectory">
<param name="dir" value="${basedir}/build" />
</antcall>
<!-- Create build directories -->
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/phpdoc"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/selenium"/>
<mkdir dir="${basedir}/build/pdepend"/>
<mkdir dir="${basedir}/build/apigen"/>
<mkdir dir="${basedir}/build/jmeter"/>
</target>
<!-- Minify css -->
<target name="minifyCss">
<exec executable="${yui_compressor.path}" failonerror="on">
<arg line="--type=css www/css/main.css -o www/css/main.min.css" />
</exec>
</target>
<!-- Minify js -->
<target name="minifyJs">
<exec executable="${yui_compressor.path}" failonerror="on">
<arg line="--type=js www/js/main.js -o www/js/main.min.js" />
</exec>
</target>
<!-- Recreate database -->
<target name="recreateDb">
<antcall target="dropTables"/>
<antcall target="createTables"/>
</target>
<!-- Drop tables in database, credentials from build.properties -->
<target name="dropTables">
<exec executable="bash" failonerror="on">
<arg value="-c" />
<arg value="mysql -u ${sql.user} --password=${sql.pass} --database=${sql.database} -BNe &quot;show tables&quot; | awk &apos;{print &quot;SET foreign_key_checks = 0; drop table &quot; $1 &quot;; SET foreign_key_checks = 1;&quot;}&apos; | mysql -u ${sql.user} --password=${sql.pass} --database=${sql.database}" />
</exec>
</target>
<!-- Create the tables and insert data into database, credentials from build.properties -->
<target name="createTables">
<exec executable="php" failonerror="on">
<arg line="${basedir}/Tools/migrate.php -h ${sql.host} -u ${sql.user} -d ${sql.database} -p '${sql.pass}' ${basedir}/db/" />
</exec>
</target>
<!-- Insert testData.sql to the newly created database -->
<target name="insertTestData">
<exec executable="bash" failonerror="on">
<arg value="-c" />
<arg value="mysql -u${sql.user} --password=${sql.pass} ${sql.database} &lt; ${basedir}/tests/db/testData.sql" />
</exec>
</target>
<!-- Clean content of the directory and check if it exists so the build will not fail -->
<target name="safeCleanDirectory">
<if>
<available file="${dir}"/>
<then>
<delete includeEmptyDirs="true">
<fileset dir="${dir}" excludes="${exclude}"/>
</delete>
</then>
</if>
</target>
<!-- Clean logs -->
<target name="cleanlog">
<antcall target="safeCleanDirectory">
<param name="dir" value="${basedir}/log" />
</antcall>
<mkdir dir="${basedir}/log"/>
<chmod dir="${basedir}/log" perm="0777" />
</target>
<!-- Clean the cache directories -->
<target name="cleancache">
<antcall target="safeCleanDirectory">
<param name="dir" value="${basedir}/temp" />
<param name="exclude" value="**/btfj.dat" />
</antcall>
<mkdir dir="${basedir}/temp/cache"/>
<chmod dir="${basedir}/temp/" perm="0777" />
<chmod dir="${basedir}/temp/cache" perm="0777" />
</target>
<target name="start-selenium">
<java jar="${selenium.path}" fork="true" spawn="true">
<env key="DISPLAY" value="${selenium.display}"/>
<arg line="-timeout 30 -port ${selenium.port} -trustAllSSLCertificates"/>
</java>
</target>
<target name="stop-selenium">
<get taskname="selenium-shutdown"
src="http://localhost:${selenium.port}/selenium-server/driver/?cmd=shutDownSeleniumServer" ignoreerrors="true" dest="/dev/null" />
<echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
</target>
<!-- Run unit tests and generate junit.xml and clover.xml -->
<target name="phpunit">
<exec executable="phpunit${script-suffix}" failonerror="on">
<arg line="--stderr -c tests/unit/phpunit.xml"/>
</exec>
</target>
<!-- Run unit tests and generate junit.xml and clover.xml -->
<target name="phpunit-cover">
<exec executable="phpunit${script-suffix}" dir="${basedir}/tests/unit" failonerror="on">
<arg line="--stderr -c ./phpunit.xml
--coverage-clover ../../build/logs/tests/phpunit.coverage.xml
--coverage-html ../../build/coverage
--log-junit ../../build/logs/tests/phpunit.xml"
/>
</exec>
</target>
<!-- Run selenium tests and generate selenium.xml -->
<target name="selenium">
<exec executable="phpunit${script-suffix}" failonerror="on" dir="${basedir}/tests/selenium">
<arg line="
--verbose
--tap
--log-junit ../../build/logs/tests/selenium.xml
./"
/>
</exec>
</target>
<!-- Run pdepend, phpmd, phpcpd, phpcs phploc and apigen in parallel -->
<target name="parallelTasks">
<parallel threadCount="2">
<antcall target="pdepend"/>
<antcall target="phpmd"/>
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phploc"/>
<antcall target="apigen"/>
</parallel>
</target>
<!-- Generate PDepend report - jdepend.xml and software metrics charts -->
<target name="pdepend">
<exec executable="pdepend${script-suffix}">
<arg line="--jdepend-xml=./build/logs/jdepend.xml
--jdepend-chart=./build/pdepend/jdepend.svg
--overview-pyramid=./build/pdepend/pyramid.svg
--ignore=${ignorepaths}
--suffix=php
./" />
</exec>
</target>
<!-- Generate Mess detector report - pmd.xml -->
<target name="phpmd">
<exec executable="phpmd${script-suffix}">
<!-- + design -->
<arg line="./ xml codesize,unusedcode,naming
--reportfile ./build/logs/pmd.xml
--exclude '${ignoredirs}'" />
</exec>
</target>
<!-- Generate Copy detector report - pmd-cpd.xml -->
<target name="phpcpd">
<exec executable="phpcpd${script-suffix}">
<arg line="--log-pmd ./build/logs/pmd-cpd.xml
--min-lines 3
--min-tokens 20
${ignoremulti}
./" />
</exec>
<xslt in="./build/logs/pmd-cpd.xml" style="./tools/cpdhtml.xslt" out="./build/logs/pmd-cpd.html" />
</target>
<!-- Generate checkstyle.xml -->
<target name="phpcs">
<exec executable="phpcs${script-suffix}">
<arg line="--report=checkstyle
--report-file='${basedir}/build/logs/checkstyle.xml'
--standard=Marten
--ignore='${ignoredirs}'
--extensions=php
./" />
</exec>
</target>
<!-- Generate API documentation -->
<target name="phpdoc">
<exec executable="phpdoc${script-suffix}">
<arg line="-ct type -ue on -t ${basedir}/build/phpdoc
-o HTML:Smarty:PHP
-d ./
-f *.php
-i *.phtml,*.html,${phpdocignorepaths} " />
</exec>
</target>
<!-- Generate APIGen documentation -->
<target name="apigen">
<exec executable="apigen${script-suffix}">
<arg line="--quiet --source app --source tests --destination ${basedir}/build/apigen/ --todo yes --undocumented ${basedir}/build/apigen/undocumented.txt --title &quot;Nodus docs&quot; --allowed-html &quot;b,i,a,ul,ol,li,p,br,var,samp,kbd,tt,pre&quot;" />
</exec>
</target>
<!-- Generate Code Browser -->
<target name="phpcb">
<exec executable="phpcb${script-suffix}">
<arg line="--log ./build/logs/
--ignore ${phpdocignorepaths}
--source ./
--output ./build/code-browser" />
</exec>
</target>
<!-- Generate PHPLoc report - phploc.csv -->
<target name="phploc">
<exec executable="phploc${script-suffix}">
<arg line="--log-csv ./build/logs/phploc.csv
${ignorephploc}
--suffixes php
./" />
</exec>
</target>
<target name="jmeter">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" classpath="${jmeter.ant}" />
<jmeter jmeterhome="${jmeter.home}" resultlog="${basedir}/build/jmeter/results.jtl" resultlogdir="${basedir}/build/jmeter/">
<property name="jmeter.save.saveservice.output_format" value="xml" />
<testplans dir="${basedir}/tests/jmeter/" includes="*.jmx"/>
<jmeterarg value="-Jdomain=${domain}"/>
<jvmarg value="-Xmx128m"/>
</jmeter>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment