|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | + |
| 3 | +<project name="Phing static code analysis" default="all"> |
| 4 | + <!-- Properties --> |
| 5 | + <property name="dir.base" value="." /> |
| 6 | + <property name="dir.tests" value="${project.basedir}/tests" /> |
| 7 | + <property name="dir.tests.unit" value="${project.basedir}/tests" /> |
| 8 | + <property name="dir.build" value="${project.basedir}/phing-build" /> |
| 9 | + <property name="dir.docs" value="${dir.build}/docs" /> |
| 10 | + <property name="dir.docs.phpdoc" value="${dir.docs}/phpdoc" /> |
| 11 | + <property name="dir.reports" value="${dir.build}/logs" /> |
| 12 | + <property name="dir.reports.pdepend" value="${dir.reports}/pdepend" /> |
| 13 | + <property name="dir.reports.unit" value="${dir.reports}/phpunit" /> |
| 14 | + <property name="dir.reports.coverage" value="${dir.reports}/phpunit/coverage" /> |
| 15 | + <property name="dir.reports.build" value="${dir.reports}/htmlreport" /> |
| 16 | + |
| 17 | + <!-- ============================================ --> |
| 18 | + <!-- Fileset: sources (all php files but those in test) --> |
| 19 | + <!-- ============================================ --> |
| 20 | + <fileset expandsymboliclinks="true" dir="${dir.base}" id="sources"> |
| 21 | + <include name="src/**/*.php" /> |
| 22 | + </fileset> |
| 23 | + |
| 24 | + <!-- ============================================ --> |
| 25 | + <!-- Target: clean --> |
| 26 | + <!-- ============================================ --> |
| 27 | + <target name="clean" description="Clean up build directories."> |
| 28 | + <echo msg="Cleaning build directories ..." /> |
| 29 | + <delete dir="${dir.build}" verbose="false" /> |
| 30 | + </target> |
| 31 | + |
| 32 | + <!-- ============================================ --> |
| 33 | + <!-- Target: prepare --> |
| 34 | + <!-- ============================================ --> |
| 35 | + <target name="prepare" description="Create build directories."> |
| 36 | + <echo msg="Creating build directories ..." /> |
| 37 | + <mkdir dir="${dir.build}" /> |
| 38 | + <mkdir dir="${dir.docs}" /> |
| 39 | + <mkdir dir="${dir.docs.phpdoc}" /> |
| 40 | + <mkdir dir="${dir.reports}" /> |
| 41 | + <mkdir dir="${dir.reports.unit}" /> |
| 42 | + <mkdir dir="${dir.reports.coverage}" /> |
| 43 | + <mkdir dir="${dir.reports.pdepend}" /> |
| 44 | + <mkdir dir="${dir.reports.build}" /> |
| 45 | + </target> |
| 46 | + |
| 47 | + <!-- ============================================ --> |
| 48 | + <!-- Target: all (default target) --> |
| 49 | + <!-- ============================================ --> |
| 50 | + <target name="all" depends="clean, prepare"> |
| 51 | + <phingcall target="codecheck" /> |
| 52 | + <phingcall target="tests" /> |
| 53 | + </target> |
| 54 | + |
| 55 | + <!-- ============================================ --> |
| 56 | + <!-- Target: codecheck (run all static code checks) --> |
| 57 | + <!-- ============================================ --> |
| 58 | + <target name="codecheck"> |
| 59 | + <phingcall target="lint" /> |
| 60 | + <phingcall target="codestyle" /> |
| 61 | + <phingcall target="mess" /> |
| 62 | + <phingcall target="copypaste" /> |
| 63 | + </target> |
| 64 | + |
| 65 | + <!-- ============================================ --> |
| 66 | + <!-- Target: tests (run all tests) --> |
| 67 | + <!-- ============================================ --> |
| 68 | + <target name="tests"> |
| 69 | + <!-- Now we are not running unit tests --> |
| 70 | + <phingcall target="unittests" /> |
| 71 | + </target> |
| 72 | + |
| 73 | + <!-- ============================================ --> |
| 74 | + <!-- Target: lint (Checks code syntax) --> |
| 75 | + <!-- ============================================ --> |
| 76 | + <target name="lint"> |
| 77 | + <echo msg="Running lint to check code syntax..." /> |
| 78 | + <phplint> |
| 79 | + <fileset refid="sources" /> |
| 80 | + </phplint> |
| 81 | + </target> |
| 82 | + |
| 83 | + <!-- ============================================ --> |
| 84 | + <!-- Target: codestyle (Checks code style compliance) --> |
| 85 | + <!-- ============================================ --> |
| 86 | + <target name="codestyle"> |
| 87 | + <echo msg="Running code sniffer to check PSR2 standard..." /> |
| 88 | + <phpcodesniffer standard="PSR2" showSniffs="true" showWarnings="true" verbosity="0" encoding="UTF-8"> |
| 89 | + <fileset refid="sources" /> |
| 90 | + <formatter type="full" outfile="${dir.reports}/reportcs.txt" /> |
| 91 | + <formatter type="checkstyle" outfile="${dir.reports}/checkstylecs.xml" /> |
| 92 | + </phpcodesniffer> |
| 93 | + </target> |
| 94 | + |
| 95 | + <!-- ============================================ --> |
| 96 | + <!-- Target: mess (Detects mess in code. Recommended rulesets: --> |
| 97 | + <!-- unusedcode,codesize,controversial,design,naming) --> |
| 98 | + <!-- It can be also used as <pmd> tag. --> |
| 99 | + <!-- ============================================ --> |
| 100 | + <target name="mess"> |
| 101 | + <echo msg="Running mess detector" /> |
| 102 | + <phpmd rulesets="unusedcode,codesize,controversial,design,naming"> |
| 103 | + <fileset refid="sources" /> |
| 104 | + <formatter type="xml" outfile="${dir.reports}/pmd.xml"/> |
| 105 | + </phpmd> |
| 106 | + </target> |
| 107 | + |
| 108 | + <!-- ============================================ --> |
| 109 | + <!-- Target: copypaste (detects copy/paste in code) --> |
| 110 | + <!-- ============================================ --> |
| 111 | + <target name="copypaste"> |
| 112 | + <echo msg="Running copy/paste detector..." /> |
| 113 | + <phpcpd> |
| 114 | + <fileset refid="sources" /> |
| 115 | + <formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" /> |
| 116 | + </phpcpd> |
| 117 | + </target> |
| 118 | + |
| 119 | + <!-- ============================================ --> |
| 120 | + <!-- Target: measure (measures the code) --> |
| 121 | + <!-- ============================================ --> |
| 122 | + <target name="measure"> |
| 123 | + <echo msg="Running code measurements..." /> |
| 124 | + <phploc reportType="csv" reportName="phploc" reportDirectory="${dir.reports}"> |
| 125 | + <fileset refid="sources" /> |
| 126 | + </phploc> |
| 127 | + </target> |
| 128 | + |
| 129 | + <!-- ============================================ --> |
| 130 | + <!-- Target: unittests (unit testing) --> |
| 131 | + <!-- ============================================ --> |
| 132 | + <target name="unittests"> |
| 133 | + <echo msg="Running unit tests..." /> |
| 134 | + <coverage-setup database="${dir.reports.unit}/coverage.db"> |
| 135 | + <fileset refid="sources" /> |
| 136 | + </coverage-setup> |
| 137 | + <phpunit configuration="${dir.tests}/phpunit.xml" codecoverage="true"> |
| 138 | + <formatter todir="${dir.reports.unit}" type="xml" /> |
| 139 | + <formatter todir="${dir.reports.unit}" type="clover" /> |
| 140 | + <batchtest> |
| 141 | + <fileset dir="${dir.tests.unit}" /> |
| 142 | + </batchtest> |
| 143 | + </phpunit> |
| 144 | + <coverage-report outfile="${dir.reports.unit}/coverage.xml"> |
| 145 | + <report todir="${dir.reports.coverage}" title="Phing unit tests run" usesorttable="true"/> |
| 146 | + </coverage-report> |
| 147 | + </target> |
| 148 | +</project> |
0 commit comments