source: trunk/ant/java.xml @ 6583

Revision 6583, 8.6 KB checked in by curtis, 9 years ago (diff)

Populate version information from Git, where applicable.

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