|
1 | | -<project name="mirth-cli" basedir="." default="build" xmlns:unless="ant:unless"> |
| 1 | +<project name="mirth-cli" basedir="." default="build" |
| 2 | + xmlns:jacoco="antlib:org.jacoco.ant" xmlns:unless="ant:unless" xmlns:if="ant:if"> |
| 3 | + |
2 | 4 | <target name="init"> |
3 | 5 | <property file="build.properties" /> |
4 | 6 |
|
|
12 | 14 |
|
13 | 15 | <target name="clean" depends="init"> |
14 | 16 | <delete dir="${classes}" /> |
15 | | - <delete dir="${build}" /> |
| 17 | + <delete dir="${build.dir}" /> |
16 | 18 | <delete dir="${dist}" /> |
17 | 19 | <delete dir="${test_classes}" /> |
18 | 20 | </target> |
|
25 | 27 | </target> |
26 | 28 |
|
27 | 29 | <target name="build" depends="compile"> |
28 | | - <mkdir dir="${build}" /> |
| 30 | + <mkdir dir="${build.dir}" /> |
29 | 31 |
|
30 | 32 | <!-- log4j2.properties file --> |
31 | | - <mkdir dir="${build}/conf" /> |
| 33 | + <mkdir dir="${build.dir}/conf" /> |
32 | 34 |
|
33 | | - <copy todir="${build}/conf"> |
| 35 | + <copy todir="${build.dir}/conf"> |
34 | 36 | <fileset dir="${conf}" /> |
35 | 37 | </copy> |
36 | 38 |
|
37 | 39 | <!-- cli-lib --> |
38 | | - <mkdir dir="${build}/cli-lib" /> |
| 40 | + <mkdir dir="${build.dir}/cli-lib" /> |
39 | 41 |
|
40 | | - <copy todir="${build}/cli-lib"> |
| 42 | + <copy todir="${build.dir}/cli-lib"> |
41 | 43 | <fileset dir="${lib}" /> |
42 | 44 | </copy> |
43 | 45 |
|
44 | | - <jar destfile="${build}/${cli.jar}" basedir="${classes}" modificationTime="${archive.entry.date}"> |
| 46 | + <jar destfile="${build.dir}/${cli.jar}" basedir="${classes}" modificationTime="${archive.entry.date}"> |
45 | 47 | <include name="com/mirth/connect/cli/**" /> |
46 | 48 | <exclude name="com/mirth/connect/cli/launcher/**" /> |
47 | 49 | </jar> |
48 | 50 |
|
49 | | - <jar destfile="${build}/${cli-launcher.jar}" basedir="${classes}" modificationTime="${archive.entry.date}"> |
| 51 | + <jar destfile="${build.dir}/${cli-launcher.jar}" basedir="${classes}" modificationTime="${archive.entry.date}"> |
50 | 52 | <include name="com/mirth/connect/cli/launcher/**" /> |
51 | 53 |
|
52 | 54 | <manifest> |
|
91 | 93 | resource="org/jacoco/ant/antlib.xml" |
92 | 94 | classpathref="jacoco.classpath"/> |
93 | 95 |
|
| 96 | + <target name="test-coverage" depends="test-compile"> |
| 97 | + <description>Run unit tests WITH JaCoCo coverage.</description> |
| 98 | + |
| 99 | + <delete dir="${jacoco.data.dir}" /> |
| 100 | + <delete dir="${reports.jacoco.dir}" /> |
| 101 | + |
| 102 | + <jacoco:agent property="jacoco.agent.arg" |
| 103 | + destfile="${jacoco.exec.file}" |
| 104 | + exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" /> |
| 105 | + |
| 106 | + <antcall target="test-run" /> |
| 107 | + |
| 108 | + <jacoco:report> |
| 109 | + <executiondata> |
| 110 | + <file file="${jacoco.exec.file}" /> |
| 111 | + </executiondata> |
| 112 | + <structure name="${ant.project.name}"> |
| 113 | + <classfiles> |
| 114 | + <fileset dir="${classes}" /> |
| 115 | + </classfiles> |
| 116 | + <sourcefiles encoding="UTF-8"> |
| 117 | + <fileset dir="${src}" /> |
| 118 | + </sourcefiles> |
| 119 | + </structure> |
| 120 | + <html destdir="${reports.jacoco.html}" /> |
| 121 | + <xml destfile="${reports.jacoco.xml}"/> |
| 122 | + </jacoco:report> |
| 123 | + </target> |
| 124 | + |
94 | 125 | <target name="test-run" depends="test-compile"> |
95 | | - <property name="junit-reports" value="junit-reports" /> |
96 | | - <property name="code-coverage-reports" value="code-coverage-reports" /> |
97 | | - <mkdir dir="${junit-reports}" /> |
98 | | - <mkdir dir="${code-coverage-reports}" /> |
99 | | - |
100 | | - <jacoco:coverage destfile="${code-coverage-reports}/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant" exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" > |
101 | | - <junit haltonfailure="false" failureproperty="test.failed" errorproperty="test.failed" fork="true" forkmode="once"> |
102 | | - <jvmarg value="-Xms128m" /> |
103 | | - <jvmarg value="-Xmx2048m" /> |
104 | | - <!-- https://stackoverflow.com/questions/54205486 --> |
105 | | - <jvmarg value="-Xshare:off" /> |
106 | | - <classpath> |
107 | | - <path refid="testclasspath" /> |
108 | | - <dirset dir="${test_classes}"/> |
109 | | - </classpath> |
110 | | - <formatter type="xml" /> |
111 | | - <batchtest todir="${junit-reports}"> |
112 | | - <fileset dir="${test_classes}"> |
113 | | - <include name="**/*Test.class" /> |
114 | | - </fileset> |
115 | | - </batchtest> |
116 | | - </junit> |
117 | | - </jacoco:coverage> |
118 | | - |
119 | | - <fail if="test.failed" message="Unit tests failed. Check reports for details."/> |
| 126 | + <description>Run unit tests. Coverage is only enabled if 'jacoco.agent.arg' is set.</description> |
| 127 | + |
| 128 | + <delete dir="${test.results.dir}" /> |
| 129 | + <delete dir="${reports.tests.dir}" /> |
| 130 | + <mkdir dir="${test.results.dir}" /> |
| 131 | + <mkdir dir="${reports.tests.dir}" /> |
| 132 | + |
| 133 | + <junit haltonfailure="false" |
| 134 | + failureproperty="test.failed" |
| 135 | + errorproperty="test.failed" |
| 136 | + fork="true" |
| 137 | + forkmode="once"> |
| 138 | + |
| 139 | + <jvmarg value="-Xms128m" /> |
| 140 | + <jvmarg value="-Xmx2048m" /> |
| 141 | + <!-- https://stackoverflow.com/questions/54205486 --> |
| 142 | + <jvmarg value="-Xshare:off" /> |
| 143 | + <jvmarg line="${jacoco.agent.arg}" if:set="jacoco.agent.arg" /> |
| 144 | + |
| 145 | + <classpath> |
| 146 | + <path refid="testclasspath" /> |
| 147 | + <dirset dir="${test_classes}"/> |
| 148 | + </classpath> |
| 149 | + |
| 150 | + <formatter type="xml" /> |
| 151 | + |
| 152 | + <batchtest todir="${test.results.dir}"> |
| 153 | + <fileset dir="${test_classes}"> |
| 154 | + <include name="**/*Test.class" /> |
| 155 | + </fileset> |
| 156 | + </batchtest> |
| 157 | + </junit> |
| 158 | + |
| 159 | + <!-- Generate HTML report from JUnit XML output --> |
| 160 | + <junitreport todir="${test.results.dir}"> |
| 161 | + <fileset dir="${test.results.dir}"> |
| 162 | + <include name="TEST-*.xml"/> |
| 163 | + </fileset> |
| 164 | + <report format="frames" todir="${reports.tests.dir}" /> |
| 165 | + </junitreport> |
| 166 | + |
| 167 | + <fail if="test.failed" message="Unit tests failed. For details, check reports in ${reports.tests.dir}."/> |
120 | 168 | </target> |
121 | 169 | </project> |
0 commit comments