source: trunk/ant/java.xml @ 6686

Revision 6686, 9.5 KB checked in by curtis, 9 years ago (diff)

Fix up test targets in Ant build scripts.

Line 
1<!--
2java.xml
3
4Ant build file for logic common to Java-based components.
5All Java-based component build files inherit from this build file.
6Download Apache Ant from http://ant.apache.org/.
7Type "ant -p" for a list of targets.
8-->
9
10<project>
11  <property file="${root.dir}/ant/java.properties"/>
12  <import file="${root.dir}/ant/common.xml"/>
13
14  <taskdef name="testng" classpath="${testng.jar}"
15    classname="org.testng.TestNGAntTask"/>
16  <condition property="doTests">
17    <available file="${tests.dir}"/>
18  </condition>
19
20  <!-- Main build targets -->
21
22  <target name="compile" depends="copy-source" description="compile classes">
23    <javac debug="true" deprecation="${component.deprecation}"
24      source="${component.java-version}"
25      target="${component.java-version}"
26      srcdir="${dest.dir}" destdir="${classes.dir}"
27      classpath="${component.classpath}"
28      includes="${component.source}">
29      <!--<compilerarg value="-Xlint:unchecked"/>-->
30    </javac>
31  </target>
32
33  <target name="compile-tests" depends="compile, copy-test-source"
34    description="compile test classes" if="doTests">
35    <javac debug="true" deprecation="${component.deprecation}"
36      source="${component.java-version}"
37      target="${component.java-version}"
38      srcdir="${test.dir}" destdir="${test-classes.dir}"
39      classpath="${classes.dir}:${component.classpath}"
40      includes="${component.source}"/>
41  </target>
42
43  <target name="exec" depends="compile" description="execute package">
44    <java fork="true" classname="${component.main-class}"
45      classpath="${classes.dir}:${component.runtime-cp}"/>
46  </target>
47
48  <target name="test" depends="jar, compile-tests"
49    description="run tests" if="doTests">
50    <!-- run JUnit tests -->
51    <if>
52      <equals arg1="${component.junit}" arg2="true"/>
53      <then>
54        <junit haltonfailure="true">
55          <classpath>
56            <pathelement location="${artifact.dir}/junit-4.8.2.jar"/>
57            <pathelement location="${test-classes.dir}"/>
58            <pathelement location="${classes.dir}"/>
59            <pathelement path="${component.runtime-cp}"/>
60          </classpath>
61          <formatter type="brief" usefile="false"/>
62          <batchtest>
63            <fileset dir="${test-classes.dir}">
64              <include name="**/*Test.class"/>
65            </fileset>
66          </batchtest>
67        </junit>
68      </then>
69    </if>
70    <!-- run TestNG tests -->
71    <if>
72      <isset property="testng.xml"/>
73      <then>
74        <testng haltonfailure="true" groups="all" testname="${component.name}">
75          <classpath>
76            <pathelement path="${component.classpath}"/>
77            <pathelement location="${test-classes.dir}"/>
78            <pathelement location="${classes.dir}"/>
79          </classpath>
80          <xmlfileset file="${testng.xml}"/>
81          <jvmarg value="-mx${testng.memory}"/>
82        </testng>
83      </then>
84    </if>
85  </target>
86
87  <target name="findbugs" depends="jar"
88    description="check source code for bugs">
89    <if>
90      <isset property="findbugs.home"/>
91      <then>
92        <findbugs home="${findbugs.home}" jvmargs="-Xmx512m"
93          output="xml:withMessages" outputFile="${build.dir}/findbugs.xml"
94          excludeFilter="${root.dir}/excludebugs.xml" reportLevel="high">
95          <auxClasspath path="${component.classpath}"/>
96          <sourcePath path="${dest.dir}"/>
97          <class location="${classes.dir}"/>
98        </findbugs>
99      </then>
100      <else>
101<echo>
102Please set the findbugs.home property to point to
103your FindBugs installation's lib directory. E.g.:
104  ant -Dfindbugs.home=${user.home}/findbugs/lib findbugs
105</echo>
106        <fail message="FindBugs not found."/>
107      </else>
108    </if>
109  </target>
110
111  <target name="style" depends="compile"
112    description="check source code style">
113    <checkstyle config="${root.dir}/checkstyle.xml" failOnViolation="false"
114      classpath="${classes.dir}:${component.classpath}">
115      <fileset dir="${dest.dir}" includes="${component.source}"/>
116    </checkstyle>
117  </target>
118
119  <target name="jar" depends="compile"
120    description="generate JAR file">
121    <mkdir dir="${artifact.dir}"/>
122    <jar jarfile="${artifact.dir}/${component.jar}" basedir="${classes.dir}">
123      <manifest>
124        <attribute name="Main-Class" value="${component.main-class}"/>
125        <attribute name="Class-Path" value="${component.manifest-cp}"/>
126      </manifest>
127    </jar>
128  </target>
129
130  <target name="osgi" depends="jar"
131    description="inject OSGi bundle information">
132    <!-- NB: Add OSGi bundle metadata. -->
133    <bundle outputDir="${artifact.dir}"
134      bundleName="${component.name}"
135      bundleSymbolicName="${domain.prefix}.${component.name}"
136      bundleVersion="${component.version}.${svn.revision}"
137      classpath="${classes.dir}"
138      exportPackage="*;version=&quot;${component.version}&quot;"
139      filename="${component.name}">
140      <manifest>
141        <attribute name="Main-Class" value="${component.main-class}"/>
142        <attribute name="Class-Path" value="${component.manifest-cp}"/>
143      </manifest>
144    </bundle>
145  </target>
146
147  <target name="utils" depends="jar"
148    description="compile extra utilities">
149    <delete>
150      <fileset dir="${utils.dir}" includes="*.class"/>
151    </delete>
152    <javac debug="true" deprecation="true" source="1.5" target="1.5"
153      srcdir="${utils.dir}" includes="*.java"
154      classpath="${artifact.dir}/${component.jar}">
155      <!--<compilerarg value="-Xlint:unchecked"/>-->
156    </javac>
157  </target>
158
159  <target name="docs" depends="compile"
160    description="generate javadocs">
161    <javadoc sourcepath="${dest.dir}" destdir="${docs.dir}/api"
162      classpath="${component.classpath}:${classes.dir}"
163      author="true" version="true" use="true"
164      nodeprecated="true" windowtitle="Bio-Formats API">
165      <packageset dir="${dest.dir}"/>
166      <doctitle><![CDATA[<h1>Bio-Formats</h1>]]></doctitle>
167      <bottom><![CDATA[${copyright.begin} ${YEAR} ${copyright.end}]]></bottom>
168      <link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
169      <link href="http://hudson.openmicroscopy.org.uk/job/OMEJAVA/javadoc/"/>
170      <link href="http://rsbweb.nih.gov/ij/developer/api/"/>
171      <link href="http://www.ssec.wisc.edu/visad-docs/javadoc/"/>
172      <!--<link href="http://www.jdocs.com/formlayout/1.0.4/api/"/>-->
173      <!--<link href="http://www.jdocs.com/looks/1.2.2/api/"/>-->
174    </javadoc>
175  </target>
176
177  <target name="clean-classes" description="remove classes from build folder">
178    <delete dir="${classes.dir}"/>
179  </target>
180
181  <target name="clean-dist"
182    description="remove distribution bundles from build folder">
183    <delete dir="${dist.dir}"/>
184  </target>
185
186  <target name="clean-docs" description="remove javadocs from build folder">
187    <delete dir="${docs.dir}"/>
188  </target>
189
190  <target name="clean-src" description="remove source files from build folder">
191    <delete dir="${dest.dir}"/>
192  </target>
193
194  <target name="clean-jar" description="remove JAR file from artifacts folder">
195    <delete>
196      <fileset dir="${artifact.dir}" includes="${component.jar}"/>
197    </delete>
198  </target>
199
200  <!-- Internal build targets -->
201
202  <target name="init"
203    depends="init-title, init-timestamp, init-version, init-manifest-cp"/>
204
205  <target name="init-manifest-cp">
206    <!-- construct manifest classpath -->
207    <propertyregex property="component.manifest-cp-temp"
208      input="${component.runtime-cp}" replace=""
209      defaultValue="${component.runtime-cp}">
210      <regexp pattern="[^\:]*\/"/>
211    </propertyregex>
212    <propertyregex property="component.manifest-cp"
213      input="${component.manifest-cp-temp}" replace=" "
214      defaultValue="${component.manifest-cp-temp}">
215      <regexp pattern=":"/>
216    </propertyregex>
217    <!--<echo>Manifest-Classpath: ${component.manifest-cp}</echo>-->
218  </target>
219
220  <target name="copy-source" depends="init">
221    <!-- copy binary resources -->
222    <copy todir="${dest.dir}" preservelastmodified="true">
223      <!--
224        include (none) to prevent problems if component.resources-bin is empty
225      -->
226      <fileset dir="${src.dir}" includes="(none) ${component.resources-bin}"/>
227    </copy>
228    <!-- copy source files and text resources with filtering -->
229    <copy todir="${dest.dir}" preservelastmodified="true">
230      <fileset dir="${src.dir}"
231        includes="${component.source} ${component.resources-text}"/>
232      <filterset>
233        <filter token="date" value="${DATE}"/>
234        <filter token="year" value="${YEAR}"/>
235        <filter token="svn.revision" value="${svn.revision}"/>
236        <filter token="svn.url" value="${svn.url}"/>
237        <filter token="svn.root" value="${svn.root}"/>
238        <filter token="svn.date" value="${svn.date}"/>
239        <filter token="svn.changed" value="${svn.changed}"/>
240        <filter token="release.version" value="${release.version}"/>
241        <filter token="visbio.version" value="${visbio.version}"/>
242      </filterset>
243    </copy>
244    <!-- copy resources to classes folder -->
245    <copy todir="${classes.dir}" preservelastmodified="true">
246      <fileset dir="${dest.dir}" excludes="${component.source}"/>
247    </copy>
248  </target>
249
250  <target name="copy-test-source" depends="init" if="doTests">
251    <copy todir="${test.dir}" preservelastmodified="true">
252      <fileset dir="${tests.dir}" includes="(none) ${component.resources-bin}"/>
253    </copy>
254
255    <copy todir="${test.dir}" preservelastmodified="true">
256      <fileset dir="${tests.dir}" includes="${component.source} ${component.resources-text}"/>
257    </copy>
258
259    <mkdir dir="${test-classes.dir}"/>
260    <copy todir="${test-classes.dir}" preservelastmodified="true">
261      <fileset dir="${tests.dir}" excludes="${component.source}"/>
262    </copy>
263  </target>
264
265</project>
Note: See TracBrowser for help on using the repository browser.