dbc639b395c63487a0e3d41b827b50915eeef5ca
[beast.git] / build.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 Copyright (C) 2009-2010 Swedish Meteorological and Hydrological Institute, SMHI,
4
5 This file is part of the Beast library.
6
7 Beast library is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Beast library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the Beast library library.  If not, see http://www.gnu.org/licenses.
19 /opt/testbuilds/baltrad-db/baltrad/db-devel
20
21 -->
22 <project name="beast" default="build" basedir=".">
23   <property file="build.properties" />
24
25   <property name="app.name" value="beast" />
26   <property name="app.version" value="0.1-dev" />
27   <property name="app.root.dir" value="${basedir}" />
28   <property name="build.dir" value="${basedir}/build" />
29   <property name="build.classes.dir" value="${build.dir}/classes" />
30   <property name="build.test.dir" value="${build.dir}/test" />
31   <property name="build.itest.dir" value="${build.dir}/itest" />
32   <property name="build.coverage.dir" value="${build.dir}/coverage" />
33   <property name="build.instrument.dir" value="${build.dir}/instrument" />
34   <property name="dist.dir" value="${basedir}/dist" />
35   <property name="source.dir" value="${basedir}/src" />
36   <property name="lib.dir" value="${basedir}/lib" />    
37   <property name="etc.dir" value="${basedir}/etc" />
38   <property name="examples.dir" value="${basedir}/examples" />
39   <property name="compile.debug" value="true" />
40   <property name="compile.optimize" value="true" />
41   <property name="compile.includeAntRuntime" value="no" />
42
43   <property file="develop.properties" />
44   <property name="prefix" value="/opt/baltrad" />
45
46   <property file="${etc.dir}/testdb.properties" />
47
48   <!-- override this with -Dbaltraddb.path= -->
49   <property name="baltraddb.path" value="/opt/baltrad/db-devel"/>
50   <property name="baltraddb.bin.path" value="${baltraddb.path}/bin"/>
51
52         <available file="${baltraddb.path}" type="dir" property="baltraddb.available"/>
53   <available file="${baltraddb.path}/share/baltrad-bdb/java/baltrad-bdb-client.jar" property="baltrad-bdb-client.jar.available"/>
54   <available file="${baltraddb.bin.path}/baltrad-bdb-server" property="baltrad-bdb-server.available"/>
55   <fail unless="baltrad-bdb-client.jar.available" message="Can not find baltrad-bdb-client.jar!" />
56   <fail unless="baltrad-bdb-server.available" message="Can not find baltrad-bdb-server executable" />
57   <fail unless="blt.db.path" message="No storage root path defined (blt.db.path)!"/>
58
59   <path id="lib.path">
60     <fileset dir="${lib.dir}">
61       <include name="**/*.jar"/>
62       <exclude name="ant/*.jar" />
63       <exclude name="junit/*.jar"/>
64       <exclude name="easymock/*.jar"/>
65       <exclude name="emma/*.jar"/>
66       <exclude name="cglib/*.jar"/>
67     </fileset>
68     <fileset dir="${baltraddb.path}/share/baltrad-bdb/java/">
69       <include name="baltrad-bdb-client.jar"/>
70     </fileset>
71     <fileset dir="${baltraddb.path}/share/baltrad-bdb/java/">
72       <include name="libs/*.jar"/>
73     </fileset>
74   </path>
75
76   <path id="test.lib.path">
77     <fileset dir="${lib.dir}">
78       <include name="junit/*.jar"/>
79       <include name="ant-junit/*.jar"/>
80       <include name="easymock/*.jar"/>
81       <include name="cglib/*.jar"/>
82     </fileset>
83   </path>
84
85   <path id="doxygen.classpath">
86     <fileset dir="${lib.dir}/doxygen">
87       <include name="*.jar"/>
88     </fileset>
89   </path>
90
91   <path id="emma.classpath" >
92     <pathelement location="${lib.dir}/emma/emma.jar" />
93     <pathelement location="${lib.dir}/emma/emma_ant.jar" />
94   </path>
95
96   <taskdef resource="emma_ant.properties" classpathref="emma.classpath" />
97
98   <!-- Generates the deliverables -->
99   <target name="build" depends="clean,compile">
100     <mkdir dir="${dist.dir}" />
101     <jar jarfile="${dist.dir}/${app.name}.jar"
102          basedir="${build.classes.dir}">
103     </jar>
104   </target>
105
106   <!-- same as running build and execute.test -->
107   <target name="distribution" depends="build, execute.test" />
108
109   <target name="-install-files">
110         <mkdir dir="${prefix}/beast" />
111         <mkdir dir="${prefix}/beast/sql" />
112         <mkdir dir="${prefix}/beast/bin" />
113         <mkdir dir="${prefix}/beast/etc" />
114         <mkdir dir="${prefix}/beast/libs" />
115         <mkdir dir="${prefix}/beast/plugins" />
116         <mkdir dir="${prefix}/beast/examples" />
117         <copy todir="${prefix}/beast/sql">
118           <fileset dir="${etc.dir}">
119                 <include name="drop_db.sql" />
120                 <include name="create_db.sql" />
121                 <include name="upgrade_db.sql" />
122           </fileset>
123         </copy>
124         <copy todir="${prefix}/beast/libs" flatten="true">
125       <fileset dir="${lib.dir}">
126         <include name="**/*.jar"/>
127         <exclude name="ant/*.jar" />
128         <exclude name="junit/*.jar"/>
129         <exclude name="easymock/*.jar"/>
130         <exclude name="emma/*.jar"/>
131         <exclude name="poi/*.jar"/>
132         <exclude name="dbunit/*.jar"/>
133         <exclude name="spring/spring-test.jar"/>
134       </fileset>
135         </copy>
136         <copy todir="${prefix}/beast/etc">
137       <fileset dir="${etc.dir}">
138         <include name="xmlrpcserver-context.xml" />
139         <include name="build-plugin.xml" />
140         <include name="log4j.properties" />
141         <include name="xmlrpcserver.properties" />
142         <include name="beast-log-messages.xml" />
143         <include name="odim_quantities.xml" />
144       </fileset>
145         </copy>
146         <copy todir="${prefix}/beast/examples">
147           <fileset dir="${examples.dir}">
148             <include name="*.groovy" />
149             <include name="*.xml" />
150           </fileset>
151         </copy>
152         <!-- remove old beast.jar that contained version information -->
153         <delete file="${prefix}/beast/bin/${app.name}-0.1-dev.jar" failonerror="false"/>
154         <delete file="${prefix}/beast/libs/commons-io-2.1.jar" failonerror="false"/> <!-- If 2.1 installed, remove it -->
155         <delete file="${prefix}/beast/libs/sshj-0.3.1.jar" failonerror="false"/>
156         <delete file="${prefix}/beast/libs/sshj-0.8.1.jar" failonerror="false"/>
157         <delete file="${prefix}/beast/libs/bcprov-jdk16-146.jar" failonerror="false"/>
158         
159         <delete file="${prefix}/beast/libs/spring.jar" failonerror="false"/>
160         <delete file="${prefix}/beast/libs/spring-webmvc.jar" failonerror="false"/>
161         <delete file="${prefix}/beast/libs/quartz-1.8.3.jar" failonerror="false"/>
162         
163         <copy file="${dist.dir}/${app.name}.jar" todir="${prefix}/beast/bin" />
164         <copy file="${etc.dir}/xmlrpcserver" todir="${prefix}/beast/bin" />
165     <chmod file="${prefix}/beast/bin/xmlrpcserver" perm="755"/>
166         <copy file="${etc.dir}/pgfwkplugin" todir="${prefix}/beast/bin" />
167     <chmod file="${prefix}/beast/bin/pgfwkplugin" perm="755"/>
168   </target>
169
170   <target name="-install-doc-files">
171         <mkdir dir="${prefix}/beast" />
172         <mkdir dir="${prefix}/beast/doc" />
173         <mkdir dir="${prefix}/beast/doc/doxygen" />
174         <mkdir dir="${prefix}/beast/doc/javadoc" />
175         <copy todir="${prefix}/beast/doc/doxygen">
176       <fileset dir="${dist.dir}/doxygen/html">
177         <include name="**/*.*" />
178       </fileset>
179         </copy>
180     <copy todir="${prefix}/beast/doc/javadoc">
181       <fileset dir="${dist.dir}/javadoc">
182         <include name="**/*.*" />
183       </fileset>
184     </copy>
185   </target>
186         
187   <target name="install" depends="distribution, -install-files" />
188         
189   <target name="install-doc" depends="doc, -install-doc-files" />
190
191   <!-- This is the overall build script that can be used to get a full build & test sequence --> 
192   <target name="hudson" depends="build,test.coverage" />
193
194   <target name="hudson-install" depends="build,test.coverage,-install-files" />
195
196   <target name="itest" depends="build,execute.itest" />
197   <target name="test" depends="build,execute.test" />
198         
199   <!-- Compile the code -->
200   <target name="compile" depends="prepare">
201     <mkdir dir="${build.classes.dir}"/>
202     <javac srcdir="${source.dir}"
203            encoding="8859_1"
204            deprecation="on"
205            debug="${compile.debug}"
206            includeAntRuntime="${compile.includeAntRuntime}"
207            optimize="${compile.optimize}"
208            destdir="${build.classes.dir}">
209       <classpath refid="lib.path"/>
210     </javac>
211   </target>
212
213   <!-- UNIT TEST PART -->
214   <target name="compile.test">
215     <mkdir dir="${build.test.dir}"/>
216     <javac srcdir="${app.root.dir}/test"
217            encoding="8859_1"
218            deprecation="on"
219            debug="${compile.debug}"
220            includeAntRuntime="${compile.includeAntRuntime}"     
221            optimize="${compile.optimize}"
222            destdir="${build.test.dir}">
223         <classpath location="${build.classes.dir}"/>
224       <classpath refid="lib.path"/>
225       <classpath refid="test.lib.path"/>
226     </javac>
227         
228     <!-- copy any resources -->
229     <copy todir="${build.test.dir}">
230       <fileset dir="${app.root.dir}/test">
231         <include name="**/*.xml"/>
232         <include name="**/*.properties"/>
233         <include name="**/*.groovy"/>
234         <include name="**/test-key.priv/*"/>
235       </fileset>
236     </copy>
237   </target>
238
239   <target name="prepare.test" depends="compile.test">
240     <mkdir dir="${dist.dir}/junit-reports" />
241   </target>     
242         
243   <target name="execute.test" depends="prepare.test">
244         <mkdir dir="${dist.dir}/junit-reports" />
245         <junit dir="${build.test.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
246           <jvmarg line="-Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
247           <formatter type="xml"/> 
248           <formatter type="brief" usefile="false" if="test.format.brief" />
249           <classpath refid="test.lib.path"/>
250           <classpath location="${build.classes.dir}"/>
251           <classpath refid="lib.path"/>
252           <classpath location="${build.test.dir}" />
253           <batchtest fork="yes" todir="${dist.dir}/junit-reports">
254             <fileset dir="${build.test.dir}" includes="**/*Test.class" excludes="**/HDF5*.class"/>
255           </batchtest>
256         </junit>
257   </target>
258
259   <!-- INTEGRATION TEST PART -->
260   <target name="compile.itest">
261     <mkdir dir="${build.itest.dir}"/>
262     <javac srcdir="${app.root.dir}/itest"
263            encoding="8859_1"
264            deprecation="on"
265            debug="${compile.debug}"
266            includeAntRuntime="${compile.includeAntRuntime}"     
267            optimize="${compile.optimize}"
268            destdir="${build.itest.dir}">
269       <classpath location="${build.classes.dir}"/>
270       <classpath refid="lib.path"/>
271       <classpath refid="test.lib.path"/>
272     </javac>
273
274     <!-- copy any resources -->
275     <copy todir="${build.itest.dir}">
276       <fileset dir="${app.root.dir}/itest">
277         <include name="**/*.xml"/>
278         <include name="**/*.xls"/>
279         <include name="**/*.properties"/>
280         <include name="**/*.groovy"/>
281         <include name="**/*.h5"/>
282       </fileset>
283     </copy>
284   </target>     
285
286   <!-- prepares the setup so that it is possible to run the junit integration tests -->
287   <target name="prepare.itest" depends="create-testdb, extras-testdb, compile.itest">
288         <mkdir dir="${dist.dir}/junit-reports" />
289         <copy file="${etc.dir}/testdb.properties" todir="${build.classes.dir}"/>
290   </target>
291
292   <target name="create-testdb">
293         <sql classpath="${lib.dir}/${db.jar}"
294              driver="${db.driver}"
295              url="${db.url}"
296              userid="${db.user}" 
297              password="${db.pwd}">
298           <transaction src="${etc.dir}/drop_db.sql"/>
299           <transaction src="${etc.dir}/create_db.sql"/>
300         </sql>
301   </target>
302
303   <target name="extras-testdb">
304         <sql classpath="${lib.dir}/${db.jar}"
305              driver="${db.driver}"
306              url="${db.url}"
307              userid="${db.user}" 
308              password="${db.pwd}"
309                  escapeprocessing="false"
310                  expandproperties="false"
311                  delimitertype="row">
312           <transaction src="${etc.dir}/extras_testdb.sql"/>
313         </sql>
314   </target>
315
316   <target name="start-baltrad-bdb-server">
317     <exec executable="${baltraddb.bin.path}/baltrad-bdb-drop"
318           failonerror="true">
319       <arg value="--conf=${etc.dir}/testdb.properties"/>
320     </exec>
321     <exec executable="${baltraddb.bin.path}/baltrad-bdb-create"
322           failonerror="true">
323       <arg value="--conf=${etc.dir}/testdb.properties"/>
324     </exec>
325     <exec executable="${baltraddb.bin.path}/baltrad-bdb-server"
326           failonerror="true">
327       <arg value="--conf=${etc.dir}/testdb.properties"/>
328       <arg value="--pidfile=${build.dir}/baltrad-bdb-server.pid"/>
329       <arg value="--logfile=${build.dir}/baltrad-bdb-server.log"/>
330     </exec>
331         <sleep seconds="2"/>
332     <exec executable="${baltraddb.bin.path}/baltrad-bdb-client"
333           failonerror="true">
334       <arg value="import_sources"/>
335       <arg value="--url=${blt.db.uri}"/>
336       <arg value="${basedir}/etc/itest_sources.xml"/>
337     </exec>
338   </target>
339
340
341   <target name="stop-baltrad-bdb-server">
342     <exec executable="cat" outputproperty="baltraddb.server.pid">
343       <arg value="${build.dir}/baltrad-bdb-server.pid"/>
344     </exec>
345     <exec executable="kill">
346       <arg value="${baltraddb.server.pid}"/>
347     </exec>
348   </target>
349         
350   <target name="execute.itest" depends="prepare.itest,start-baltrad-bdb-server">
351     <junit dir="${build.itest.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
352       <jvmarg line="-Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
353       <formatter type="xml"/> 
354       <formatter type="brief" usefile="false" if="test.format.brief" />
355       <classpath refid="test.lib.path"/>
356       <classpath location="${build.classes.dir}"/>
357       <classpath refid="lib.path"/>
358       <classpath location="${build.itest.dir}" />
359       <batchtest fork="yes" todir="${dist.dir}/junit-reports">
360         <fileset dir="${build.itest.dir}" includes="**/*Test.class"
361                  excludes="eu/baltrad/beast/net/FileDistributionITest.class"/>
362         <!--
363         <fileset dir="${build.itest.dir}" includes="**/VolumeRuleManagerITest.class"
364                  excludes="eu/baltrad/beast/net/FileDistributionITest.class"/>
365         -->         
366       </batchtest>
367     </junit>
368     <antcall target="stop-baltrad-bdb-server" />
369   </target>
370
371   <!-- target that can be used to manually test FileDistribution -->
372   <target name="execute.itest.filedistribution" depends="compile.itest">
373     <java classname="eu.baltrad.beast.net.FileDistributionITest" fork="true">
374       <arg value="${itest.filedistribution.src}"/>
375       <arg value="${itest.filedistribution.dst}"/>
376       <arg value="${itest.filedistribution.entry}"/>
377       <classpath refid="test.lib.path"/>
378       <classpath location="${build.classes.dir}"/>
379       <classpath refid="lib.path"/>
380       <classpath location="${build.itest.dir}" />
381     </java>
382   </target>
383
384   <!-- CODE COVERAGE -->
385   <target name="instrument.coverage">
386     <delete dir="${build.instrument.dir}" />
387     <delete file="${build.coverage.dir}/coverage.ec" />
388     <delete file="${build.coverage.dir}/metadata.emma" />
389     <mkdir dir="${build.instrument.dir}" />
390     <mkdir dir="${build.coverage.dir}" />
391
392         <emma enabled="true">
393       <instr instrpath="${build.classes.dir}/"
394              destdir="${build.instrument.dir}/" 
395              metadatafile="${build.coverage.dir}/metadata.emma"
396              merge="true"/>
397     </emma>
398   </target>
399   
400   <target name="unittest.coverage" depends="instrument.coverage">
401     <mkdir dir="${dist.dir}/coverage-reports" />
402     <junit dir="${build.test.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
403       <jvmarg line="-d64 -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
404       <sysproperty key="emma.coverage.out.file" file="${build.coverage.dir}/coverage.ec" /> <!-- So I know where ec file is placed -->
405       <formatter type="xml"/> 
406       <classpath location="${build.instrument.dir}" /> <!-- For instrumentation -->
407       <classpath refid="test.lib.path"/>
408       <classpath location="${build.classes.dir}"/>
409       <classpath refid="lib.path"/>
410       <classpath location="${build.test.dir}" />
411       <classpath refid="emma.classpath" />
412         
413       <batchtest fork="yes" todir="${dist.dir}/junit-reports">
414         <fileset dir="${build.test.dir}" includes="**/*Test.class"/>
415       </batchtest>
416     </junit>
417
418         <emma enabled="true">
419       <report sourcepath="${source.dir}" >
420         <fileset dir="${build.coverage.dir}" >
421           <include name="*.emma" />
422           <include name="*.ec" />
423         </fileset>
424         <xml outfile="${dist.dir}/coverage-reports/coverage.xml" depth="method"/>
425       </report>
426     </emma>
427   </target>
428
429   <!-- performs coverage from running all tests (unit tests, integration tests-->
430   <target name="test.coverage" depends="prepare.test,prepare.itest,instrument.coverage,start-baltrad-bdb-server">
431     <mkdir dir="${dist.dir}/junit-reports" />
432     <mkdir dir="${dist.dir}/coverage-reports" />
433
434         <junit dir="${build.test.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
435       <jvmarg line="-d64 -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
436       <sysproperty key="emma.coverage.out.file" file="${build.coverage.dir}/coverage.ec" /> <!-- So I know where ec file is placed -->
437       <formatter type="xml"/> 
438       <classpath location="${build.instrument.dir}" /> <!-- For instrumentation -->
439       <classpath refid="test.lib.path"/>
440       <classpath location="${build.classes.dir}"/>
441       <classpath refid="lib.path"/>
442       <classpath location="${build.test.dir}" />
443       <classpath location="${build.itest.dir}" />
444       <classpath refid="emma.classpath" />
445         
446       <batchtest fork="true" todir="${dist.dir}/junit-reports">
447         <fileset dir="${build.test.dir}" includes="**/*Test.class"/>
448         <fileset dir="${build.itest.dir}" includes="**/*Test.class"
449                  excludes="eu/baltrad/beast/net/FileDistributionITest.class"/>
450       </batchtest>
451     </junit>
452
453     <antcall target="stop-baltrad-bdb-server" />
454
455         <emma enabled="true">
456       <report sourcepath="${source.dir}" >
457         <fileset dir="${build.coverage.dir}" >
458           <include name="*.emma" />
459           <include name="*.ec" />
460         </fileset>
461         <xml outfile="${dist.dir}/coverage-reports/coverage.xml" depth="method"/>
462       </report>
463     </emma>
464   </target>
465         
466   <!-- clean directories for building -->
467   <target name="clean">
468     <delete dir="${build.dir}" />
469     <delete dir="${dist.dir}" />
470   </target>
471         
472   <!-- Prepare for compilation and jar-generation, copy files -->
473   <target name="prepare">
474     <mkdir dir="${build.dir}" />
475     <mkdir dir="${build.classes.dir}" />
476     <mkdir dir="${build.test.dir}" />
477
478         <!-- Copy misc extra files that resides in the src into classes -->
479     <copy todir="${build.classes.dir}" preservelastmodified="true">
480       <fileset dir="${source.dir}">
481         <include name="**/*.properties"/>
482         <include name="**/*.handlers"/>
483         <include name="**/*.schemas"/>
484         <include name="**/*.xml"/>
485         <include name="**/*.dtd"/>
486         <include name="**/*.xsd"/>
487         <include name="**/*.vm"/>
488         <include name="**/*.ftl"/>
489         <include name="**/*.types"/>
490       </fileset>
491     </copy>
492         <mkdir dir="${blt.db.path}" />
493   </target>
494         
495   <target name="doc" description="Generates doxygen">
496     <taskdef name="doxygen" classname="org.doxygen.tools.DoxygenTask" classpathref="doxygen.classpath" />
497         <mkdir dir="${dist.dir}/doxygen" />
498         <mkdir dir="${dist.dir}/javadoc" />
499     <doxygen configFilename="doxygen/beast_doxygen.cfg"/>
500         <javadoc packagenames="eu.baltrad.*"
501                  sourcepath="src"
502                  excludepackagenames="com.dummy.test.doc-files.*"
503                  defaultexcludes="yes"
504                  destdir="${dist.dir}/javadoc"
505                  author="true"
506                  version="true"
507                  use="true"
508                  windowtitle="Beast API">
509         <classpath refid="lib.path"/>
510         <doctitle><![CDATA[<h1>Beast API</h1>]]></doctitle>
511         <bottom><![CDATA[<i>Copyright 2010 Swedish Meteorological and Hydrological Institute.</i>]]></bottom>
512         <tag name="todo" scope="all" description="To do:"/>
513         <group title="Adaptors" packages="eu.baltrad.beast.adaptor*"/>
514         <group title="DB" packages="eu.baltrad.beast.db*"/>
515         <group title="Messages" packages="eu.baltrad.beast.manager*:eu.baltrad.beast.message*"/>
516         <group title="PgFwk" packages="eu.baltrad.beast.pgfwk*"/>
517         <group title="Rules" packages="eu.baltrad.beast.router*:eu.baltrad.beast.rules*"/>
518         <group title="Scheduler" packages="eu.baltrad.beast.scheduler*"/>
519         <link href="http://download.oracle.com/javase/6/docs/api/"/>
520       </javadoc>
521   </target>
522 </project>
523