source: trunk/ant/java.xml @ 6982

Revision 6982, 9.6 KB checked in by melissa, 9 years ago (diff)

Tweaked component.runtime-cp for the ome-xml component and updated the default 'test' target to include 'component.runtime-cp' in the TestNG classpath. See #566.

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