查看: 235|回复: 0

[PHP代码] 基于window下的jenkins php集成环境搭建分享(2)

发表于 7 天前

来自: http://my.oschina.net/u/1167564/blog/607045


@build.xml (ant构建配置文件)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="name-of-project" default="build">
  3. <!-- By default, we assume all tools to be on the $PATH -->
  4. <property name="toolsdir" value=""/>
  5. <!--改成您相应的应用目录和测试目录-->
  6. <property name="testdir" value="${basedir}/Test"/>
  7. <property name="appdir" value="${basedir}/PHPCbping"/>
  8. <available file="${basedir}/build" property="build_path"/>
  9. <available file="${basedir}/App/TestControllers1" property="TestControllers1_exist"/>
  10. <!--<property name="version-m" value="1.1" />-->
  11. <!--<property name="version" value="1.1.0" />-->
  12. <!--<property name="stability" value="stable" />-->
  13. <!--<property name="releasenotes" value="" />-->
  14. <!--<property name="tarfile" value="${phing.project.name}.${buildnumber}.${buildid}.tar.gz" />-->
  15. <!--<property name="pkgfile" value="${phing.project.name}.${version}.tgz" />-->
  16. <!--<property name="distfile" value="dist/${tarfile}" />-->
  17. <!--<property name="tests.dir" value="test" />-->
  18. <!-- -->
  19. <!--<fileset id="api.tar.gz" dir=".">-->
  20. <!--<include name="test/**"/>-->
  21. <!--<include name="*.php"/>-->
  22. <!--<include name="*.xml"/>-->
  23. <!--</fileset>-->
  24. <!--<target name="check" description="Check variables" >-->
  25. <!--<fail unless="version" message="Version not defined!" />-->
  26. <!--<fail unless="buildnumber" message="buildnumber not defined!" />-->
  27. <!--<fail unless="buildid" message="buildid not defined!" />-->
  28. <!--<delete dir="dist" failonerror="false" />-->
  29. <!--<mkdir dir="dist" />-->
  30. <!--</target>-->
  31. <!--<target name="tar" depends="check" description="Create tar file for release">-->
  32. <!--<echo msg="Creating distribution tar for ${phing.project.name} ${version}"/>-->
  33. <!--<delete file="${distfile}" failonerror="false"/>-->
  34. <!--<tar destfile="${distfile}" compression="gzip">-->
  35. <!--<fileset refid="api.tar.gz"/>-->
  36. <!--</tar>-->
  37. <!--</target>-->
  38. <!-- Uncomment the following when the tools are in ${basedir}/vendor/bin -->
  39. <!-- <property name="toolsdir" value="${basedir}/vendor/bin/"/> -->
  40. <target name="build"
  41. depends="prepare,lint,phploc-ci,pdepend,phpmd-ci,phpcpd-ci,phpunit,phpdox"
  42. description=""/>
  43. <target name="build-parallel"
  44. depends="prepare,lint,tools-parallel,phpunit,phpdox"
  45. description=""/>
  46. <target name="tools-parallel" description="Run tools in parallel">
  47. <parallel threadCount="2">
  48. <sequential>
  49. <antcall target="pdepend"/>
  50. <antcall target="phpmd-ci"/>
  51. </sequential>
  52. <antcall target="phpcpd-ci"/>
  53. <!--<antcall target="phpcs-ci"/>-->
  54. <antcall target="phploc-ci"/>
  55. </parallel>
  56. </target>
  57. <target name="clean"
  58. unless="clean.done"
  59. if="build_path"
  60. description="Cleanup build artifacts">
  61. <delete includeEmptyDirs="true">
  62. <fileset dir="build" includes="**/*"/>
  63. </delete>
  64. <property name="clean.done" value="true"/>
  65. </target>
  66. <target name="prepare"
  67. unless="prepare.done"
  68. depends="clean,phpunit-init-clean"
  69. description="Prepare for build">
  70. <chmod dir="build" perm="0777"/>
  71. <mkdir dir="${basedir}/build/api"/>
  72. <mkdir dir="${basedir}/build/coverage"/>
  73. <mkdir dir="${basedir}/build/logs"/>
  74. <mkdir dir="${basedir}/build/pdepend"/>
  75. <mkdir dir="${basedir}/build/phpdox"/>
  76. <property name="prepare.done" value="true"/>
  77. </target>
  78. <target name="phpunit-init-clean" if="TestControllers1_exist" depends="clean">
  79. <move todir="${testdir}/TestControllers1" failonerror="">
  80. <fileset dir="${basedir}/App/TestControllers1"/>
  81. </move>
  82. </target>
  83. <target name="lint"
  84. unless="lint.done"
  85. description="Perform syntax check of sourcecode files">
  86. <apply executable="php" failonerror="true" taskname="lint">
  87. <arg value="-l"/>
  88. <fileset dir="${appdir}">
  89. <include name="**/*.php"/>
  90. <modified/>
  91. </fileset>
  92. <fileset dir="${testdir}">
  93. <include name="**/*.php"/>
  94. <modified/>
  95. </fileset>
  96. </apply>
  97. <property name="lint.done" value="true"/>
  98. </target>
  99. <target name="phploc"
  100. unless="phploc.done"
  101. description="Measure project size using PHPLOC and print human readable output. Intended for usage on the command line.">
  102. <exec executable="${toolsdir}phploc.bat" taskname="phploc">
  103. <arg value="--count-tests"/>
  104. <arg path="${appdir}"/>
  105. <!--<arg path="${testdir}"/>-->
  106. </exec>
  107. <property name="phploc.done" value="true"/>
  108. </target>
  109. <target name="phploc-ci"
  110. unless="phploc.done"
  111. depends="prepare"
  112. description="Measure project size using PHPLOC and log result in CSV and XML format. Intended for usage within a continuous integration environment.">
  113. <exec executable="${toolsdir}phploc.bat" taskname="phploc">
  114. <arg value="--count-tests"/>
  115. <arg value="--log-csv"/>
  116. <arg path="${basedir}/build/logs/phploc.csv"/>
  117. <arg value="--log-xml"/>
  118. <arg path="${basedir}/build/logs/phploc.xml"/>
  119. <arg path="${appdir}"/>
  120. <!--<arg path="${testdir}"/>-->
  121. </exec>
  122. <property name="phploc.done" value="true"/>
  123. </target>
  124. <target name="pdepend"
  125. unless="pdepend.done"
  126. depends="prepare"
  127. description="Calculate software metrics using PHP_Depend and log result in XML format. Intended for usage within a continuous integration environment.">
  128. <exec executable="${toolsdir}pdepend.bat" taskname="pdepend">
  129. <arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml"/>
  130. <arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg"/>
  131. <arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg"/>
  132. <arg path="${appdir}"/>
  133. </exec>
  134. <property name="pdepend.done" value="true"/>
  135. </target>
  136. <target name="phpmd"
  137. unless="phpmd.done"
  138. description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
  139. <exec executable="${toolsdir}phpmd.bat" taskname="phpmd">
  140. <arg path="${appdir}"/>
  141. <arg value="text"/>
  142. <arg path="${basedir}/phpmd.xml"/>
  143. </exec>
  144. <property name="phpmd.done" value="true"/>
  145. </target>
  146. <target name="phpmd-ci"
  147. unless="phpmd.done"
  148. depends="prepare"
  149. description="Perform project mess detection using PHPMD and log result in XML format. Intended for usage within a continuous integration environment.">
  150. <exec executable="${toolsdir}phpmd.bat" taskname="phpmd">
  151. <arg path="${appdir}"/>
  152. <arg value="xml"/>
  153. <arg path="${basedir}/phpmd.xml"/>
  154. <arg value="--reportfile"/>
  155. <arg path="${basedir}/build/logs/pmd.xml"/>
  156. </exec>
  157. <property name="phpmd.done" value="true"/>
  158. </target>
  159. <target name="phpcpd"
  160. unless="phpcpd.done"
  161. description="Find duplicate code using PHPCPD and print human readable output. Intended for usage on the command line before committing.">
  162. <exec executable="${toolsdir}phpcpd.bat" taskname="phpcpd">
  163. <arg path="${appdir}"/>
  164. </exec>
  165. <property name="phpcpd.done" value="true"/>
  166. </target>
  167. <target name="phpcpd-ci"
  168. unless="phpcpd.done"
  169. depends="prepare"
  170. description="Find duplicate code using PHPCPD and log result in XML format. Intended for usage within a continuous integration environment.">
  171. <exec executable="${toolsdir}phpcpd.bat" taskname="phpcpd">
  172. <arg value="--log-pmd"/>
  173. <arg path="${basedir}/build/logs/pmd-cpd.xml"/>
  174. <arg path="${appdir}"/>
  175. </exec>
  176. <property name="phpcpd.done" value="true"/>
  177. </target>
  178. <target name="phpunit"
  179. unless="phpunit.done"
  180. depends="prepare"
  181. description="Run unit tests with PHPUnit">
  182. <exec executable="${toolsdir}phpunit.bat" failonerror="true" taskname="phpunit">
  183. <arg value="--configuration"/>
  184. <arg path="${basedir}/phpunit.xml.dist"/>
  185. <arg value="--include-path"/>
  186. <arg path="${appdir}"/>
  187. </exec>
  188. <property name="phpunit.done" value="true"/>
  189. </target>
  190. <target name="phpdox"
  191. unless="phpdox.done"
  192. depends="phploc-ci"
  193. description="Generate project documentation using phpDox">
  194. <exec executable="${toolsdir}phpdox.bat" dir="${basedir}" taskname="phpdox"/>
  195. <property name="phpdox.done" value="true"/>
  196. </target>
  197. </project>
复制代码

@phpunit.xm.dist(相关信息可以查看官方文档)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <phpunit
  3. colors="true"
  4. stopOnFailure="false"
  5. backupStaticAttributes="false"
  6. convertErrorsToExceptions="true"
  7. convertNoticesToExceptions="true"
  8. convertWarningsToExceptions="true"
  9. processIsolation="false"
  10. addUncoveredFilesFromWhitelist="true"
  11. syntaxCheck="false"
  12. cacheTokens="true"
  13. verbose="false"
  14. >
  15. <php>
  16. <includePath>PHPCbping/</includePath>
  17. </php>
  18. <testsuites>
  19. <testsuite name="TEST">
  20. <directory>Test/</directory>
  21. <!--<file phpVersion="5.3.0" phpVersionOperator=">=">Test/CommandTest.php</file>-->
  22. <exclude>PHPCbping/</exclude>
  23. </testsuite>
  24. </testsuites>
  25. <filter>
  26. <whitelist processUncoveredFilesFromWhitelist="true">
  27. <directory suffix=".php">PHPCbping/</directory>
  28. </whitelist>
  29. </filter>
  30. <logging>
  31. <log type="coverage-clover" target="build/logs/clover.xml"/>
  32. <log type="coverage-html" target="build/coverage"/>
  33. <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
  34. </logging>
  35. </phpunit>
复制代码

@phpmd.xml(相关规则信息可以查看官方文档)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ruleset name="phpcbping-coding-standard"
  3. xmlns="http://pmd.sf.net/ruleset/1.0.0"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
  6. http://pmd.sf.net/ruleset_xml_schema.xsd"
  7. xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
  8. <description>Description of your coding standard</description>
  9. <rule ref="rulesets/codesize.xml"/>
  10. <rule ref="rulesets/cleancode.xml"/>
  11. <rule ref="rulesets/unusedcode.xml"/>
  12. <rule ref="rulesets/design.xml"/>
  13. <rule ref="rulesets/naming.xml"/>
  14. <rule ref="rulesets/controversial.xml/Superglobals"/>
  15. <!-- ... -->
  16. </ruleset>
复制代码

@phpdox.xml(相关规则信息可以查看官方文档)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <phpdox xmlns="http://xml.phpdox.net/config">
  3. <project name="phpdox-project" source="${basedir}/PHPCbping" workdir="${basedir}/build/api/xml">
  4. <collector publiconly="false" backend="parser">
  5. <include mask="*.php"/>
  6. </collector>
  7. <generator output="${basedir}/build/api">
  8. <enrich base="${basedir}/build/logs">
  9. <source type="build"/>
  10. <source type="pmd"/>
  11. <source type="phploc"/>
  12. </enrich>
  13. <build engine="html" enabled="true" output="html">
  14. <file extension="html"/>
  15. </build>
  16. </generator>
  17. </project>
  18. </phpdox>
复制代码




回复

使用道具 举报