build.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <project name="junit" default="dist" basedir="."
  2. xmlns:artifact="antlib:org.apache.maven.artifact.ant">
  3. <tstamp />
  4. <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
  5. <property file="${user.home}/.junit.properties" />
  6. <property name="src" value="src/main/java" />
  7. <property name="srcresources" location="src/main/resources" />
  8. <property name="target" location="target" />
  9. <property name="bin" location="${target}/main" />
  10. <property name="version-base" value="4.12" />
  11. <property name="version" value="${version-base}" />
  12. <property name="dist" value="junit${version}" />
  13. <property name="versionfile" value="${src}/junit/runner/Version.java" />
  14. <property name="testsrc" location="src/test/java" />
  15. <property name="testsresources" location="src/test/resources" />
  16. <property name="testbin" location="${target}/test/java" />
  17. <property name="unjarred"
  18. value="**/*.jar, ${testfiles}, doc/**, README.html, .classpath, .project, cpl-v10.html" />
  19. <property name="binjar" value="junit-${version}.jar" />
  20. <property name="srcjar" value="junit-${version}-sources.jar" />
  21. <property name="javadocdir" location="${dist}/javadoc" />
  22. <property name="hamcrestlib" location="lib/hamcrest-core-1.3.jar" />
  23. <target name="init">
  24. <tstamp/>
  25. </target>
  26. <target name="versiontag" depends="init">
  27. <filter token="version" value="${version}" />
  28. <copy
  29. file="${versionfile}.template"
  30. tofile="${versionfile}"
  31. filtering="on"
  32. overwrite="true"
  33. />
  34. </target>
  35. <target name="clean">
  36. <!-- If two builds are made within a minute -->
  37. <delete dir="${dist}" quiet="true" />
  38. <!-- Delete all previous temporary build artifacts -->
  39. <delete dir="${target}" quiet="true" />
  40. </target>
  41. <macrodef name="junit_compilation">
  42. <attribute name="srcdir"/>
  43. <attribute name="destdir"/>
  44. <attribute name="classpath"/>
  45. <sequential>
  46. <mkdir dir="@{destdir}"/>
  47. <javac
  48. srcdir="@{srcdir}"
  49. destdir="@{destdir}"
  50. debug="on"
  51. classpath="@{classpath}"
  52. includeantruntime="false"
  53. source="1.5"
  54. target="1.5"
  55. >
  56. <compilerarg value="-Xlint:unchecked" />
  57. </javac>
  58. </sequential>
  59. </macrodef>
  60. <target name="build" depends="versiontag">
  61. <junit_compilation srcdir="${src}" destdir="${bin}" classpath="${hamcrestlib}"/>
  62. <junit_compilation srcdir="${testsrc}" destdir="${testbin}" classpath="${hamcrestlib};${bin}"/>
  63. </target>
  64. <target name="jars" depends="build">
  65. <mkdir dir="${dist}" />
  66. <jar
  67. jarfile="${dist}/${srcjar}"
  68. basedir="${src}"
  69. excludes="${unjarred}, **/*.class"
  70. />
  71. <jar
  72. jarfile="${dist}/${binjar}"
  73. basedir="${bin}"
  74. excludes="${unjarred}, **/*.java, build.xml"
  75. />
  76. </target>
  77. <target name="samples-and-tests">
  78. <copy todir="${dist}">
  79. <fileset dir="${testbin}" />
  80. <fileset dir="${testsrc}" />
  81. </copy>
  82. </target>
  83. <target name="javadoc">
  84. <javadoc destdir="${javadocdir}"
  85. author="false"
  86. version="false"
  87. use="false"
  88. windowtitle="JUnit API"
  89. stylesheetfile="src/main/javadoc/stylesheet.css"
  90. >
  91. <excludepackage name="junit.*" />
  92. <excludepackage name="org.junit.internal.*" />
  93. <excludepackage name="org.junit.experimental.theories.internal.*" />
  94. <sourcepath location="${src}" />
  95. <link href="http://docs.oracle.com/javase/1.5.0/docs/api/" />
  96. <classpath>
  97. <pathelement location="${hamcrestlib}" />
  98. </classpath>
  99. </javadoc>
  100. </target>
  101. <target name="populate-dist"
  102. depends="clean, build, jars, samples-and-tests, javadoc"
  103. >
  104. <copy todir="${dist}/doc">
  105. <fileset dir="doc"/>
  106. </copy>
  107. <copy file="README.md" tofile="${dist}/README.md" />
  108. <copy file="BUILDING" tofile="${dist}/BUILDING" />
  109. <copy file="epl-v10.html" tofile="${dist}/epl-v10.html" />
  110. <copy file="build.xml" tofile="${dist}/build.xml" />
  111. </target>
  112. <macrodef name="run-dist-tests">
  113. <!-- Runs the tests against the built jar files -->
  114. <element name="extra-args" implicit="yes" />
  115. <sequential>
  116. <java classname="org.junit.runner.JUnitCore" fork="yes" failonerror="true">
  117. <extra-args />
  118. <arg value="org.junit.tests.AllTests"/>
  119. <classpath>
  120. <pathelement location="${dist}" />
  121. <pathelement location="${dist}/${binjar}" />
  122. <pathelement location="${hamcrestlib}" />
  123. <pathelement location="${testsresources}" />
  124. </classpath>
  125. </java>
  126. </sequential>
  127. </macrodef>
  128. <macrodef name="run-local-tests">
  129. <!-- Runs the tests against the local class files -->
  130. <sequential>
  131. <java classname="org.junit.runner.JUnitCore" fork="yes" failonerror="true">
  132. <arg value="org.junit.tests.AllTests"/>
  133. <classpath>
  134. <pathelement location="${bin}" />
  135. <pathelement location="${testbin}" />
  136. <pathelement location="${hamcrestlib}" />
  137. <pathelement location="${testsresources}" />
  138. </classpath>
  139. </java>
  140. </sequential>
  141. </macrodef>
  142. <target name="test" depends="build">
  143. <run-local-tests />
  144. </target>
  145. <target name="dist" depends="populate-dist">
  146. <run-dist-tests>
  147. <jvmarg value="-Dignore.this=ignored"/>
  148. </run-dist-tests>
  149. </target>
  150. <target name="profile" depends="populate-dist">
  151. <run-dist-tests>
  152. <jvmarg value="-agentlib:hprof=cpu=samples"/>
  153. </run-dist-tests>
  154. </target>
  155. </project>