source: branches/cleanup/components/java.xml @ 5817

Revision 5817, 8.2 KB checked in by melissa, 10 years ago (diff)

Added root 'test' target and modified component 'test' targets to succeed if no tests are present.

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