build.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="SonataDoctrineORMAdminBundle" basedir="." default="build:main">
  3. <!-- Config files -->
  4. <property name="dir.config" value="${project.basedir}" />
  5. <property name="config.phpunit" value="${dir.config}/phpunit.xml.dist" />
  6. <property name="config.pmd" value="${dir.config}/pmd.xml.dist" />
  7. <!-- Build paths -->
  8. <property name="dir.build" value="${project.basedir}/build" />
  9. <property name="dir.reports" value="${dir.build}/reports" />
  10. <property name="dir.reports.check" value="${dir.reports}/check" />
  11. <property name="dir.reports.test" value="${dir.reports}/test" />
  12. <property name="dir.reports.test.unit" value="${dir.reports.test}/unit" />
  13. <property name="dir.reports.test.coverage" value="${dir.reports.test}/coverage" />
  14. <property name="dir.docs" value="${dir.build}/docs" />
  15. <property name="dir.docs.api" value="${dir.docs}/api" />
  16. <property name="dir.docs.rst" value="${dir.docs}/rst" />
  17. <property name="dir.docs.php" value="${dir.docs}/php" />
  18. <!-- Source paths -->
  19. <property name="dir.src" value="${project.basedir}" />
  20. <property name="dir.src.rst" value="${dir.src}/Resources/doc" />
  21. <!-- Source fileset (used by check tasks) -->
  22. <fileset id="sourcecode" dir="${dir.src}">
  23. <include name="**/*.php" />
  24. <exclude name="**/*Test.php" />
  25. <exclude name="vendor/**/*.php" />
  26. </fileset>
  27. <!-- BUILD TASKS -->
  28. <!-- Main (default) task -->
  29. <target name="build:main"
  30. depends="build:clean, build:prepare, build:check, build:test, build:doc"
  31. description="Run all test and build everything"/>
  32. <!-- Clean previous build files -->
  33. <target name="build:clean"
  34. description="Clean previous build files">
  35. <delete dir="${dir.build}" verbose="true" />
  36. </target>
  37. <!-- Prepare build (performed by each build:* task when called as standalone) -->
  38. <target name="build:prepare"
  39. description="Prepare build">
  40. <mkdir dir="${dir.build}" />
  41. </target>
  42. <!-- Check Project -->
  43. <target name="build:check"
  44. description="Check source code"
  45. depends="build:prepare, check:prepare, check:cs, check:md, check:cpd"/>
  46. <!-- Test Project -->
  47. <target name="build:test"
  48. description="Perform all tests"
  49. depends="build:prepare, test:prepare, test:unit"/>
  50. <!-- Generate documentation -->
  51. <target name="build:doc"
  52. depends="build:prepare, doc:prepare, doc:api"
  53. description="Generate API documentation"/>
  54. <!-- CHECK SECTION -->
  55. <!-- Prepare check (performed by each check:* task when called as standalone) -->
  56. <target name="check:prepare"
  57. description="Create check directories">
  58. <mkdir dir="${dir.reports.check}" />
  59. </target>
  60. <!-- CodeSniffer with Symfony2 convention -->
  61. <target name="check:cs"
  62. depends="check:prepare"
  63. description="Generate PHP_CodeSniffer report">
  64. <phpcodesniffer standard="Symfony2" showSniffs="true" showWarnings="true">
  65. <fileset refid="sourcecode" />
  66. <config name="error_severity" value="1"/>
  67. <config name="warning_severity" value="5"/>
  68. <formatter type="checkstyle" outfile="${dir.reports.check}/checkstyle.xml" />
  69. </phpcodesniffer>
  70. </target>
  71. <!-- PHP Copy and Paste Detector -->
  72. <target name="check:cpd"
  73. description="Generate phpcpd report"
  74. depends="check:prepare">
  75. <phpcpd>
  76. <fileset refid="sourcecode" />
  77. <formatter type="pmd" outfile="${dir.reports.check}/cpd.xml" />
  78. </phpcpd>
  79. </target>
  80. <!-- PHP Mess detector -->
  81. <target name="check:md"
  82. description="Generate phpmd report"
  83. depends="check:prepare" >
  84. <!-- if config.pmd file not found, use default pmd config -->
  85. <if>
  86. <not><available file="${config.pmd}"/></not>
  87. <then>
  88. <echo msg="phpmd config file not found: ${config.pmd}" />
  89. <property name="config.pmd" value="codesize,unusedcode,naming,design" override="yes"/>
  90. </then>
  91. </if>
  92. <phpmd rulesets="${config.pmd}">
  93. <fileset refid="sourcecode" />
  94. <formatter type="xml" outfile="${dir.reports.check}/pmd.xml" />
  95. </phpmd>
  96. </target>
  97. <!-- TEST SECTION -->
  98. <!-- Prepare test environment (performed by each test:* task when called as standalone) -->
  99. <target name="test:prepare"
  100. description="Prepare the test environment">
  101. <echo msg="Prepare test report directory" />
  102. <mkdir dir="${dir.reports.test}" />
  103. <echo msg="Installing/Updating vendors..." />
  104. <exec command="composer update" passthru="true"/>
  105. </target>
  106. <!-- Prepare unit test environment -->
  107. <target name="test:unit:prepare"
  108. description="Prepare the unit test environment"
  109. depends="test:prepare">
  110. <mkdir dir="${dir.reports.test.unit}" />
  111. </target>
  112. <!-- Execute unit tests and code coverage -->
  113. <target name="test:unit"
  114. description="Perform unit tests and code coverage"
  115. depends="test:prepare, test:unit:prepare">
  116. <exec executable="phpunit" logoutput="true">
  117. <arg line="--log-junit ${dir.reports.test.unit}/phpunit.xml" />
  118. <arg line="--coverage-clover ${dir.reports.test.coverage}/clover.xml" />
  119. <arg line="--coverage-html ${dir.reports.test.coverage}/html" />
  120. <arg line="-c ${config.phpunit}" />
  121. </exec>
  122. </target>
  123. <!-- DOCUMENTATION SECTION -->
  124. <!-- Prepare the documentation environment -->
  125. <target name="doc:prepare"
  126. description="Prepare the documentation">
  127. <mkdir dir="${dir.docs}" />
  128. </target>
  129. <!-- Prepare the Api documentation -->
  130. <target name="doc:api:prepare"
  131. description="Prepare the API documentation">
  132. <mkdir dir="${dir.docs.api}" />
  133. </target>
  134. <!-- Generate the Api documentation -->
  135. <target name="doc:api"
  136. description="Generate API documentation"
  137. depends="doc:prepare, doc:api:prepare">
  138. <exec executable="apigen" logoutput="true" passthru="true">
  139. <arg line="--source ${dir.src}" />
  140. <arg line="--exclude */vendor/*" />
  141. <arg line="--exclude */Tests/*" />
  142. <arg line="--destination ${dir.docs.api}" />
  143. </exec>
  144. </target>
  145. <!-- Prepare the phpDoc documentation -->
  146. <target name="doc:php:prepare"
  147. description="Prepare the Php documentation">
  148. <mkdir dir="${dir.docs.php}" />
  149. </target>
  150. <!-- Build the phpDoc documentation -->
  151. <target name="doc:php"
  152. description="Generate Php documentation"
  153. depends="doc:prepare, doc:php:prepare">
  154. <exec executable="phpdoc" logoutput="true" passthru="true">
  155. <arg line="--directory ${dir.src}" />
  156. <arg line="--ignore '*/vendor/*,*/Tests/*'" />
  157. <arg line="--target ${dir.docs.php}" />
  158. <arg line="--sourcecode" />
  159. </exec>
  160. </target>
  161. <!-- Generate the RST documentation -->
  162. <target name="doc:rst"
  163. description="Generate RST documentation"
  164. depends="doc:prepare">
  165. <!-- delete previous directory (sphinx refuses to work on an existing directory) -->
  166. <delete dir="${dir.docs.rst}"/>
  167. <exec command="sphinx-build -C -a -b html ${dir.src.rst} ${dir.docs.rst}" passthru="true" />
  168. </target>
  169. </project>