1<!-- $Id$ -->
2<project name="clover" default="build" basedir=".">
3
4  <property name="db" location="../.."/>
5  <property name="db.jar" location="${db}/build_unix/db.jar"/>
6  <property name="test.src" location="src"/>
7  <property name="examples.src" location="${db}/examples_java/src"/>
8  <property name="clover.initstring" location="reports/clover.db"/>
9  <property name="clover.excludes" value="**/test/** collections/** db/** com/sleepycat/db/**"/>
10  <!--
11  <property name="build.compiler"
12            value="org.apache.tools.ant.taskdefs.CloverCompilerAdapter"/>
13  -->
14
15  <target name="all" depends="clean,test,report"/>
16
17  <target name="clean">
18    <delete dir="classes"/>
19    <delete dir="tmp"/>
20    <delete dir="reports"/>
21    <delete dir="original"/>
22    <delete dir="evolved"/>
23    <delete dir="testevolvedir"/>
24    <delete dir="testserialdir"/>
25    <delete dir="testenhancedir"/>
26  </target>
27
28  <target name="init">
29    <mkdir dir="classes"/>
30    <mkdir dir="tmp"/>
31    <mkdir dir="reports"/>
32  </target>
33
34  <path id="clover.classpath">
35    <pathelement location="clover.jar"/>
36    <pathelement location="velocity.jar"/>
37  </path>
38
39  <path id="classpath">
40    <pathelement location="${db.jar}"/>
41    <pathelement location="classes"/>
42    <pathelement location="clover.jar"/>
43    <path refid="clover.classpath"/>
44  </path>
45
46  <path id="enhanced.classpath">
47    <pathelement location="${db.jar}"/>
48    <pathelement location="testenhancedir"/>
49  </path>
50
51  <target name="build" depends="init">
52    <echo message="Using db.jar: ${db.jar}"/>
53    <javac destdir="classes" debug="on" source="1.5" target="1.5">
54      <classpath refid="classpath"/>
55      <src path="${test.src}"/>
56      <src path="${examples.src}"/>
57      <exclude name="com/sleepycat/**/release/**"/>
58    </javac>
59    <!-- Compile original version of TestSerial.java.original. -->
60    <property name="testserialpath"
61              value="com/sleepycat/collections/test/serial/TestSerial"/>
62    <copy file="${test.src}/${testserialpath}.java.original"
63          tofile="testserialdir/${testserialpath}.java"/>
64    <javac destdir="testserialdir" debug="on" source="1.5" target="1.5"
65           includeAntRuntime="true" srcdir="testserialdir">
66      <include name="${testserialpath}.java"/>
67      <classpath refid="classpath"/>
68    </javac>
69    <!-- Compile original version of EvolveClasses. -->
70    <copy file=
71      "${test.src}/com/sleepycat/persist/test/EvolveClasses.java.original"
72          tofile=
73      "testevolvedir/com/sleepycat/persist/test/EvolveClasses.java"/>
74    <copy file=
75      "${test.src}/com/sleepycat/persist/test/EvolveCase.java"
76          tofile=
77      "testevolvedir/com/sleepycat/persist/test/EvolveCase.java"/>
78    <copy file=
79      "${test.src}/com/sleepycat/persist/test/PersistTestUtils.java"
80          tofile=
81      "testevolvedir/com/sleepycat/persist/test/PersistTestUtils.java"/>
82    <javac debug="on" source="1.5" target="1.5">
83      <src path="testevolvedir"/>
84      <classpath refid="classpath"/>
85    </javac>
86  </target>
87
88  <target name="test" depends="build">
89
90    <!-- Determine which tests to run. -->
91    <condition property="dotestserial">
92      <or>
93        <not><isset property="testcase"/></not>
94        <equals arg1="${testcase}" arg2=
95         "com.sleepycat.collections.test.serial.StoredClassCatalogTest"/>
96      </or>
97    </condition>
98    <condition property="dotestevolve">
99      <or>
100        <not><isset property="testcase"/></not>
101        <equals arg1="${testcase}"
102                arg2="com.sleepycat.persist.test.EvolveTest"/>
103      </or>
104    </condition>
105
106    <!-- Performs initialization needed before StoredClassCatalogTest. -->
107    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
108           showoutput="on">
109      <jvmarg value="-ea"/>
110      <classpath path="testserialdir"/> <!-- Must be first -->
111      <classpath refid="classpath"/>
112      <sysproperty key="testdestdir" value="./tmp"/>
113      <sysproperty key="longtest" value="${longtest}"/>
114      <formatter type="plain" usefile="false"/>
115      <formatter type="xml"/>
116      <test name=
117            "com.sleepycat.collections.test.serial.StoredClassCatalogTestInit"
118            todir="reports" if="dotestserial"/>
119    </junit>
120
121    <!-- Performs initialization needed before persist EvolveTest. -->
122    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
123           showoutput="on">
124      <jvmarg value="-ea"/>
125      <classpath path="testevolvedir"/>
126      <classpath refid="classpath"/>
127      <sysproperty key="testdestdir" value="./tmp"/>
128      <sysproperty key="longtest" value="${longtest}"/>
129      <formatter type="plain" usefile="false"/>
130      <formatter type="xml"/>
131      <test name="com.sleepycat.persist.test.EvolveTestInit"
132            todir="reports" if="dotestevolve"/>
133    </junit>
134
135    <!-- Performs testcase if set, or batch tests. -->
136    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
137           showoutput="on">
138      <jvmarg value="-ea"/>
139      <classpath refid="classpath"/>
140      <sysproperty key="testdestdir" value="./tmp"/>
141      <sysproperty key="longtest" value="${longtest}"/>
142      <formatter type="plain" usefile="false"/>
143      <formatter type="xml"/>
144      <test name="${testcase}" todir="reports" if="testcase"/>
145      <batchtest todir="reports" unless="testcase">
146        <fileset dir="classes" includes="**/*Test.class"/>
147      </batchtest>
148    </junit>
149
150    <!-- Run the persist tests with -javaagent to enhance classes as they are
151         loaded.  In this, and the following two tests with enhanced classes,
152         set the expectEnhanced system property to cause the test to fail if
153         classes are not enhanced.  -->
154    <echo message="Run persist tests with -javaagent"/>
155    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
156           showoutput="on">
157      <jvmarg value="-ea"/>
158      <jvmarg value="-javaagent:${db.jar}=enhance:-v,com.sleepycat.persist"/>
159      <classpath refid="classpath"/>
160      <sysproperty key="testdestdir" value="./tmp"/>
161      <sysproperty key="longtest" value="${longtest}"/>
162      <sysproperty key="expectEnhanced" value="true"/>
163      <formatter type="plain" usefile="false"/>
164      <formatter type="xml"/>
165      <batchtest todir="reports" unless="testcase">
166        <fileset dir="classes"
167                 includes="com/sleepycat/persist/**/*Test.class"/>
168      </batchtest>
169    </junit>
170
171    <!-- Enhance persist test classes by rewriting the class files with the
172         enhancer ant task, and run the persist tests again.  Compile
173         ClassEnhancerTask here.  It is not compiled into db.jar because that
174         would create a primary build dependency on the Ant libraries. -->
175    <echo message="Run persist tests with ClassEnhancer ant task"/>
176    <delete dir="testenhancedir"/>
177    <mkdir dir="testenhancedir"/>
178    <copy todir="testenhancedir">
179      <fileset dir="classes" includes="com/sleepycat/persist/**/*.class"/>
180    </copy>
181    <javac destdir="testenhancedir" debug="on" source="1.5" target="1.5"
182           includeAntRuntime="true" srcdir="${db}/java/src">
183      <include name="com/sleepycat/persist/model/ClassEnhancerTask.java"/>
184      <classpath refid="classpath"/>
185    </javac>
186    <taskdef name="enhancer"
187             classname="com.sleepycat.persist.model.ClassEnhancerTask">
188      <classpath refid="enhanced.classpath"/>
189    </taskdef>
190    <enhancer verbose="on">
191      <fileset dir="testenhancedir"/>
192    </enhancer>
193    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
194           showoutput="on">
195      <jvmarg value="-ea"/>
196      <classpath refid="enhanced.classpath"/>
197      <classpath refid="classpath"/>
198      <sysproperty key="testdestdir" value="./tmp"/>
199      <sysproperty key="longtest" value="${longtest}"/>
200      <sysproperty key="expectEnhanced" value="true"/>
201      <formatter type="plain" usefile="false"/>
202      <formatter type="xml"/>
203      <batchtest todir="reports" unless="testcase">
204        <fileset dir="classes"
205                 includes="com/sleepycat/persist/**/*Test.class"/>
206      </batchtest>
207    </junit>
208
209    <!-- Enhance persist test classes by rewriting the class files with the
210         ClassEnhancer main program, and run the persist tests again. -->
211    <echo message="Run persist tests with ClassEnhancer main program"/>
212    <delete dir="testenhancedir"/>
213    <mkdir dir="testenhancedir"/>
214    <copy todir="testenhancedir">
215      <fileset dir="classes" includes="com/sleepycat/persist/**/*.class"/>
216    </copy>
217    <java fork="yes" failonerror="true"
218          classname="com.sleepycat.persist.model.ClassEnhancer">
219      <arg line="-v testenhancedir"/>
220      <classpath refid="classpath"/>
221    </java>
222    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
223           showoutput="on">
224      <jvmarg value="-ea"/>
225      <classpath refid="enhanced.classpath"/>
226      <classpath refid="classpath"/>
227      <sysproperty key="testdestdir" value="./tmp"/>
228      <sysproperty key="longtest" value="${longtest}"/>
229      <sysproperty key="expectEnhanced" value="true"/>
230      <formatter type="plain" usefile="false"/>
231      <formatter type="xml"/>
232      <batchtest todir="reports" unless="testcase">
233        <fileset dir="classes"
234                 includes="com/sleepycat/persist/**/*Test.class"/>
235      </batchtest>
236    </junit>
237
238  </target>
239
240  <!-- examples runs all examples, but does not include access_example because
241       it is interactive.
242  -->
243  <target name="examples" depends="build">
244    <echo message="=== HelloDatabaseWorld ==="/>
245    <java dir="." fork="yes" classpathref="classpath" failonerror="true"
246         classname="collections.hello.HelloDatabaseWorld"/>
247    <echo message=""/>
248    <antcall target="one_shipment_example">
249      <param name="param_name" value="basic"/>
250    </antcall>
251    <antcall target="one_shipment_example">
252      <param name="param_name" value="index"/>
253    </antcall>
254    <antcall target="one_shipment_example">
255      <param name="param_name" value="entity"/>
256    </antcall>
257    <antcall target="one_shipment_example">
258      <param name="param_name" value="tuple"/>
259    </antcall>
260    <antcall target="one_shipment_example">
261      <param name="param_name" value="sentity"/>
262    </antcall>
263    <antcall target="one_shipment_example">
264      <param name="param_name" value="marshal"/>
265    </antcall>
266    <antcall target="one_shipment_example">
267      <param name="param_name" value="factory"/>
268    </antcall>
269    <antcall target="one_persist_example">
270      <param name="param_name" value="CustomKeyOrderExample"/>
271    </antcall>
272    <antcall target="one_persist_example">
273      <param name="param_name" value="EventExample"/>
274    </antcall>
275    <antcall target="one_persist_example">
276      <param name="param_name" value="EventExampleDPL"/>
277    </antcall>
278    <antcall target="one_persist_example">
279      <param name="param_name" value="PersonExample"/>
280    </antcall>
281    <antcall target="DplDump">
282      <param name="home" value="tmp"/>
283      <param name="store" value="PersonStore"/>
284    </antcall>
285    <antcall target="db-gettingStarted"/>
286    <antcall target="db-txn"/>
287    <antcall target="persist-gettingStarted"/>
288    <antcall target="persist-txn"/>
289  </target>
290
291  <target name="one_shipment_example">
292    <echo message="=== ${param_name} ==="/>
293    <delete dir="tmp"/>
294    <mkdir dir="tmp"/>
295    <java dir="." fork="yes" classpathref="classpath" failonerror="true"
296     classname="collections.ship.${param_name}.Sample"/>
297  </target>
298
299  <target name="one_persist_example">
300    <echo message="=== ${param_name} ==="/>
301    <delete dir="tmp"/>
302    <mkdir dir="tmp"/>
303    <java fork="yes" dir="." classname="persist.${param_name}"
304          failonerror="true">
305      <jvmarg value="-ea"/>
306      <arg line="-h tmp"/>
307      <classpath refid="classpath"/>
308    </java>
309  </target>
310
311  <!--
312  Before running this example, first run another DPL example that writes to the
313  home directory.  Note that we do not clear the home directory here, in order
314  to use the DB in the home directory from a previous run.
315  -->
316  <target name="DplDump">
317    <echo message="=== DplDump ${home} ${store} ==="/>
318    <java fork="yes" dir="." classname="persist.DplDump" failonerror="true">
319      <jvmarg value="-ea"/>
320      <arg line="-h ${home} -s ${store}"/>
321      <classpath refid="classpath"/>
322    </java>
323  </target>
324
325  <target name="access_example" depends="build">
326    <echo message="=== AccessExample ==="/>
327    <java fork="yes" dir="." classpathref="classpath" failonerror="true"
328          classname="collections.access.AccessExample">
329    </java>
330  </target>
331
332  <!-- Test GSG examples -->
333
334  <target name="db-gettingStarted" depends="build">
335    <delete dir="tmp"/>
336    <mkdir dir="tmp"/>
337    <copy todir="tmp">
338      <fileset dir="${examples.src}/db/GettingStarted">
339        <include name="*.txt"/>
340        <exclude name="*.java"/>
341      </fileset>
342    </copy>
343    <java fork="yes" dir="tmp"
344        classname="db.GettingStarted.ExampleDatabaseLoad"
345        failonerror="true">
346      <arg line="-h ."/>
347      <classpath refid="classpath"/>
348    </java>
349    <java fork="yes" dir="tmp"
350        classname="db.GettingStarted.ExampleDatabaseRead"
351        failonerror="true">
352      <arg line="-h ."/>
353      <classpath refid="classpath"/>
354    </java>
355    <delete file="tmp/inventory.txt"/>
356    <delete file="tmp/vendors.txt"/>
357  </target>
358
359  <target name="db-txn" depends="build">
360    <delete dir="tmp"/>
361    <mkdir dir="tmp"/>
362    <java fork="yes" dir="."
363        classname="db.txn.TxnGuide"
364        failonerror="true">
365      <arg line="-h tmp"/>
366      <classpath refid="classpath"/>
367    </java>
368  </target>
369
370  <target name="persist-gettingStarted" depends="build">
371    <delete dir="tmp"/>
372    <mkdir dir="tmp"/>
373    <mkdir dir="tmp/JEDB"/>
374    <copy todir="tmp">
375      <fileset dir="${examples.src}/persist/gettingStarted">
376        <include name="*.txt"/>
377        <exclude name="*.java"/>
378      </fileset>
379    </copy>
380    <java fork="yes" dir="tmp"
381        classname="persist.gettingStarted.SimpleStorePut"
382        failonerror="true">
383      <arg line="-h ."/>
384      <classpath refid="classpath"/>
385    </java>
386    <java fork="yes" dir="tmp"
387        classname="persist.gettingStarted.SimpleStoreGet"
388        failonerror="true">
389      <arg line="-h ."/>
390      <classpath refid="classpath"/>
391    </java>
392    <delete file="tmp/inventory.txt"/>
393    <delete file="tmp/vendors.txt"/>
394  </target>
395
396  <target name="persist-txn" depends="build">
397    <delete dir="tmp"/>
398    <mkdir dir="tmp"/>
399    <java fork="yes" dir="."
400        classname="persist.txn.TxnGuideDPL"
401        failonerror="true">
402      <arg line="-h tmp"/>
403      <classpath refid="classpath"/>
404    </java>
405  </target>
406
407  <target name="report">
408    <java classname="com.cortexeb.tools.clover.reporters.html.HtmlReporter"
409          failonerror="true" fork="true">
410       <arg line="--outputdir reports --showSrc --initstring ${clover.initstring} --title 'Berkeley DB Java BDB API'"/>
411       <classpath refid="clover.classpath"/>
412    </java>
413  </target>
414
415</project>
416