Added install-files target to build.xml
[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-files" depends="-install-files" />
190
191   <target name="install-doc" depends="doc, -install-doc-files" />
192
193   <!-- This is the overall build script that can be used to get a full build & test sequence --> 
194   <target name="hudson" depends="build,test.coverage" />
195
196   <target name="hudson-install" depends="build,test.coverage,-install-files" />
197
198   <target name="itest" depends="build,execute.itest" />
199   <target name="test" depends="build,execute.test" />
200         
201   <!-- Compile the code -->
202   <target name="compile" depends="prepare">
203     <mkdir dir="${build.classes.dir}"/>
204     <javac srcdir="${source.dir}"
205            encoding="8859_1"
206            deprecation="on"
207            debug="${compile.debug}"
208            includeAntRuntime="${compile.includeAntRuntime}"
209            optimize="${compile.optimize}"
210            destdir="${build.classes.dir}">
211       <classpath refid="lib.path"/>
212     </javac>
213   </target>
214
215   <!-- UNIT TEST PART -->
216   <target name="compile.test">
217     <mkdir dir="${build.test.dir}"/>
218     <javac srcdir="${app.root.dir}/test"
219            encoding="8859_1"
220            deprecation="on"
221            debug="${compile.debug}"
222            includeAntRuntime="${compile.includeAntRuntime}"     
223            optimize="${compile.optimize}"
224            destdir="${build.test.dir}">
225         <classpath location="${build.classes.dir}"/>
226       <classpath refid="lib.path"/>
227       <classpath refid="test.lib.path"/>
228     </javac>
229         
230     <!-- copy any resources -->
231     <copy todir="${build.test.dir}">
232       <fileset dir="${app.root.dir}/test">
233         <include name="**/*.xml"/>
234         <include name="**/*.properties"/>
235         <include name="**/*.groovy"/>
236         <include name="**/test-key.priv/*"/>
237       </fileset>
238     </copy>
239   </target>
240
241   <target name="prepare.test" depends="compile.test">
242     <mkdir dir="${dist.dir}/junit-reports" />
243   </target>     
244         
245   <target name="execute.test" depends="prepare.test">
246         <mkdir dir="${dist.dir}/junit-reports" />
247         <junit dir="${build.test.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
248           <jvmarg line="-Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
249           <formatter type="xml"/> 
250           <formatter type="brief" usefile="false" if="test.format.brief" />
251           <classpath refid="test.lib.path"/>
252           <classpath location="${build.classes.dir}"/>
253           <classpath refid="lib.path"/>
254           <classpath location="${build.test.dir}" />
255           <batchtest fork="yes" todir="${dist.dir}/junit-reports">
256             <fileset dir="${build.test.dir}" includes="**/*Test.class" excludes="**/HDF5*.class"/>
257           </batchtest>
258         </junit>
259   </target>
260
261   <!-- INTEGRATION TEST PART -->
262   <target name="compile.itest">
263     <mkdir dir="${build.itest.dir}"/>
264     <javac srcdir="${app.root.dir}/itest"
265            encoding="8859_1"
266            deprecation="on"
267            debug="${compile.debug}"
268            includeAntRuntime="${compile.includeAntRuntime}"     
269            optimize="${compile.optimize}"
270            destdir="${build.itest.dir}">
271       <classpath location="${build.classes.dir}"/>
272       <classpath refid="lib.path"/>
273       <classpath refid="test.lib.path"/>
274     </javac>
275
276     <!-- copy any resources -->
277     <copy todir="${build.itest.dir}">
278       <fileset dir="${app.root.dir}/itest">
279         <include name="**/*.xml"/>
280         <include name="**/*.xls"/>
281         <include name="**/*.properties"/>
282         <include name="**/*.groovy"/>
283         <include name="**/*.h5"/>
284       </fileset>
285     </copy>
286   </target>     
287
288   <!-- prepares the setup so that it is possible to run the junit integration tests -->
289   <target name="prepare.itest" depends="create-testdb, extras-testdb, compile.itest">
290         <mkdir dir="${dist.dir}/junit-reports" />
291         <copy file="${etc.dir}/testdb.properties" todir="${build.classes.dir}"/>
292   </target>
293
294   <target name="create-testdb">
295         <sql classpath="${lib.dir}/${db.jar}"
296              driver="${db.driver}"
297              url="${db.url}"
298              userid="${db.user}" 
299              password="${db.pwd}">
300           <transaction src="${etc.dir}/drop_db.sql"/>
301           <transaction src="${etc.dir}/create_db.sql"/>
302         </sql>
303   </target>
304
305   <target name="extras-testdb">
306         <sql classpath="${lib.dir}/${db.jar}"
307              driver="${db.driver}"
308              url="${db.url}"
309              userid="${db.user}" 
310              password="${db.pwd}"
311                  escapeprocessing="false"
312                  expandproperties="false"
313                  delimitertype="row">
314           <transaction src="${etc.dir}/extras_testdb.sql"/>
315         </sql>
316   </target>
317
318   <target name="start-baltrad-bdb-server">
319     <exec executable="${baltraddb.bin.path}/baltrad-bdb-drop"
320           failonerror="true">
321       <arg value="--conf=${etc.dir}/testdb.properties"/>
322     </exec>
323     <exec executable="${baltraddb.bin.path}/baltrad-bdb-create"
324           failonerror="true">
325       <arg value="--conf=${etc.dir}/testdb.properties"/>
326     </exec>
327     <exec executable="${baltraddb.bin.path}/baltrad-bdb-server"
328           failonerror="true">
329       <arg value="--conf=${etc.dir}/testdb.properties"/>
330       <arg value="--pidfile=${build.dir}/baltrad-bdb-server.pid"/>
331       <arg value="--logfile=${build.dir}/baltrad-bdb-server.log"/>
332     </exec>
333         <sleep seconds="2"/>
334     <exec executable="${baltraddb.bin.path}/baltrad-bdb-client"
335           failonerror="true">
336       <arg value="import_sources"/>
337       <arg value="--url=${blt.db.uri}"/>
338       <arg value="${basedir}/etc/itest_sources.xml"/>
339     </exec>
340   </target>
341
342
343   <target name="stop-baltrad-bdb-server">
344     <exec executable="cat" outputproperty="baltraddb.server.pid">
345       <arg value="${build.dir}/baltrad-bdb-server.pid"/>
346     </exec>
347     <exec executable="kill">
348       <arg value="${baltraddb.server.pid}"/>
349     </exec>
350   </target>
351         
352   <target name="execute.itest" depends="prepare.itest,start-baltrad-bdb-server">
353     <junit dir="${build.itest.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
354       <jvmarg line="-Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
355       <formatter type="xml"/> 
356       <formatter type="brief" usefile="false" if="test.format.brief" />
357       <classpath refid="test.lib.path"/>
358       <classpath location="${build.classes.dir}"/>
359       <classpath refid="lib.path"/>
360       <classpath location="${build.itest.dir}" />
361       <batchtest fork="yes" todir="${dist.dir}/junit-reports">
362         <fileset dir="${build.itest.dir}" includes="**/*Test.class"
363                  excludes="eu/baltrad/beast/net/FileDistributionITest.class"/>
364         <!--
365         <fileset dir="${build.itest.dir}" includes="**/VolumeRuleManagerITest.class"
366                  excludes="eu/baltrad/beast/net/FileDistributionITest.class"/>
367         -->         
368       </batchtest>
369     </junit>
370     <antcall target="stop-baltrad-bdb-server" />
371   </target>
372
373   <!-- target that can be used to manually test FileDistribution -->
374   <target name="execute.itest.filedistribution" depends="compile.itest">
375     <java classname="eu.baltrad.beast.net.FileDistributionITest" fork="true">
376       <arg value="${itest.filedistribution.src}"/>
377       <arg value="${itest.filedistribution.dst}"/>
378       <arg value="${itest.filedistribution.entry}"/>
379       <classpath refid="test.lib.path"/>
380       <classpath location="${build.classes.dir}"/>
381       <classpath refid="lib.path"/>
382       <classpath location="${build.itest.dir}" />
383     </java>
384   </target>
385
386   <!-- CODE COVERAGE -->
387   <target name="instrument.coverage">
388     <delete dir="${build.instrument.dir}" />
389     <delete file="${build.coverage.dir}/coverage.ec" />
390     <delete file="${build.coverage.dir}/metadata.emma" />
391     <mkdir dir="${build.instrument.dir}" />
392     <mkdir dir="${build.coverage.dir}" />
393
394         <emma enabled="true">
395       <instr instrpath="${build.classes.dir}/"
396              destdir="${build.instrument.dir}/" 
397              metadatafile="${build.coverage.dir}/metadata.emma"
398              merge="true"/>
399     </emma>
400   </target>
401   
402   <target name="unittest.coverage" depends="instrument.coverage">
403     <mkdir dir="${dist.dir}/coverage-reports" />
404     <junit dir="${build.test.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
405       <jvmarg line="-d64 -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
406       <sysproperty key="emma.coverage.out.file" file="${build.coverage.dir}/coverage.ec" /> <!-- So I know where ec file is placed -->
407       <formatter type="xml"/> 
408       <classpath location="${build.instrument.dir}" /> <!-- For instrumentation -->
409       <classpath refid="test.lib.path"/>
410       <classpath location="${build.classes.dir}"/>
411       <classpath refid="lib.path"/>
412       <classpath location="${build.test.dir}" />
413       <classpath refid="emma.classpath" />
414         
415       <batchtest fork="yes" todir="${dist.dir}/junit-reports">
416         <fileset dir="${build.test.dir}" includes="**/*Test.class"/>
417       </batchtest>
418     </junit>
419
420         <emma enabled="true">
421       <report sourcepath="${source.dir}" >
422         <fileset dir="${build.coverage.dir}" >
423           <include name="*.emma" />
424           <include name="*.ec" />
425         </fileset>
426         <xml outfile="${dist.dir}/coverage-reports/coverage.xml" depth="method"/>
427       </report>
428     </emma>
429   </target>
430
431   <!-- performs coverage from running all tests (unit tests, integration tests-->
432   <target name="test.coverage" depends="prepare.test,prepare.itest,instrument.coverage,start-baltrad-bdb-server">
433     <mkdir dir="${dist.dir}/junit-reports" />
434     <mkdir dir="${dist.dir}/coverage-reports" />
435
436         <junit dir="${build.test.dir}" showoutput="true" forkmode="perBatch" printsummary="no" >
437       <jvmarg line="-d64 -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -noverify"/>
438       <sysproperty key="emma.coverage.out.file" file="${build.coverage.dir}/coverage.ec" /> <!-- So I know where ec file is placed -->
439       <formatter type="xml"/> 
440       <classpath location="${build.instrument.dir}" /> <!-- For instrumentation -->
441       <classpath refid="test.lib.path"/>
442       <classpath location="${build.classes.dir}"/>
443       <classpath refid="lib.path"/>
444       <classpath location="${build.test.dir}" />
445       <classpath location="${build.itest.dir}" />
446       <classpath refid="emma.classpath" />
447         
448       <batchtest fork="true" todir="${dist.dir}/junit-reports">
449         <fileset dir="${build.test.dir}" includes="**/*Test.class"/>
450         <fileset dir="${build.itest.dir}" includes="**/*Test.class"
451                  excludes="eu/baltrad/beast/net/FileDistributionITest.class"/>
452       </batchtest>
453     </junit>
454
455     <antcall target="stop-baltrad-bdb-server" />
456
457         <emma enabled="true">
458       <report sourcepath="${source.dir}" >
459         <fileset dir="${build.coverage.dir}" >
460           <include name="*.emma" />
461           <include name="*.ec" />
462         </fileset>
463         <xml outfile="${dist.dir}/coverage-reports/coverage.xml" depth="method"/>
464       </report>
465     </emma>
466   </target>
467         
468   <!-- clean directories for building -->
469   <target name="clean">
470     <delete dir="${build.dir}" />
471     <delete dir="${dist.dir}" />
472   </target>
473         
474   <!-- Prepare for compilation and jar-generation, copy files -->
475   <target name="prepare">
476     <mkdir dir="${build.dir}" />
477     <mkdir dir="${build.classes.dir}" />
478     <mkdir dir="${build.test.dir}" />
479
480         <!-- Copy misc extra files that resides in the src into classes -->
481     <copy todir="${build.classes.dir}" preservelastmodified="true">
482       <fileset dir="${source.dir}">
483         <include name="**/*.properties"/>
484         <include name="**/*.handlers"/>
485         <include name="**/*.schemas"/>
486         <include name="**/*.xml"/>
487         <include name="**/*.dtd"/>
488         <include name="**/*.xsd"/>
489         <include name="**/*.vm"/>
490         <include name="**/*.ftl"/>
491         <include name="**/*.types"/>
492       </fileset>
493     </copy>
494         <mkdir dir="${blt.db.path}" />
495   </target>
496         
497   <target name="doc" description="Generates doxygen">
498     <taskdef name="doxygen" classname="org.doxygen.tools.DoxygenTask" classpathref="doxygen.classpath" />
499         <mkdir dir="${dist.dir}/doxygen" />
500         <mkdir dir="${dist.dir}/javadoc" />
501     <doxygen configFilename="doxygen/beast_doxygen.cfg"/>
502         <javadoc packagenames="eu.baltrad.*"
503                  sourcepath="src"
504                  excludepackagenames="com.dummy.test.doc-files.*"
505                  defaultexcludes="yes"
506                  destdir="${dist.dir}/javadoc"
507                  author="true"
508                  version="true"
509                  use="true"
510                  windowtitle="Beast API">
511         <classpath refid="lib.path"/>
512         <doctitle><![CDATA[<h1>Beast API</h1>]]></doctitle>
513         <bottom><![CDATA[<i>Copyright 2010 Swedish Meteorological and Hydrological Institute.</i>]]></bottom>
514         <tag name="todo" scope="all" description="To do:"/>
515         <group title="Adaptors" packages="eu.baltrad.beast.adaptor*"/>
516         <group title="DB" packages="eu.baltrad.beast.db*"/>
517         <group title="Messages" packages="eu.baltrad.beast.manager*:eu.baltrad.beast.message*"/>
518         <group title="PgFwk" packages="eu.baltrad.beast.pgfwk*"/>
519         <group title="Rules" packages="eu.baltrad.beast.router*:eu.baltrad.beast.rules*"/>
520         <group title="Scheduler" packages="eu.baltrad.beast.scheduler*"/>
521         <link href="http://download.oracle.com/javase/6/docs/api/"/>
522       </javadoc>
523   </target>
524 </project>
525