|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<project name="Project" default="help"> |
| 3 | + |
| 4 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 5 | + <!-- | Init --> |
| 6 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 7 | + |
| 8 | + <!-- Vars --> |
| 9 | + <property name="basedir" value="."/> |
| 10 | + |
| 11 | + <!-- Command help --> |
| 12 | + <target name="help"> |
| 13 | + <echo message="Error: No command passed"/> |
| 14 | + <echo message="The following commands are available:"/> |
| 15 | + <echo message="|"/> |
| 16 | + <echo message="| +++ Build +++"/> |
| 17 | + <echo message="|-- build (Run the build)"/> |
| 18 | + <echo message="| |-- dependencies (Install dependencies)"/> |
| 19 | + <echo message="| |-- tests (Lint all files and run tests)"/> |
| 20 | + <echo message="| |-- metrics (Generate quality metrics)"/> |
| 21 | + <echo message="|-- cleanup (Cleanup the build directory)"/> |
| 22 | + <echo message="|"/> |
| 23 | + <echo message="| +++ Composer +++"/> |
| 24 | + <echo message="|-- composer -> composer-download, composer-install"/> |
| 25 | + <echo message="|-- composer-download (Downloads composer.phar to project)"/> |
| 26 | + <echo message="|-- composer-install (Install all dependencies)"/> |
| 27 | + <echo message="|-- composer-update (Update dependencies and generate new lockfile)"/> |
| 28 | + <echo message="|"/> |
| 29 | + <echo message="| +++ Testing +++"/> |
| 30 | + <echo message="|-- phpunit -> phpunit-full"/> |
| 31 | + <echo message="|-- phpunit-tests (Run unit tests)"/> |
| 32 | + <echo message="|-- phpunit-full (Run unit tests and generate code coverage report / logs)"/> |
| 33 | + <echo message="|"/> |
| 34 | + <echo message="| +++ Metrics +++"/> |
| 35 | + <echo message="|-- phploc (Generate lines of code metric)"/> |
| 36 | + <echo message="|-- phpcpd (Generate copy paste metric)"/> |
| 37 | + <echo message="|-- phpcs (Generate code sniffer metric)"/> |
| 38 | + <echo message="|-- phpmd (Generate mess detector metric)"/> |
| 39 | + <echo message="|"/> |
| 40 | + <echo message="| +++ Tools +++"/> |
| 41 | + <echo message="|-- lint (Lint all php files)"/> |
| 42 | + <echo message=""/> |
| 43 | + </target> |
| 44 | + |
| 45 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 46 | + <!-- | Build --> |
| 47 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 48 | + |
| 49 | + <!-- run the build --> |
| 50 | + <target name="build" depends="cleanup, prepare"> |
| 51 | + <!-- get all the dependencies necessary for the build --> |
| 52 | + <antcall target="dependencies"/> |
| 53 | + <!-- ok, looks good - now run all the tests --> |
| 54 | + <antcall target="tests"/> |
| 55 | + <!-- great, no errors - now we should generate some cool quality metrics --> |
| 56 | + <antcall target="metrics"/> |
| 57 | + </target> |
| 58 | + |
| 59 | + <!-- fetch dependencies --> |
| 60 | + <target name="dependencies"> |
| 61 | + <antcall target="composer"/> |
| 62 | + </target> |
| 63 | + |
| 64 | + <!-- run tests --> |
| 65 | + <target name="tests"> |
| 66 | + <!-- when there is a syntax error we're failing right at the beginning --> |
| 67 | + <antcall target="lint"/> |
| 68 | + <!-- ahh boy, the unit tests --> |
| 69 | + <antcall target="phpunit-full"/> |
| 70 | + </target> |
| 71 | + |
| 72 | + <!-- generate metrics --> |
| 73 | + <target name="metrics"> |
| 74 | + <antcall target="phploc"/> |
| 75 | + <antcall target="phpcpd"/> |
| 76 | + <antcall target="phpcs"/> |
| 77 | + <antcall target="phpmd"/> |
| 78 | + </target> |
| 79 | + |
| 80 | + <!-- cleanup --> |
| 81 | + <target name="cleanup"> |
| 82 | + <delete dir="${basedir}/build"/> |
| 83 | + </target> |
| 84 | + |
| 85 | + <!-- prepare --> |
| 86 | + <target name="prepare"> |
| 87 | + <mkdir dir="${basedir}/build"/> |
| 88 | + </target> |
| 89 | + |
| 90 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 91 | + <!-- | Composer --> |
| 92 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 93 | + |
| 94 | + <!-- main target --> |
| 95 | + <target name="composer" depends="composer-download, composer-install"/> |
| 96 | + |
| 97 | + <!-- preconditions --> |
| 98 | + <target name="composer-preconditions"> |
| 99 | + <available file="${basedir}/composer.phar" property="binary.present"/> |
| 100 | + <available file="${basedir}/vendor" property="vendor.present"/> |
| 101 | + </target> |
| 102 | + |
| 103 | + <!-- download the latest composer release --> |
| 104 | + <target name="composer-download" depends="composer-preconditions" unless="binary.present"> |
| 105 | + <exec dir="${basedir}" executable="wget"> |
| 106 | + <arg value="https://getcomposer.org/installer"/> |
| 107 | + </exec> |
| 108 | + <exec dir="${basedir}" executable="php"> |
| 109 | + <arg value="installer"/> |
| 110 | + </exec> |
| 111 | + <delete file="${basedir}/installer"/> |
| 112 | + </target> |
| 113 | + |
| 114 | + <!-- install dependencies --> |
| 115 | + <target name="composer-install" depends="composer-preconditions"> <!-- unless="vendor.present" --> |
| 116 | + <exec dir="${basedir}" executable="php"> |
| 117 | + <arg value="composer.phar"/> |
| 118 | + <arg value="install"/> |
| 119 | + </exec> |
| 120 | + </target> |
| 121 | + |
| 122 | + <!-- update dependencies and generate new lockfile--> |
| 123 | + <target name="composer-update" depends="composer-preconditions"> |
| 124 | + <exec dir="${basedir}" executable="php"> |
| 125 | + <arg value="composer.phar"/> |
| 126 | + <arg value="update"/> |
| 127 | + </exec> |
| 128 | + </target> |
| 129 | + |
| 130 | + <!-- cleanup --> |
| 131 | + <target name="composer-cleanup"> |
| 132 | + <delete dir="${basedir}/vendor"/> |
| 133 | + <delete file="${basedir}/composer.phar"/> |
| 134 | + </target> |
| 135 | + |
| 136 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 137 | + <!-- | PHP-Unit --> |
| 138 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 139 | + |
| 140 | + <!-- main target --> |
| 141 | + <target name="phpunit" depends="phpunit-full"/> |
| 142 | + |
| 143 | + <!-- create necessary directories --> |
| 144 | + <target name="phpunit-prepare"> |
| 145 | + <mkdir dir="${basedir}/build/phpunit"/> |
| 146 | + <mkdir dir="${basedir}/build/coverage"/> |
| 147 | + </target> |
| 148 | + |
| 149 | + <!-- run all tests --> |
| 150 | + <target name="phpunit-tests"> |
| 151 | + <exec dir="${basedir}/src/Tests" executable="${basedir}/vendor/bin/phpunit" failonerror="true"> |
| 152 | + <arg line="--verbose --stderr"/> |
| 153 | + <arg line="."/> |
| 154 | + </exec> |
| 155 | + </target> |
| 156 | + |
| 157 | + <!-- run all tests and generate logs / code coverage --> |
| 158 | + <target name="phpunit-full" depends="phpunit-prepare"> |
| 159 | + <exec dir="${basedir}/src/Tests" executable="${basedir}/vendor/bin/phpunit" failonerror="true"> |
| 160 | + <arg line="--verbose --stderr"/> |
| 161 | + <arg line="--log-junit ${basedir}/build/phpunit/phpunit.xml"/> |
| 162 | + <arg line="--coverage-html ${basedir}/build/coverage"/> |
| 163 | + <arg line="."/> |
| 164 | + </exec> |
| 165 | + </target> |
| 166 | + |
| 167 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 168 | + <!-- | PHP Lines of Code --> |
| 169 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 170 | + |
| 171 | + <!-- create necessary directories --> |
| 172 | + <target name="phploc-prepare"> |
| 173 | + <mkdir dir="${basedir}/build/phploc"/> |
| 174 | + </target> |
| 175 | + |
| 176 | + <!-- generate lines of code metric --> |
| 177 | + <target name="phploc" depends="phploc-prepare"> |
| 178 | + <exec dir="${basedir}" executable="${basedir}/vendor/bin/phploc"> |
| 179 | + <arg value="--log-xml"/> |
| 180 | + <arg value="${basedir}/build/phploc/phploc.xml"/> |
| 181 | + <arg path="${basedir}/src"/> |
| 182 | + </exec> |
| 183 | + </target> |
| 184 | + |
| 185 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 186 | + <!-- | PHP Copy-Paste-Detector --> |
| 187 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 188 | + |
| 189 | + <!-- create necessary directories --> |
| 190 | + <target name="phpcpd-prepare"> |
| 191 | + <mkdir dir="${basedir}/build/phpcpd"/> |
| 192 | + </target> |
| 193 | + |
| 194 | + <!-- run copy paste detector --> |
| 195 | + <target name="phpcpd" depends="phpcpd-prepare"> |
| 196 | + <exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcpd"> |
| 197 | + <arg value="--log-pmd"/> |
| 198 | + <arg path="${basedir}/build/phpcpd/phpcpd.xml"/> |
| 199 | + <arg path="${basedir}/src"/> |
| 200 | + </exec> |
| 201 | + </target> |
| 202 | + |
| 203 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 204 | + <!-- | PHP Code-Sniffer --> |
| 205 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 206 | + |
| 207 | + <!-- create necessary directories --> |
| 208 | + <target name="phpcs-prepare"> |
| 209 | + <mkdir dir="${basedir}/build/phpcs"/> |
| 210 | + </target> |
| 211 | + |
| 212 | + <!-- generate code sniffer metric --> |
| 213 | + <target name="phpcs" depends="phpcs-prepare"> |
| 214 | + <exec dir="${basedir}" executable="${basedir}/vendor/bin/phpcs"> |
| 215 | + <arg value="--standard=PSR2"/> |
| 216 | + <arg value="--extensions=php"/> |
| 217 | + <arg value="-n"/> |
| 218 | + <arg value="--report=checkstyle"/> |
| 219 | + <arg value="--report-file=${basedir}/build/phpcs/phpcs-checkstyle.xml"/> |
| 220 | + <arg path="${basedir}/src"/> |
| 221 | + </exec> |
| 222 | + </target> |
| 223 | + |
| 224 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 225 | + <!-- | PHP Mess-Detector --> |
| 226 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 227 | + |
| 228 | + <!-- create necessary directories --> |
| 229 | + <target name="phpmd-prepare"> |
| 230 | + <mkdir dir="${basedir}/build/phpmd"/> |
| 231 | + </target> |
| 232 | + |
| 233 | + <!-- generate mess detector metric --> |
| 234 | + <target name="phpmd" depends="phpmd-prepare"> |
| 235 | + <exec dir="${basedir}" executable="${basedir}/vendor/bin/phpmd"> |
| 236 | + <arg path="${basedir}/src"/> |
| 237 | + <arg value="xml"/> |
| 238 | + <arg value="cleancode,codesize,controversial,design,naming,unusedcode"/> |
| 239 | + <arg value="--reportfile"/> |
| 240 | + <arg value="${basedir}/build/phpmd/phpmd.xml"/> |
| 241 | + </exec> |
| 242 | + </target> |
| 243 | + |
| 244 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 245 | + <!-- | Lint --> |
| 246 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 247 | + |
| 248 | + <!-- check syntax of all php files in src/ directory --> |
| 249 | + <target name="lint"> |
| 250 | + <apply executable="php" failonerror="true"> |
| 251 | + <arg value="-l"/> |
| 252 | + <fileset dir="${basedir}"> |
| 253 | + <include name="**/*.php"/> |
| 254 | + <exclude name="**/vendor/**"/> |
| 255 | + </fileset> |
| 256 | + </apply> |
| 257 | + </target> |
| 258 | + |
| 259 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 260 | + <!-- | PHP-Doc --> |
| 261 | + <!-- ++++++++++++++++++++++++++++++++++++++++++ --> |
| 262 | + |
| 263 | + <!-- create necessary directories --> |
| 264 | + <target name="phpdoc-prepare"> |
| 265 | + <mkdir dir="${basedir}/build/phpdoc"/> |
| 266 | + </target> |
| 267 | + |
| 268 | +</project> |
0 commit comments