|
3 | 3 | <property name="src.dir" value="src/main" /> |
4 | 4 | <property name="src.java.dir" value="${src.dir}/java" /> |
5 | 5 |
|
| 6 | + <property name="test.dir" value="src/test" /> |
| 7 | + <property name="test.java.dir" value="${test.dir}/java" /> |
| 8 | + |
6 | 9 | <property name="build.dir" value="build" /> |
| 10 | + <property name="build.classes.dir" value="${build.dir}/classes" /> |
7 | 11 | <property name="dist.dir" value="dist" /> |
8 | 12 |
|
| 13 | + <property name="build.reports.dir" value="${build.dir}/reports" /> |
| 14 | + |
| 15 | + <property name="junit.reports.dir" value="${build.reports.dir}/junit" /> |
| 16 | + <property name="junit.reports.xml.dir" value="${junit.reports.dir}/xml" /> |
| 17 | + <property name="junit.reports.html.dir" value="${junit.reports.dir}/html" /> |
| 18 | + |
| 19 | + <property name="junit.test.pattern" value="**/*Test.java" /> |
| 20 | + |
| 21 | + <property name="cobertura.reports.dir" value="${build.reports.dir}/cobertura" /> |
| 22 | + <property name="cobertura.reports.xml.dir" value="${cobertura.reports.dir}/xml" /> |
| 23 | + <property name="cobertura.reports.html.dir" value="${cobertura.reports.dir}/html" /> |
| 24 | + |
| 25 | + <property name="lib.dir" value="lib" /> |
| 26 | + <property name="lib.test.dir" value="${lib.dir}/test" /> |
| 27 | + |
| 28 | + <property name="build.test.classes.dir" value="${build.dir}/test/classes" /> |
| 29 | + <property name="cobertura.instrumented.dir" value="${build.dir}/test/instrumented-classes" /> |
| 30 | + |
9 | 31 | <target name="init"> |
10 | | - <mkdir dir="${build.dir}" /> |
| 32 | + <mkdir dir="${build.classes.dir}" /> |
| 33 | + <mkdir dir="${build.test.classes.dir}" /> |
11 | 34 | <mkdir dir="${dist.dir}" /> |
| 35 | + |
| 36 | + <mkdir dir="${junit.reports.xml.dir}" /> |
| 37 | + <mkdir dir="${junit.reports.html.dir}" /> |
| 38 | + |
| 39 | + <mkdir dir="${cobertura.reports.xml.dir}" /> |
| 40 | + <mkdir dir="${cobertura.reports.html.dir}" /> |
12 | 41 | </target> |
13 | 42 |
|
14 | 43 | <target name="clean"> |
|
17 | 46 | </target> |
18 | 47 |
|
19 | 48 | <target name="compile"> |
20 | | - <javac srcdir="${src.java.dir}" destdir="${build.dir}" debug="on" includeantruntime="false" source="1.6" target="1.6" /> |
| 49 | + <javac srcdir="${src.java.dir}" destdir="${build.classes.dir}" debug="on" includeantruntime="false" source="1.6" target="1.6" /> |
| 50 | + </target> |
| 51 | + |
| 52 | + <!-- |
| 53 | + Now for the compile classpaths |
| 54 | + --> |
| 55 | + |
| 56 | + <path id="test.compile.classpath"> |
| 57 | + <fileset dir="${lib.test.dir}" includes="**/*.jar" /> |
| 58 | + <pathelement path="${build.classes.dir}/" /> |
| 59 | + </path> |
| 60 | + |
| 61 | + <!-- |
| 62 | + Now for the test classpath |
| 63 | + --> |
| 64 | + <path id="test.classpath"> |
| 65 | + <fileset dir="${lib.test.dir}" includes="**/*.jar" /> |
| 66 | + <fileset dir="${build.test.classes.dir}"> |
| 67 | + <include name="**/*.class" /> |
| 68 | + <include name="**/*.properties" /> |
| 69 | + </fileset> |
| 70 | + </path> |
| 71 | + |
| 72 | + <path id="cobertura.classpath"> |
| 73 | + <fileset dir="${lib.test.dir}" includes="**/*.jar" /> |
| 74 | + </path> |
| 75 | + |
| 76 | + <taskdef classpathref="cobertura.classpath" resource="tasks.properties" /> |
| 77 | + |
| 78 | + <!-- |
| 79 | + Compile all of the test cases |
| 80 | + --> |
| 81 | + <target name="compile-test" depends="compile" description="[cobertura-build] Compile all of the test code sources"> |
| 82 | + <javac srcdir="${test.java.dir}" destdir="${build.test.classes.dir}" debug="on" includeantruntime="false"> |
| 83 | + <classpath path="${build.classes.dir}" /> |
| 84 | + <classpath refid="test.classpath" /> |
| 85 | + </javac> |
| 86 | + |
| 87 | + <copy todir="${build.test.classes.dir}"> |
| 88 | + <fileset dir="${test.java.dir}"> |
| 89 | + <include name="**/*.properties" /> |
| 90 | + </fileset> |
| 91 | + </copy> |
| 92 | + </target> |
| 93 | + |
| 94 | + <!-- |
| 95 | + |
| 96 | + --> |
| 97 | + <target name="cobertura" depends="compile-test" description="[cobertura-build] Run the junit tests, compile the cobertura reports"> |
| 98 | + <delete file="cobertura.ser" /> |
| 99 | + |
| 100 | + <cobertura-instrument todir="${cobertura.instrumented.dir}"> |
| 101 | + <includeClasses regex=".*" /> |
| 102 | + <excludeClasses regex="org.apache.log4j.*" /> |
| 103 | + <excludeClasses regex=".*\.Test.*" /> |
| 104 | + |
| 105 | + <instrumentationClasspath> |
| 106 | + <pathelement location="${build.classes.dir}" /> |
| 107 | + </instrumentationClasspath> |
| 108 | + </cobertura-instrument> |
| 109 | + |
| 110 | + <junit fork="yes" failureProperty="test.failed" printsummary="true" showoutput="true"> |
| 111 | + <!-- |
| 112 | + Specify the name of the coverage data file to use. |
| 113 | + The value specified below is the default. |
| 114 | + --> |
| 115 | + <sysproperty key="net.sourceforge.cobertura.datafile" file="${basedir}/cobertura.ser" /> |
| 116 | + |
| 117 | + <!-- |
| 118 | + Note the classpath order: instrumented classes are before the |
| 119 | + original (uninstrumented) classes. This is important. |
| 120 | + --> |
| 121 | + <classpath location="${cobertura.instrumented.dir}" /> |
| 122 | + <classpath location="${build.classes.dir}" /> |
| 123 | + |
| 124 | + <classpath location="${build.test.classes.dir}" /> |
| 125 | + |
| 126 | + <!-- |
| 127 | + The instrumented classes reference classes used by the |
| 128 | + Cobertura runtime, so Cobertura and its dependencies |
| 129 | + must be on your classpath. |
| 130 | + --> |
| 131 | + <classpath refid="cobertura.classpath" /> |
| 132 | + |
| 133 | + <formatter type="xml" /> |
| 134 | + <batchtest todir="${junit.reports.xml.dir}" unless="testcase"> |
| 135 | + <fileset dir="${test.java.dir}"> |
| 136 | + <include name="${junit.test.pattern}" /> |
| 137 | + </fileset> |
| 138 | + </batchtest> |
| 139 | + </junit> |
| 140 | + |
| 141 | + <junitreport todir="${junit.reports.xml.dir}" > |
| 142 | + <fileset dir="${junit.reports.xml.dir}"> |
| 143 | + <include name="TEST-*.xml"/> |
| 144 | + </fileset> |
| 145 | + <report format="frames" todir="${junit.reports.html.dir}"/> |
| 146 | + </junitreport> |
| 147 | + <!-- Now generate the report --> |
| 148 | + <cobertura-report format="html" destdir="${cobertura.reports.html.dir}" srcdir="${src.java.dir}" /> |
| 149 | + <cobertura-report format="xml" destdir="${cobertura.reports.xml.dir}" srcdir="${src.java.dir}" /> |
| 150 | + |
| 151 | + <fail if="${test.failed}" message="JUnit Tests Failed!!" /> |
21 | 152 | </target> |
22 | 153 |
|
23 | | - <target name="dist" depends="clean,init,compile" description="build the distributable jar file"> |
| 154 | + <target name="dist" depends="clean,init,compile,cobertura" description="build the distributable jar file"> |
24 | 155 | <jar destfile="dist/${ant.project.name}.jar"> |
25 | | - <fileset dir="${build.dir}"> |
| 156 | + <fileset dir="${build.classes.dir}"> |
26 | 157 | <include name="**/*.*"/> |
27 | 158 | </fileset> |
28 | 159 | </jar> |
|
0 commit comments