Skip to content

Commit 0c8ca81

Browse files
committed
build.xml: add targets to compile + run the tests
1 parent c576533 commit 0c8ca81

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

build.xml

+51-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
<property name="build.dir" value="build" />
66
<property name="jarfile" value="ij.jar" />
77
<property name="javadoc.dir" value="../api" />
8+
<property name="repository" value="https://maven.scijava.org/content/groups/public" />
9+
<property name="src-tests.dir" value="tests" />
10+
<property name="build-tests.dir" value="${build.dir}/tests" />
11+
<property name="build-tests-lib.dir" value="${build.dir}/tests/lib" />
812

9-
10-
<target name="compile" description="Compile everything.">
13+
<target name="compile" description="Compile the source code.">
1114
<!-- First, ensure the build directory exists. -->
1215
<mkdir dir="${build.dir}" />
1316
<!-- Build everything; add debug="on" to debug -->
@@ -26,7 +29,8 @@
2629
<copy todir="${build.dir}/macros"><fileset dir="macros"/></copy>
2730
<!-- Build ij.jar. -->
2831
<jar jarfile="${jarfile}" basedir="${build.dir}"
29-
manifest="MANIFEST.MF" />
32+
manifest="MANIFEST.MF"
33+
excludes="${src-tests.dir}" />
3034
</target>
3135

3236

@@ -74,4 +78,48 @@
7478
</target>
7579

7680

81+
<target name="compile-tests" depends="compile" description="Compile the unit tests.">
82+
<!-- First, ensure needed build directories exist. -->
83+
<mkdir dir="${build-tests.dir}" />
84+
<mkdir dir="${build-tests-lib.dir}" />
85+
<!-- Download dependencies needed for the unit tests. -->
86+
<get src="${repository}/junit/junit/4.13.2/junit-4.13.2.jar"
87+
dest="${build-tests-lib.dir}" skipexisting="true" />
88+
<get src="${repository}/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar"
89+
dest="${build-tests-lib.dir}" skipexisting="true" />
90+
<get src="${repository}/ome/formats-api/6.9.0/formats-api-6.9.0.jar"
91+
dest="${build-tests-lib.dir}" skipexisting="true" />
92+
<get src="${repository}/ome/formats-bsd/6.9.0/formats-bsd-6.9.0.jar"
93+
dest="${build-tests-lib.dir}" skipexisting="true" />
94+
<!-- Build the unit tests in debug mode. -->
95+
<path id="compile-tests.classpath">
96+
<pathelement location="${build.dir}" />
97+
<fileset dir="${build-tests-lib.dir}" includes="*.jar" />
98+
</path>
99+
<javac srcdir="${src-tests.dir}" destdir="${build-tests.dir}" classpathref="compile-tests.classpath"
100+
optimize="on" source="1.8" target="1.8" debug="on" includeantruntime="false" encoding="utf-8"
101+
excludes="data/**" />
102+
</target>
103+
104+
105+
<target name="run-tests" depends="compile-tests" description="Run the unit tests.">
106+
<path id="run-tests.classpath">
107+
<pathelement location="${build.dir}" />
108+
<pathelement location="${build-tests.dir}" />
109+
<fileset dir="${build-tests-lib.dir}" includes="*.jar" />
110+
</path>
111+
<!-- Construct a list of test classes to run. -->
112+
<path id="test-files">
113+
<fileset dir="${src-tests.dir}" includes="**/*Test.java" />
114+
</path>
115+
<pathconvert dirsep="." pathsep=" " property="test-classes" refid="test-files">
116+
<regexpmapper from="^.*/tests/(.*)\.java$$" to="\1" />
117+
</pathconvert>
118+
<!-- Run all the test classes. -->
119+
<java classname="org.junit.runner.JUnitCore" classpathref="run-tests.classpath" fork="yes">
120+
<arg line="${test-classes}" />
121+
</java>
122+
</target>
123+
124+
77125
</project>

0 commit comments

Comments
 (0)