source: build.xml @ 26

Last change on this file since 26 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 19.0 KB
Line 
1<project name="weka" default="compile" basedir=".">
2<!--
3  ===========================================================================
4   Ant build file for weka. Tested with ant 1.6.5 and Junit 3.8.2. Requires
5   JavaMail and the java activation framework for mailing unit test results.
6
7   Type ant -projecthelp for targets and descriptions.
8   Assumes weka and tests (if unit testing) are in the same directory.
9   Build file can reside and be executed from either inside weka or the
10   directory containing weka.
11
12   $Revision: 5694 $
13  ===========================================================================
14-->
15
16  <!-- set global properties for this build -->
17  <property name="src" value="src/main/java"/>
18  <property name="src-test" value="src/test/java"/>
19  <property name="lib" value="lib" />
20  <property name="regression_tests_root" value="src/test/resources/wekarefs"/>
21  <property name="build" value="build"/>
22  <property name="dist"  value="dist"/>
23  <property name="doc"  value="doc"/>
24  <property name="reports"  value="reports"/>
25  <property name="javac_max_memory" value="256m"/>
26  <property name="run_tests_fail" value="true"/>
27  <property name="headless" value="false"/>
28  <property name="macdistrib" value="osx-distrib"/>
29  <property name="debug" value="on" />
30
31  <target name="init_all">
32    <!-- Create the time stamp -->
33    <tstamp/>
34  </target>
35
36   <!-- general classpath definition, incl. CLASSPATH env. variable,
37   // but jars in lib directory have precedence over the CLASSPATH variable -->
38  <path id="project.class.path">
39    <fileset dir="${lib}">
40      <include name="*.jar"/>
41      <include name="*.zip"/>
42    </fileset>
43    <pathelement location="${build}/classes"/>
44    <pathelement location="${build}/testcases"/>
45    <pathelement path="${java.class.path}" />
46  </path>
47
48<!--
49 ============================================================================
50 Compilation and documentation making stuff
51 ============================================================================
52-->
53
54  <target name="init_compile" depends="init_all">
55    <!-- Create the build directory structure used by compile -->
56    <mkdir dir="${build}/classes"/>
57  </target>
58
59  <!-- Compile the java code from ${src}/weka into ${build}/classes -->
60  <target name="compile" depends="init_compile" 
61   description="Compile weka and deposit class files in build/classes">
62    <javac srcdir="${src}" 
63      fork="yes" memoryMaximumSize="${javac_max_memory}"
64      destdir="${build}/classes"
65      optimize="${optimization}"
66      debug="${debug}"
67      deprecation="${deprecation}"
68      source="1.6" target="1.6">
69
70      <classpath refid="project.class.path" /> 
71    </javac>
72    <copy todir="${build}/classes" >
73       <fileset dir="${src}">
74         <include name="weka/**/*.excludes"/>
75         <include name="weka/**/*.gif"/>
76         <include name="weka/**/*.png"/>
77         <include name="weka/**/*.jpeg"/>
78         <include name="weka/**/*.jpg"/>
79         <include name="weka/**/*.props"/>
80         <include name="weka/**/*.txt"/>
81         <include name="weka/**/*.xml"/>
82         <include name="weka/**/DatabaseUtils.props.*"/>
83         <include name="weka/gui/beans/README*"/>
84         <include name="**/*.cup"/>
85         <include name="**/*.flex"/>
86         <include name="**/*.jflex"/>
87         <include name="**/*.properties"/>
88         <include name="**/*.default"/>
89       </fileset>
90    </copy>
91    <rmic base="${build}/classes"
92       classname="weka.experiment.RemoteEngine"/>
93    <unzip src="${lib}/java-cup.jar" dest="${build}/classes">
94      <patternset>
95        <include name="java_cup/runtime/**/*"/>
96      </patternset>
97    </unzip>
98  </target>
99
100  <!-- Make the javadocs -->
101  <target name="docs" 
102          depends="init_all" 
103          description="Make javadocs into ./doc">
104    <mkdir dir="${doc}"/>
105    <javadoc sourcepath="${src}" 
106             classpathref="project.class.path"
107             destdir="${doc}" 
108             packagenames="weka.*"
109             Author="yes" 
110             Public="yes" 
111             maxmemory="256m"/>
112   
113    <!-- insert the links to our homepage and documentation.html -->
114    <replace dir="${doc}" 
115             token="&#34;help-doc.html&#34;" 
116             value="&#34;../documentation.html&#34; target=&#34;_blank&#34;">
117      <include name="**/*.html"/>
118    </replace>
119     
120    <replace dir="${doc}" 
121             token="Help&lt;/B&gt;&lt;/FONT&gt;&lt;/A&gt;&#38;nbsp;&lt;/TD&gt;" 
122             value="Help&lt;/B&gt;&lt;/FONT&gt;&lt;/A&gt;&#38;nbsp;&lt;/TD&gt; &lt;TD BGCOLOR=&#34;&#35;EEEEFF&#34; CLASS=&#34;NavBarCell1&#34;&gt; &lt;A HREF=&#34;http://www.cs.waikato.ac.nz/ml/weka/&#34; target=&#34;_blank&#34;&gt;&lt;FONT CLASS=&#34;NavBarFont1&#34;&gt;&lt;B&gt;Weka's home&lt;/B&gt;&lt;/FONT&gt;&lt;/A&gt;&#38;nbsp;&lt;/TD&gt;">
123      <include name="**/*.html"/>
124    </replace>
125  </target> 
126
127
128<!--
129  ===========================================================================
130  Unit testing stuff
131  ===========================================================================
132-->
133<!-- Junit testing initialization -->
134  <target name="init_tests" depends="init_all">
135    <available property="junit.present" classname="junit.framework.TestCase"/>
136    <!-- Create the build directory structure used by compile -->
137    <mkdir dir="${build}/testcases"/>
138    <mkdir dir="${reports}"/>
139  </target>
140
141  <!-- compile the testcases -->
142  <target name="compile_tests" depends="init_tests, compile" 
143   description="Compile unit tests into build/testcases">
144     <javac srcdir="${src-test}" 
145       fork="yes" memoryMaximumSize="${javac_max_memory}"
146            destdir="${build}/testcases"
147            optimize="${optimization}"
148            debug="${debug}"
149            deprecation="${deprecation}"
150            source="1.5" target="1.5">
151       <classpath refid="project.class.path" /> 
152     </javac>
153     <copy todir="${build}/testcases" >
154       <fileset dir="${src-test}">
155          <include name="**/*.arff"/>
156          <include name="**/*.cost"/>
157          <include name="**/*.xml"/>
158          <include name="**/*.matrix"/>
159       </fileset>
160     </copy>
161  </target>
162
163  <!-- Put everything in ${build}/testcases into the weka-tests.jar file -->
164  <target name="jar_tests" depends="compile_tests, init_dist"
165   description="Creates a jar file with the test cases in ./dist">
166    <jar jarfile="${dist}/weka-tests.jar" 
167      basedir="${build}/testcases">
168    </jar>
169  </target>
170
171  <!-- Run the test cases via junit's testrunner class.
172   This is a faster, simpler option than running the junit task -->
173  <target name="run_tests" depends="compile_tests" 
174   description="Execute unit tests (fast)">
175     <java fork="yes" dir="."
176      classname="junit.textui.TestRunner"
177      taskname="junit" failonerror="${run_tests_fail}">
178         <arg value="weka.AllTests"/>
179         <classpath refid="project.class.path" /> 
180         <jvmarg value="-Djava.awt.headless=${headless}"/> 
181         <jvmarg value="-Dweka.test.Regression.root=${regression_tests_root}"/>
182     </java>
183  </target>
184
185<!-- Run the test cases and produce an html summary (in ${reports}-->
186  <target name="junit" depends="compile_tests" 
187   description="Execute unit tests and produce html summary (in ./reports)">
188     <junit fork="yes" dir=".">
189       <jvmarg value="-Djava.awt.headless=${headless}"/> 
190       <jvmarg value="-Dweka.test.Regression.root=${regression_tests_root}"/>
191        <formatter type="xml"/>
192        <classpath refid="project.class.path" /> 
193         <batchtest todir="${reports}">
194            <fileset dir="${build}/testcases">
195               <include name="**/*Test.class"/>
196               <exclude name="**/AllTests.class"/>
197            </fileset>
198         </batchtest>
199     </junit>
200
201     <junitreport todir="${reports}">
202        <fileset dir="${reports}">
203           <include name="TEST-*.xml"/>
204        </fileset>
205        <report format="noframes" todir="${reports}"/>
206     </junitreport>
207  </target>
208
209
210<!--
211  ===========================================================================
212  Release making stuff
213  ===========================================================================
214-->
215
216  <target name = "init_dist" depends="init_all">
217    <!-- Create the distribution directory -->
218    <mkdir dir="${dist}"/>
219  </target>
220
221  <!-- Put everything in ${build}/classes into the weka.jar file -->
222  <target name="exejar" depends="compile, init_dist"
223   description="Create an executable jar file in ./dist">
224    <jar jarfile="${dist}/weka.jar" 
225      basedir="${build}/classes">
226     <manifest>
227       <attribute name="Main-Class" value="weka.gui.GUIChooser"/>
228     </manifest>
229    </jar>
230  </target>
231
232  <!-- Put all .java, and .props files into ${dist}/weka-src.jar-->
233  <target name="srcjar" depends="init_dist, init_all"
234   description="Create a jar file containing weka source in ./dist"> 
235    <!-- jar up the source -->
236    <jar jarfile="${dist}/weka-src.jar" 
237      basedir=".">
238      <include name="*.xml"/>
239      <include name="src/**/*.excludes"/>
240      <include name="src/**/*.gif"/>
241      <include name="src/**/*.java"/>
242      <include name="src/**/*.jpeg"/>
243      <include name="src/**/*.jpg"/>
244      <include name="src/**/*.props"/>
245      <include name="src/**/*.txt"/>
246      <include name="src/**/*.xml"/>
247      <include name="src/**/DatabaseUtils.props.*"/>
248      <include name="src/**/weka/gui/beans/README*"/>
249      <include name="src/**/*.cup"/>
250      <include name="src/**/*.flex"/>
251      <include name="src/**/*.jflex"/>
252      <include name="src/**/*.properties"/>
253      <include name="src/**/*.default"/>
254      <include name="src/**/*.cost"/>
255      <include name="src/**/*.arff"/>
256      <include name="src/**/*.matrix"/>
257      <include name="lib/**/*.jar"/>
258    </jar>
259  </target>
260
261  <!-- make a jar file containing just the stuff needed for running a remote experiment server -->
262  <target name="remotejar" depends="compile, init_dist"
263   description="Create a jar file containing classes for remote experiments in ./dist">
264     <jar jarfile="${dist}/remoteEngine.jar"
265      basedir="${build}/classes"
266      includes="weka/experiment/*_*.class,weka/experiment/RemoteEngine*.class,weka/experiment/Compute.class,weka/experiment/Task.class,weka/experiment/TaskStatusInfo.class,weka/core/Queue*.class,weka/core/RevisionHandler.class,weka/core/Utils.class,weka/core/RevisionUtils.class"/>
267     <copy todir="${dist}" >
268       <fileset dir="${src}/weka/experiment">
269          <include name="remote.policy"/>
270          <include name="remote.policy.example"/>
271       </fileset>
272    </copy>
273    <jar jarfile="${dist}/remoteExperimentServer.jar"
274     basedir="${dist}"
275     includes="remoteEngine.jar,remote.policy,remote.policy.example"/>
276     <delete file="${dist}/remoteEngine.jar"/>
277     <delete file="${dist}/remote.policy"/>
278     <delete file="${dist}/remote.policy.example"/>
279   </target>
280
281  <!-- Writes $release version number to weka/core/version.txt -->   
282  <target name="set_version">
283    <echo message="${release}" file="${src}/weka/core/version.txt"/>
284    <echo message="${release}" file="${build}/classes/weka/core/version.txt"/>
285  </target>
286
287  <!-- Make a release -->
288  <target name="release" depends="run_tests, release_sub_tasks"
289   description="Make a release in ${release}. Run with -Drelease=&lt;number of release (eg. 3-4-1)&gt;.">
290  </target>
291
292  <target name="release_no_junit" depends="compile, release_sub_tasks"
293   description="Make a release in ${release} without running junit tests. Run with -Drelease=&lt;number of release (eg. 3-4-1)&gt;.">
294  </target>
295
296  <target name="release_sub_tasks" depends="set_version, exejar, remotejar, srcjar, docs, changelog">
297    <!-- copy the docs to dist/docs -->
298
299    <copy todir="weka-${release}/weka-${release}/doc" >
300       <fileset dir="${doc}"/>
301    </copy>
302    <copy todir="weka-${release}/weka-${release}">
303       <fileset dir="${dist}"/>
304    </copy>
305    <copy todir="weka-${release}/weka-${release}/changelogs">
306       <fileset dir="../wekadocs/changelogs"/>
307    </copy>
308    <copy todir="weka-${release}/weka-${release}/data">
309       <fileset dir="../wekadocs/data"/>
310    </copy>
311    <copy todir="weka-${release}/weka-${release}">
312      <fileset dir="../wekadocs">
313        <include name="*.pdf"/>
314      </fileset>
315    </copy>
316    <copy todir="weka-${release}/weka-${release}">
317       <fileset dir="../wekadocs">
318         <include name="README*"/>
319         <include name="COPYING"/>
320         <include name="documentation.*"/>
321         <include name="weka.gif"/>
322         <include name="weka.ico"/>
323       </fileset>
324    </copy>
325    <zip destfile="weka-${release}.zip" 
326     basedir="weka-${release}"/>
327  </target>
328
329  <!-- Make a Max OSX application (NOTE: assumes that release/release_no_junit or something that calls
330       release has been run first!!!). Also requires Ant version 1.7.0 or higher -->
331  <target name="osx_application" description="Make an OS X application. Run with -Drelease=&lt;number of release (eg. 3-4-1)&gt;. Assumes a release target has been run first!">
332    <mkdir dir="${macdistrib}"/>
333    <mkdir dir="${macdistrib}/weka-${release}"/>
334    <copy todir="${macdistrib}/weka-${release}">
335      <fileset dir="weka-${release}/weka-${release}"/>
336    </copy>
337    <taskdef name="jarbundler" 
338             classname="net.sourceforge.jarbundler.JarBundler" />
339    <jarbundler dir="${macdistrib}"
340                name="weka-${release}"
341                mainclass="weka.gui.GUIChooser"
342                icon="${src}/weka/gui/weka_icon.icns"
343                version="${release}"
344                verbose="true"
345                VMOptions="-Xmx256M"
346                shortname="Weka"
347                arguments=""
348                workingdirectory="$APP_PACKAGE/Contents/Resources"
349                jvmversion="1.5+">
350      <javaproperty name="java.library.path" value="$APP_PACKAGE/Contents/Resources"/>
351      <jarfileset dir="weka-${release}/weka-${release}">
352        <include name="weka.jar"/>
353      </jarfileset>
354    </jarbundler>
355
356    <!-- Make a .dmg disk image -->
357    <exec executable="/usr/bin/hdiutil" os="Mac OS X">
358      <arg value="create"/>
359      <arg value="-srcfolder"/>
360      <arg value="${macdistrib}"/>
361      <arg value="-volname"/>
362      <arg value="weka-${release}"/>
363      <arg value="-ov"/>
364      <arg value="${macdistrib}/weka-${release}.dmg"/>
365    </exec>
366  </target>
367
368<!-- New subversion stuff -->
369 <target name="svnCheckout" description="Checkout from subversion. Run with -Dsvn_username=username -Dsvn_password=password -Dweka_branch=&lt;branch name (e.g. trunk, branches/book2ndEd-branch)&gt;.">
370    <property name="source-root" value="."/>
371    <property name="repository.URL" value="https://svn.scms.waikato.ac.nz/svn/weka"/>
372    <java classname="org.tmatesoft.svn.cli.SVN"
373       dir="${source-root}/" fork="true">
374      <arg value="co"/>
375      <arg value="--username"/>
376      <arg value="${svn_username}"/>
377      <arg value="--password"/>
378      <arg value="${svn_password}"/>
379      <arg value="${repository.URL}/${weka_branch}/weka"/>
380      <classpath>
381        <pathelement location="${ant.home}/lib/svnkit.jar" />
382        <pathelement location="${ant.home}/lib/svnkit-cli.jar" />
383      </classpath>
384    </java>
385    <java classname="org.tmatesoft.svn.cli.SVN"
386       dir="${source-root}/" fork="true">
387      <arg value="co"/>
388      <arg value="--username"/>
389      <arg value="${svn_username}"/>
390      <arg value="--password"/>
391      <arg value="${svn_password}"/>
392      <arg value="${repository.URL}/${weka_branch}/wekadocs"/>
393      <classpath>
394        <pathelement location="${ant.home}/lib/svnkit.jar" />
395        <pathelement location="${ant.home}/lib/svnkit-cli.jar" />
396      </classpath>
397    </java>
398    <java classname="org.tmatesoft.svn.cli.SVN"
399       dir="${source-root}/" fork="true">
400      <arg value="co"/>
401      <arg value="--username"/>
402      <arg value="${svn_username}"/>
403      <arg value="--password"/>
404      <arg value="${svn_password}"/>
405      <arg value="${repository.URL}/${weka_branch}/installer"/>
406      <classpath>
407        <pathelement location="${ant.home}/lib/svnkit.jar" />
408        <pathelement location="${ant.home}/lib/svnkit-cli.jar" />
409      </classpath>
410    </java>
411  </target>
412
413   <target name="changelog"
414    description="Create a changelog file for a release of Weka. Run with -Dsvn_username=username -Dsvn_password=password -Drelease=&lt;number of release (eg. 3-4-1)&gt;, -Ddate_range=&lt;date range for changes (eg. {2008-07-16}:{2008-09-29})&gt;, -Dweka_branch=&lt;branch name (e.g. trunk, branches/book2ndEd-branch)&gt;.">
415    <property name="repository.URL" value="https://svn.scms.waikato.ac.nz/svn/weka"/>
416    <java classname="org.tmatesoft.svn.cli.SVN" fork="true"
417          output="../wekadocs/changelogs/CHANGELOG-${release}">
418      <arg value="log"/>
419      <arg value="--username"/>
420      <arg value="${svn_username}"/>
421      <arg value="--password"/>
422      <arg value="${svn_password}"/>
423      <arg value="-r"/>
424      <arg value="${date_range}"/>
425      <arg value="-v"/>
426      <arg value="${repository.URL}/${weka_branch}/weka/src/main/java/weka"/>
427      <classpath>
428        <pathelement location="${ant.home}/lib/svnkit.jar" />
429        <pathelement location="${ant.home}/lib/svnkit-cli.jar" />
430      </classpath>
431    </java>
432  </target>
433
434  <!-- This target is used for an automated nightly/weekly build job -->
435  <target name="nightly_build"
436          depends="init_tests"
437          description="Does a svn checkout, builds, runs unit tests, and mails the output to mail recipients (run ant with -Dsvn_username=username -Dsvn_password=password -Dweka_branch=branch -Dmail_recipients=&lt;email,email,...&gt; -Dmail_sender=email -Dmail_smtp_host=smtp-server)">
438
439     <!-- run the build process -->
440     <ant antfile="${ant.file}" target="svnCheckout" output="${reports}/nightly_build-init.txt">
441       <property name="mail_smtp_host" value="${mail_smtp_host}"/>
442       <property name="mail_sender" value="${mail_sender}"/>
443       <property name="mail_recipients" value="${mail_recipients}"/>
444       <property name="svn_username" value="${svn_username}"/>
445       <property name="svn_password" value="${svn_password}"/>
446       <property name="weka_branch" value="${weka_branch}"/>
447     </ant>
448
449     <ant antfile="${ant.file}" dir="weka" target="run_tests" output="../${reports}/nightly_build-results.txt">
450       <property name="mail_smtp_host" value="${mail_smtp_host}"/>
451       <property name="mail_sender" value="${mail_sender}"/>
452       <property name="mail_recipients" value="${mail_recipients}"/>
453       <property name="run_tests_fail" value="false"/>
454       <property name="headless" value="${headless}"/>
455     </ant>
456
457     <!-- mail the results -->
458     <mail messageMimeType="text/html"
459               tolist="${mail_recipients}"
460               mailhost="${mail_smtp_host}"
461               subject="nightly build results (${weka_branch}): ${TODAY}"
462               from="${mail_sender}">
463       <fileset dir="${reports}">
464         <include name="nightly_build*.*"/>
465       </fileset>
466     </mail>
467  </target>
468
469
470<!-- Clean -->
471  <target name="clean" depends="init_all"
472   description="Removes the build, dist and reports directories">
473    <!-- Delete the ${build} and ${dist} directory trees -->
474    <delete dir="${build}"/>
475    <delete dir="${dist}"/>
476    <delete dir="${reports}"/>
477  </target>
478
479  <target name="superclean" depends="clean"
480   description="Clean plus removes source trees! and doc directories">
481  <!-- WARNING, this deletes the source and doc directories -->
482    <delete dir="${src}"/>
483    <delete dir="${doc}"/>
484  </target>
485</project>
Note: See TracBrowser for help on using the repository browser.