* New upstream release:
[debian/jabref.git] / build.xml
1 <?xml version="1.0"?>
2 <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3    Filename: $RCSfile: build.xml,v $
4    Purpose:  Ant build file for Jabref.
5
6              Ant-Download: http://jakarta.apache.org/ant
7              Ant-Manual:   http://jakarta.apache.org/ant/manual/index.html
8
9              Jabref-Homepage:    http://jabref.sourceforge.net
10              Jabref@SourceForge: http://sourceforge.net/projects/jabref
11              Jabref@FreshMeat:   http://freshmeat.net
12              Jabref-CVSRoot:     :pserver:anonymous@cvs.jabref.sourceforge.net:/cvsroot/jabref
13
14              Further questions:
15                help mailing list:      must be inserted
16
17    Precondition: 1. Ant should be installed.
18                  2. JAVA_HOME environment variable contains the path to JDK1.4 or higher
19                  3. ANT_HOME environment variable contains the path to ant's home directory
20
21    Language: XML
22    Compiler: Ant
23    Authors:  Joerg K. Wegner, wegnerj@informatik.uni-tuebingen.de
24              Morten O. Alver
25    Version:  $Revision: 1.77 $
26              $Date: 2006/11/23 22:37:19 $
27              $Author: coezbek $
28
29    modified:
30              23.11.2006 c.oezbek
31              - tried to fix classpath issues
32              28.07.2005 r.nagel
33              - insert dynamic build info generation (resource/build.properties)
34              - copy fonts directory, used by the new about dialog
35              - change static "version" into mainfest file into ${jabref.version}
36              09.06.2005 r.nagel
37              - bugfix, first it should be made a rebuild of the build directory
38              and then a jar should be generated from this directory
39              - take all files for the jar archive !!! FROM BUILD directory !!!
40
41 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
42
43 <project name="JabRef" default="jars" basedir=".">
44
45         <!-- ==========================================================================================
46         PROPERTY SETUP
47      ========================================================================================== -->
48
49         <!-- some version information -->
50         <property name="jabref.bin" value="JabRef-2.2" />
51         <property name="jabref.version" value="2.2b2" />
52         <property name="jabref.placeholder.version" value="@version@" />
53         <!-- used by replace task -->
54
55
56         <!-- Set the properties for intermediate directory -->
57         <property name="build.dir" value="build" />
58         <property name="build.classes" value="${build.dir}/classes" />
59         <property name="build.tmp" value="${build.dir}/tmp" />
60         <property name="build.osx" value="${build.dir}/classes/osxadapter" />
61         <property name="build.lib" value="${build.dir}/lib" />
62         <property name="build.win" value="${build.dir}/windows" />
63         <property name="build.images" value="${build.dir}/images" />
64         <property name="build.fonts" value="${build.dir}/images/font" />
65         <property name="build.resource" value="${build.dir}/resource" />
66         <property name="build.help" value="${build.dir}/help" />
67         <property name="build.javadocs" value="${build.dir}/docs/API" />
68         <property name="build.extensions" value="${build.dir}/extensions" />
69         <property name="build.extension-javadocs" value="${build.extensions}/API" />
70         <property name="build.extension-layout" value="${build.extensions}/layout" />
71         <property name="build.openoffice.meta" value="${build.resource}/openoffice" />
72
73         <!-- Set the properties for source directories -->
74         <property name="src.dir" value="src" />
75         <property name="src.tests" value="src/java/tests" />
76         <property name="txt.dir" value="src/txt" />
77         <property name="java.dir" value="${src.dir}/java" />
78         <property name="osx.dir" value="${src.dir}/osx" />
79         <property name="win.installer.dir" value="${src.dir}/windows/nsis" />
80         <property name="resource.dir" value="${src.dir}/resource" />
81         <property name="bin.dir" value="${src.dir}/scripts" />
82         <property name="images.dir" value="${src.dir}/images" />
83         <property name="fonts.dir" value="${src.dir}/images/font" />
84         <property name="help.dir" value="${src.dir}/help" />
85         <property name="extensions.dir" value="${src.dir}/extensions" />
86         <property name="layout.dir" value="${src.dir}/resource/layout" />
87
88         <!-- Set the properties for library directories -->
89         <property name="library.directory" value="lib" />
90
91         <!-- Load user dependent properties -->
92         <property file="build.properties" />
93         <!-- 
94            * For instance define the NSIS-compiler:
95            *   nsis.executable="d:\prog\dev\NSIS\makensis.exe" 
96            *-->
97
98         <!-- win.installer can only be build under Windows -->
99         <condition property="is.windows">
100                 <and>
101                         <os family="windows" />
102                         <isset property="nsis.executable" />
103                 </and>
104         </condition>
105
106         <taskdef name="jarbundler" classpath="${library.directory}/jarbundler-1.4.jar" classname="com.loomcom.ant.tasks.jarbundler.JarBundler" />
107
108
109         <!-- Build classpath -->
110         <path id="classpath">
111                 <pathelement path="${build.classes}" />
112                 <pathelement path="${build.dir}" />
113                 <pathelement location="${library.directory}/antlr.jar" />
114                 <pathelement location="${library.directory}/antlr-3.0b5.jar" />
115                 <pathelement location="${library.directory}/looks-2.0.4.jar" />
116                 <pathelement location="${library.directory}/forms-1.0.4.jar" />
117                 <pathelement location="${library.directory}/spin.jar" />
118                 <pathelement location="${library.directory}/glazedlists-1.7.0_java14.jar" />
119                 <pathelement location="${library.directory}/microba.jar" />
120         <pathelement location="${library.directory}/PDFBox-0.7.3-dev-reduced.jar" />
121         <pathelement location="${library.directory}/JempBox-0.1.0-dev.jar" />
122         </path>
123         
124         <target name="run" depends="build">
125                 <java classname="net.sf.jabref.JabRef" fork="true">
126                         <classpath refid="classpath"/>
127                 </java>
128         </target>
129         
130         <!-- Runs project -->
131         <target name="runFromJar" depends="jars">
132                 <java classname="net.sf.jabref.JabRef" fork="true">
133                         <classpath>
134                                 <pathelement location="${build.lib}/jabref.jar" />
135                         </classpath>
136                 </java>
137         </target>
138
139         <target name="profile" depends="jars" description="Profile JabRef">
140                 <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
141
142                 <nbprofiledirect>
143                         <classpath refid="classpath"/>
144                 </nbprofiledirect>
145
146                 <property environment="env" />
147                 <java fork="true" classname="net.sf.jabref.JabRef" dir="${build.dir}" jvm="${profiler.info.jvm}">
148                         <jvmarg value="${profiler.info.jvmargs.agent}" />
149                         <jvmarg line="${profiler.info.jvmargs}" />
150                         <env key="LD_LIBRARY_PATH" path="${profiler.info.agentpath}:${env.LD_LIBRARY_PATH}" />
151                         <classpath refid="classpath"/>
152                 </java>
153         </target>
154
155         <!-- Compiles project -->
156         <target name="compile">
157                 <mkdir dir="${build.classes}" />
158                 <javac debug="on" deprecation="on" destdir="${build.classes}" source="1.4" target="1.4">
159                         <src path="${java.dir}" />
160                         <exclude name="tests/**" />
161                         <classpath refid="classpath"/>
162                 </javac>
163         </target>
164
165         <!-- Compiles only the tests -->
166         <target name="compiletest">
167                 <mkdir dir="${build.classes}" />
168                 <!--deprecation="on"-->
169                 <javac srcdir="${java.dir}/tests" debug="off" destdir="${build.classes}" source="1.4" target="1.4">
170                         <classpath refid="classpath"/>
171                 </javac>
172         </target>
173
174         <!-- Builds the OSXAdapter -->
175         <target name="osx">
176                 <mkdir dir="${build.classes}" />
177
178                 <javac srcdir="${osx.dir}" debug="on" destdir="${build.classes}" target="1.4">
179                 </javac>
180         </target>
181
182         <!-- Copies in the OSXAdapter class, which is compilable only on Mac  -->
183         <target name="non_osx">
184                 <mkdir dir="${build.osx}" />
185                 <copy file="${library.directory}/OSXAdapter.class" todir="${build.osx}" />
186         </target>
187
188         <!-- Jars up project -->
189         <target name="jars" depends="build, unjarlib">
190                 <mkdir dir="${build.lib}" />
191                 <mkdir dir="${build.tmp}" />
192                 <jar destfile="${build.lib}/jabref.jar">
193
194                         <fileset dir="${build.classes}" />
195                         <fileset dir="${build.tmp}" />
196                         <fileset dir="${build.dir}">
197                                 <include name="images/**" />
198                                 <include name="help/**" />
199                                 <include name="help/de/**" />
200                                 <include name="help/no/**" />
201                                 <include name="resource/**" />
202                         </fileset>
203                         <fileset dir="${library.directory}">
204                                 <include name="EndNote.zip" />
205                         </fileset>
206                         <fileset dir="${txt.dir}">
207                                 <include name="gpl.txt" />
208                                 <include name="lesser.txt" />
209                                 <include name="jgoodies.txt" />
210                                 <include name="README" />
211                         </fileset>
212                         <manifest>
213                                 <attribute name="Main-Class" value="net.sf.jabref.JabRef" />
214                         </manifest>
215                 </jar>
216
217         </target>
218
219         <!-- copy all necessary files and insert version informations -->
220         <target name="build" depends="compile, buildinfos" description="Build project">
221
222                 <mkdir dir="${build.resource}" />
223
224                 <copy todir="${build.resource}">
225                         <fileset dir="${resource.dir}">
226                                 <include name="**" />
227                         </fileset>
228                 </copy>
229                 <mkdir dir="${build.images}" />
230                 <copy todir="${build.images}">
231                         <fileset dir="${images.dir}">
232                                 <include name="**" />
233                         </fileset>
234                 </copy>
235
236                 <!-- the fonts are used by the new about dialog
237                 <mkdir dir="${build.fonts}" />
238                 <copy todir="${build.fonts}">
239                         <fileset dir="${fonts.dir}">
240                                 <include name="*" />
241                         </fileset>
242                 </copy> -->
243
244                 <mkdir dir="${build.help}" />
245                 <copy todir="${build.help}">
246                         <fileset dir="${help.dir}">
247                                 <!--<include name="*" />-->
248                         </fileset>
249                 </copy>
250
251                 <!-- Insert version informations -->
252                 <replace dir="${build.help}" token="${jabref.placeholder.version}" value="${jabref.version}">
253                         <include name="**/About.html" />
254                 </replace>
255                 <replace dir="${build.openoffice.meta}" token="${jabref.placeholder.version}" value="${jabref.version}">
256                         <include name="meta.xml" />
257                 </replace>
258
259         </target>
260
261         <!-- generate and save some build infos !!! necessary for dynamic build infos !!! -->
262         <!-- todo : replace it by the replace task :-),
263           src/resource/build.properties = template
264           build/resource/build.properties = real info file
265         -->
266         <target name="buildinfos">
267                 <tstamp />
268                 <!-- get date -->
269                 <buildnumber />
270                 <!-- generate new build number -> build.number -->
271                 <echo message="build number = ${build.number}" />
272                 <!-- write the file, please do not edit this lines -->
273                 <echo file="${resource.dir}/build.properties">builddate=${TODAY}
274 build=${build.number}
275 version=${jabref.version}</echo>
276         </target>
277
278
279         <!-- Creates all docs -->
280         <target name="docs" depends="javadocs" description="Generates all the documentation" />
281
282         <!-- Creates javadocs -->
283         <target name="javadocs" depends="compile" description="Generates the javadocs">
284                 <mkdir dir="${build.javadocs}" />
285                 <javadoc sourcepath="${java.dir}" destdir="${build.javadocs}" author="true" version="true" windowtitle="JabRef API" link="http://java.sun.com/j2se/1.4.1/docs/api/">
286
287                         <fileset dir="${java.dir}" defaultexcludes="yes">
288                                 <include name="**/*.java" />
289                         </fileset>
290
291                         <classpath refid="classpath" />
292                 </javadoc>
293         </target>
294
295         <!-- Creates javadocs for the extensions -->
296         <target name="extension-javadocs" depends="build" description="Generates the javadocs for the extensions archive">
297                 <mkdir dir="${build.extension-javadocs}" />
298                 <copy todir="${build.extension-javadocs}">
299                         <fileset dir="${help.dir}" defaultexcludes="yes">
300                                 <include name="CustomExports.html" />
301                                 <include name="CustomImports.html" />
302                         </fileset>
303                 </copy>
304
305                 <javadoc sourcepath="${java.dir}" destdir="${build.extension-javadocs}" author="true" version="true" windowtitle="JabRef-Extensions API" link="http://java.sun.com/j2se/1.4.1/docs/api/" Overview="${extensions.dir}/API/overview.html" access="protected">
306                         <!-- 
307                  create javadoc only selectively for classes that 
308                  users extending JabRef are likely to use
309               -->
310                         <fileset dir="${java.dir}" defaultexcludes="yes">
311                                 <include name="net/sf/jabref/imports/ImportFormat.java" />
312                                 <include name="net/sf/jabref/imports/ImportFormatReader.java" />
313                                 <include name="net/sf/jabref/BibtexEntry.java" />
314                                 <include name="net/sf/jabref/BibtexEntryType.java" />
315                                 <include name="net/sf/jabref/AuthorList.java" />
316                                 <include name="net/sf/jabref/AuthorList.java" />
317                                 <include name="net/sf/jabref/export/layout/LayoutFormatter.java" />
318                         </fileset>
319
320                         <classpath refid="classpath" />
321                 </javadoc>
322         </target>
323
324         <!-- Creates javadocs for the extensions -->
325         <target name="extensions" depends="extension-javadocs" description="Generates the extensions archive">
326                 <!-- copy examples -->
327                 <copy todir="${build.extensions}">
328                         <fileset dir="${java.dir}">
329                                 <include name="net/sf/jabref/export/layout/format/CurrentDate.java" />
330                                 <include name="net/sf/jabref/export/layout/format/ToLowerCase.java" />
331                                 <include name="net/sf/jabref/export/layout/format/HTMLChars.java" />
332                                 <include name="net/sf/jabref/imports/*Importer.java" />
333                         </fileset>
334                 </copy>
335                 <mkdir dir="${build.extension-layout}" />
336                 <copy todir="${build.extension-layout}">
337                         <fileset dir="${layout.dir}" />
338                 </copy>
339                 <copy todir="${build.extensions}">
340                         <fileset dir="${extensions.dir}" />
341                         <filterset>
342                                 <filter token="version" value="${jabref.version}" />
343                         </filterset>
344                 </copy>
345                 <!-- create extensions-zip file -->
346                 <zip destfile="${build.dir}/jabref-extensions.zip">
347                         <zipfileset dir="${build.extensions}" prefix="jabref-extensions" />
348                 </zip>
349         </target>
350
351         <target name="clean" depends="win.installer.clean" description="Clean project">
352                 <delete dir="${build.dir}" />
353         </target>
354
355         <!-- Unpacks jar needed jar files from lib directory into temp directory. -->
356         <target name="unjarlib" description="Unpacks jars from library">
357                 <mkdir dir="${build.tmp}" />
358                 <unjar src="${library.directory}/antlr.jar" dest="${build.tmp}" />
359                 <unjar src="${library.directory}/antlr-3.0b5.jar" dest="${build.tmp}" />
360                 <unjar src="${library.directory}/looks-2.0.4.jar" dest="${build.tmp}" />
361                 <unjar src="${library.directory}/forms-1.0.4.jar" dest="${build.tmp}" />
362                 <unjar src="${library.directory}/spin.jar" dest="${build.tmp}" />
363                 <unjar src="${library.directory}/glazedlists-1.7.0_java14.jar" dest="${build.tmp}" />
364                 <unjar src="${library.directory}/microba.jar" dest="${build.tmp}" />
365         <unjar src="${library.directory}/PDFBox-0.7.3-dev-reduced.jar" dest="${build.tmp}" />
366         <unjar src="${library.directory}/JempBox-0.1.0-dev.jar" dest="${build.tmp}" />
367         <delete dir="${build.tmp}/META-INF" />
368                 <!-- rename the microba license file -->
369                 <move file="${build.tmp}/license.txt" tofile="${build.tmp}/microba-license.txt" />
370         </target>
371
372
373         <target name="osxjar">
374                 <jarbundler dir="${build.lib}" name="JabRef" mainclass="net.sf.jabref.JabRef" jars="${build.lib}/jabref.jar" icon="${images.dir}/JabRef-Logo.icns" version="${jabref.version}" jvmversion="1.4+" stubfile="${library.directory}/JavaApplicationStub" />
375         </target>
376
377
378         <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
379         <!-- Build Windows Installer                                                    -->
380         <!--                                                                            -->
381         <!-- Don't forget to set nsis.executable property                               -->
382         <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
383
384         <target name="win.installer.clean" description="Delete Installer and Exe-Wrapper + Temp-files">
385                 <delete dir="${win.installer.dir}/dist" />
386                 <delete file="${win.installer.dir}/JabRefSetup.exe" />
387         </target>
388
389         <target name="win.installer.prepare" depends="jars" if="is.windows" description="Copy files in place to be used by the installer">
390                 <!-- Gather everything that will go into the installer in dist -->
391                 <mkdir dir="${win.installer.dir}/dist" />
392                 <!--            <copy file="${build.lib}/${jabref.bin}.jar" 
393                 todir="${win.installer.dir}/dist" /> -->
394                 <copy todir="${win.installer.dir}/dist">
395                         <fileset dir="${txt.dir}">
396                                 <include name="gpl.txt" />
397                                 <include name="lesser.txt" />
398                                 <include name="README" />
399                         </fileset>
400                 </copy>
401         </target>
402
403         <target name="win.installer.exewrapper" depends="win.installer.prepare" if="is.windows" description="Create Exe-Wrapper">
404                 <exec dir="." executable="${nsis.executable}" failonerror="true">
405                         <arg line="'/DJARFILE=${jabref.bin}.jar' '/DVERSION=${jabref.version}' '/DAPPICON=../../../${images.dir}/JabRef.ico' ${win.installer.dir}/launcher.nsi" />
406                 </exec>
407         </target>
408
409         <target name="win.installer.build" depends="win.installer.exewrapper" if="is.windows" description="Create Windows-Installer.">
410                 <exec dir="." executable="${nsis.executable}" failonerror="true">
411                         <arg line="'/DVERSION=${jabref.version}' ${win.installer.dir}/setup.nsi" />
412                 </exec>
413         </target>
414
415         <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
416         What's about the software design ?!;-)
417     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
418
419         <target name="pmd" description="SOFTWAREDESIGN: Project Mess Detector !;-)">
420                 <echo>Checking Project Mess Detection (PMD) rulesets.</echo>
421                 <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
422                         <classpath>
423                                 <pathelement path="${classpath}" />
424                                 <fileset dir="${library.directory}">
425                                         <include name="*.jar" />
426                                 </fileset>
427                         </classpath>
428                 </taskdef>
429                 <!-- allowed Pretty Much Done rulsets -->
430                 <!-- rulesets/basic.xml -->
431                 <!-- rulesets/braces.xml -->
432                 <!-- rulesets/codesize.xml-->
433                 <!-- rulesets/controversial.xml-->
434                 <!-- rulesets/coupling.xml-->
435                 <!-- rulesets/design.xml -->
436                 <!-- rulesets/experimental.xml -->
437                 <!-- rulesets/favorites.xml -->
438                 <!-- rulesets/imports.xml -->
439                 <!-- rulesets/naming.xml -->
440                 <!-- rulesets/javabean.xml -->
441                 <!-- rulesets/junit.xml -->
442                 <!-- rulesets/scratchpad.xml -->
443                 <!-- rulesets/strictexception.xml -->
444                 <!-- rulesets/strings.xml -->
445                 <!-- rulesets/unusedcode.xml -->
446
447                 <pmd rulesetfiles="rulesets/unusedcode.xml,rulesets/basic.xml" failonerror="no">
448                         <formatter type="html" toFile="${build.dir}/pmd_report.html" />
449                         <fileset dir="${src.dir}">
450                                 <include name="**/*.java" />
451                         </fileset>
452                 </pmd>
453
454                 <!-- check for duplicated code -->
455                 <echo>WARNING: use environment variable: ANT_OPTS=-Xmx512m or this task will fail.</echo>
456                 <echo>Checking for duplicated code using the Copy/Paste Detector (CPD).</echo>
457                 <taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask">
458                         <classpath>
459                                 <pathelement path="${classpath}" />
460                                 <fileset dir="${library.directory}">
461                                         <include name="*.jar" />
462                                 </fileset>
463                         </classpath>
464                 </taskdef>
465                 <cpd format="text" minimumTokenCount="100" outputFile="${build.dir}/duplicated_code_report.txt">
466                         <fileset dir="${src.dir}">
467                                 <include name="**/*.java" />
468                         </fileset>
469                 </cpd>
470         </target>
471
472
473         <target name="javancss" description="SOFTWAREDESIGN: Determining the NCSS and CCN code metrics for JOELib.">
474                 <taskdef name="javancss" classname="javancss.JavancssAntTask">
475                         <classpath>
476                                 <pathelement path="${classpath}" />
477                                 <fileset dir="${library.directory}">
478                                         <include name="*.jar" />
479                                 </fileset>
480                         </classpath>
481                 </taskdef>
482                 <echo>Cyclomatic
483 Complexity             Ease of       Risk
484 Number (CCN)           maintenance
485 (McCabe metric)
486 ---------------------------------------------
487 1-10, simple           easy          minimum
488 11-20, complex         moderate      moderate
489 21-50, more complex    hard          high
490 >50, unstable          very hard     very high
491
492 </echo>
493                 <javancss srcdir="${src.dir}" includes="**/*.java" excludes="jama/**/*.java, jmat/**/*.java, cformat/**/*.java" abortOnFail="false" ccnPerFuncMax="30" generateReport="true" outputfile="${build.dir}/javancss_report.plain" format="plain" packageMetrics="true" classMetrics="false" functionMetrics="false" />
494         </target>
495
496         <target name="jalopy" description="SOFTWAREDESIGN: source code formatter using the JOELib convention.">
497                 <taskdef name="jalopy" classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
498                         <classpath>
499                                 <pathelement path="${classpath}" />
500                                 <fileset dir="${library.directory}">
501                                         <include name="*.jar" />
502                                 </fileset>
503                         </classpath>
504                 </taskdef>
505                 <jalopy fileformat="unix" convention="${src.dir}/java/jalopy.format.convention.xml" history="file" historymethod="adler32" loglevel="error" threads="2" classpathref="classpath" backup="bak">
506                         <fileset dir="${src.dir}">
507                                 <include name="java/net/sf/jabref/**/*.java" />
508                         </fileset>
509                 </jalopy>
510         </target>
511
512         <target name="test">
513                 <junit printsummary="yes" fork="yes" haltonfailure="no">
514                         <batchtest fork="yes" todir="/tmp/testres">
515                                 <fileset dir="${build.classes}">
516                                         <include name="**/*Tester.class" />
517                                         <include name="**/*Test.class" />
518                                 </fileset>
519                         </batchtest>
520                         <classpath refid="classpath"/>
521                 </junit>
522         </target>
523  
524 </project>