* 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.5 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.82.2.1 $
26              $Date: 2007/06/20 18:51:59 $
27              $Author: mortenalver $
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.version" value="2.3b" />
51         <property name="jabref.placeholder.version" value="@version@" />
52         <!-- used by replace task -->
53
54
55         <!-- Set the properties for intermediate directory -->
56         <property name="build.jar" value="JabRef-${jabref.version}.jar" />
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 <!--    <property name="nsis.executable" value="makensis.exe"/> -->
92
93         <!-- Load user dependent properties -->
94         <!-- For instance to redefine the NSIS-compiler write 
95                 nsis.executable="d:\prog\dev\NSIS\makensis.exe"
96           -->
97         <property file="user.properties" />
98
99         <!-- win.installer can only be build under Windows if the nsis.executable is found -->
100         <condition property="is.windows">
101                 <and>
102                         <os family="windows" />
103                         <isset property="nsis.executable" />
104                 </and>
105         </condition>
106
107         <taskdef name="jarbundler" classpath="${library.directory}/jarbundler-1.4.jar" classname="com.loomcom.ant.tasks.jarbundler.JarBundler" />
108
109
110         <!-- Build classpath -->
111         <path id="classpath">
112                 <pathelement path="${build.classes}" />
113                 <pathelement path="${build.dir}" />
114                 <pathelement location="${library.directory}/antlr.jar" />
115                 <pathelement location="${library.directory}/antlr-3.0b5.jar" />
116                 <pathelement location="${library.directory}/looks-2.0.4.jar" />
117                 <pathelement location="${library.directory}/forms-1.0.4.jar" />
118                 <pathelement location="${library.directory}/spin.jar" />
119                 <pathelement location="${library.directory}/glazedlists-1.7.0_java15.jar" />
120                 <pathelement location="${library.directory}/microba.jar" />
121                 <pathelement location="${library.directory}/PDFBox-0.7.3-dev-reduced.jar" />
122                 <pathelement location="${library.directory}/JempBox-0.1.0-dev.jar" />
123         </path>
124
125         <target name="run" depends="build">
126                 <java classname="net.sf.jabref.JabRef" fork="true">
127                         <classpath refid="classpath" />
128                 </java>
129         </target>
130
131         <!-- Runs project -->
132         <target name="runFromJar" depends="jars">
133                 <java classname="net.sf.jabref.JabRef" fork="true">
134                         <classpath>
135                                 <pathelement location="${build.lib}/${build.jar}" />
136                         </classpath>
137                 </java>
138         </target>
139
140         <target name="profile" depends="jars" description="Profile JabRef">
141                 <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
142
143                 <nbprofiledirect>
144                         <classpath refid="classpath" />
145                 </nbprofiledirect>
146
147                 <property environment="env" />
148                 <java fork="true" classname="net.sf.jabref.JabRef" dir="${build.dir}" jvm="${profiler.info.jvm}">
149                         <jvmarg value="${profiler.info.jvmargs.agent}" />
150                         <jvmarg line="${profiler.info.jvmargs}" />
151                         <env key="LD_LIBRARY_PATH" path="${profiler.info.agentpath}:${env.LD_LIBRARY_PATH}" />
152                         <classpath refid="classpath" />
153                 </java>
154         </target>
155
156         <!-- Compiles project -->
157         <target name="compile">
158                 <mkdir dir="${build.classes}" />
159                 <javac debug="on" deprecation="on" destdir="${build.classes}" source="1.5" target="1.5">
160                         <src path="${java.dir}" />
161                         <exclude name="tests/**" />
162                         <classpath refid="classpath" />
163                 </javac>
164         </target>
165
166         <!-- Compiles only the tests -->
167         <target name="compiletest">
168                 <mkdir dir="${build.classes}" />
169                 <!--deprecation="on"-->
170                 <javac srcdir="${java.dir}/tests" debug="off" destdir="${build.classes}" source="1.5" target="1.5">
171                         <classpath refid="classpath" />
172                 </javac>
173         </target>
174
175         <!-- Builds the OSXAdapter -->
176         <target name="osx">
177                 <mkdir dir="${build.classes}" />
178
179                 <javac srcdir="${osx.dir}" debug="on" destdir="${build.classes}" target="1.5">
180                 </javac>
181         </target>
182
183         <!-- Copies in the OSXAdapter class, which is compilable only on Mac  -->
184         <target name="non_osx">
185                 <mkdir dir="${build.osx}" />
186                 <copy file="${library.directory}/OSXAdapter.class" todir="${build.osx}" />
187         </target>
188
189         <!-- Jars up project -->
190         <target name="jars" depends="build, unjarlib">
191                 <mkdir dir="${build.lib}" />
192                 <mkdir dir="${build.tmp}" />
193                 <jar destfile="${build.lib}/${build.jar}">
194
195                         <fileset dir="${build.classes}" />
196                         <fileset dir="${build.tmp}" />
197                         <fileset dir="${build.dir}">
198                                 <include name="images/**" />
199                                 <include name="help/**" />
200                                 <include name="help/de/**" />
201                                 <include name="help/no/**" />
202                                 <include name="resource/**" />
203                         </fileset>
204                         <fileset dir="${library.directory}">
205                                 <include name="EndNote.zip" />
206                         </fileset>
207                         <fileset dir="${txt.dir}">
208                                 <include name="gpl.txt" />
209                                 <include name="lesser.txt" />
210                                 <include name="jgoodies.txt" />
211                                 <include name="README" />
212                         </fileset>
213                         <manifest>
214                                 <attribute name="Main-Class" value="net.sf.jabref.JabRef" />
215                         </manifest>
216                 </jar>
217
218         </target>
219
220         <!-- copy all necessary files and insert version informations -->
221         <target name="build" depends="compile, buildinfos" description="Build project">
222
223                 <mkdir dir="${build.resource}" />
224
225                 <copy todir="${build.resource}">
226                         <fileset dir="${resource.dir}">
227                                 <include name="**" />
228                         </fileset>
229                 </copy>
230                 <mkdir dir="${build.images}" />
231                 <copy todir="${build.images}">
232                         <fileset dir="${images.dir}">
233                                 <include name="**" />
234                         </fileset>
235                 </copy>
236
237                 <!-- the fonts are used by the new about dialog
238                 <mkdir dir="${build.fonts}" />
239                 <copy todir="${build.fonts}">
240                         <fileset dir="${fonts.dir}">
241                                 <include name="*" />
242                         </fileset>
243                 </copy> -->
244
245                 <mkdir dir="${build.help}" />
246                 <copy todir="${build.help}">
247                         <fileset dir="${help.dir}">
248                                 <!--<include name="*" />-->
249                         </fileset>
250                 </copy>
251
252                 <!-- Insert version informations -->
253                 <replace dir="${build.help}" token="${jabref.placeholder.version}" value="${jabref.version}">
254                         <include name="**/About.html" />
255                 </replace>
256                 <replace dir="${build.openoffice.meta}" token="${jabref.placeholder.version}" value="${jabref.version}">
257                         <include name="meta.xml" />
258                 </replace>
259
260         </target>
261
262         <!-- generate and save some build infos !!! necessary for dynamic build infos !!! -->
263         <!-- todo : replace it by the replace task :-),
264           src/resource/build.properties = template
265           build/resource/build.properties = real info file
266         -->
267         <target name="buildinfos">
268                 <tstamp />
269                 <!-- get date -->
270                 <buildnumber />
271                 <!-- generate new build number -> build.number -->
272                 <echo message="build number = ${build.number}" />
273                 <!-- write the file, please do not edit this lines -->
274                 <echo file="${resource.dir}/build.properties">builddate=${TODAY}
275 build=${build.number}
276 version=${jabref.version}</echo>
277         </target>
278
279
280         <!-- Creates all docs -->
281         <target name="docs" depends="javadocs" description="Generates all the documentation" />
282
283         <!-- Creates javadocs -->
284         <target name="javadocs" depends="compile" description="Generates the javadocs">
285                 <mkdir dir="${build.javadocs}" />
286                 <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/">
287
288                         <fileset dir="${java.dir}" defaultexcludes="yes">
289                                 <include name="**/*.java" />
290                         </fileset>
291
292                         <classpath refid="classpath" />
293                 </javadoc>
294         </target>
295
296         <!-- Creates javadocs for the extensions -->
297         <target name="extension-javadocs" depends="build" description="Generates the javadocs for the extensions archive">
298                 <mkdir dir="${build.extension-javadocs}" />
299                 <copy todir="${build.extension-javadocs}">
300                         <fileset dir="${help.dir}" defaultexcludes="yes">
301                                 <include name="CustomExports.html" />
302                                 <include name="CustomImports.html" />
303                         </fileset>
304                 </copy>
305
306                 <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">
307                         <!-- 
308                  create javadoc only selectively for classes that 
309                  users extending JabRef are likely to use
310               -->
311                         <fileset dir="${java.dir}" defaultexcludes="yes">
312                                 <include name="net/sf/jabref/imports/ImportFormat.java" />
313                                 <include name="net/sf/jabref/imports/ImportFormatReader.java" />
314                                 <include name="net/sf/jabref/BibtexEntry.java" />
315                                 <include name="net/sf/jabref/BibtexEntryType.java" />
316                                 <include name="net/sf/jabref/AuthorList.java" />
317                                 <include name="net/sf/jabref/AuthorList.java" />
318                                 <include name="net/sf/jabref/export/layout/LayoutFormatter.java" />
319                         </fileset>
320
321                         <classpath refid="classpath" />
322                 </javadoc>
323         </target>
324
325         <!-- Creates javadocs for the extensions -->
326         <target name="extensions" depends="extension-javadocs" description="Generates the extensions archive">
327                 <!-- copy examples -->
328                 <copy todir="${build.extensions}">
329                         <fileset dir="${java.dir}">
330                                 <include name="net/sf/jabref/export/layout/format/CurrentDate.java" />
331                                 <include name="net/sf/jabref/export/layout/format/ToLowerCase.java" />
332                                 <include name="net/sf/jabref/export/layout/format/HTMLChars.java" />
333                                 <include name="net/sf/jabref/imports/*Importer.java" />
334                         </fileset>
335                 </copy>
336                 <mkdir dir="${build.extension-layout}" />
337                 <copy todir="${build.extension-layout}">
338                         <fileset dir="${layout.dir}" />
339                 </copy>
340                 <copy todir="${build.extensions}">
341                         <fileset dir="${extensions.dir}" />
342                         <filterset>
343                                 <filter token="version" value="${jabref.version}" />
344                         </filterset>
345                 </copy>
346                 <!-- create extensions-zip file -->
347                 <zip destfile="${build.dir}/jabref-extensions.zip">
348                         <zipfileset dir="${build.extensions}" prefix="jabref-extensions" />
349                 </zip>
350         </target>
351
352         <target name="clean" depends="win.installer.clean" description="Clean project">
353                 <delete dir="${build.dir}" />
354         </target>
355
356         <!-- Unpacks jar needed jar files from lib directory into temp directory. -->
357         <target name="unjarlib" description="Unpacks jars from library">
358                 <mkdir dir="${build.tmp}" />
359                 <unjar src="${library.directory}/antlr.jar" dest="${build.tmp}" />
360                 <unjar src="${library.directory}/antlr-3.0b5.jar" dest="${build.tmp}" />
361                 <unjar src="${library.directory}/looks-2.0.4.jar" dest="${build.tmp}" />
362                 <unjar src="${library.directory}/forms-1.0.4.jar" dest="${build.tmp}" />
363                 <unjar src="${library.directory}/spin.jar" dest="${build.tmp}" />
364                 <unjar src="${library.directory}/glazedlists-1.7.0_java15.jar" dest="${build.tmp}" />
365                 <unjar src="${library.directory}/microba.jar" dest="${build.tmp}" />
366                 <unjar src="${library.directory}/PDFBox-0.7.3-dev-reduced.jar" dest="${build.tmp}" />
367                 <unjar src="${library.directory}/JempBox-0.1.0-dev.jar" dest="${build.tmp}" />
368                 <delete dir="${build.tmp}/META-INF" />
369                 <!-- rename the microba license file -->
370                 <move file="${build.tmp}/license.txt" tofile="${build.tmp}/microba-license.txt" />
371         </target>
372
373
374         <target name="osxjar">
375                 <jarbundler dir="${build.lib}" name="JabRef" mainclass="net.sf.jabref.JabRef" jars="${build.lib}/${build.jar}" icon="${images.dir}/JabRef-Logo.icns" version="${jabref.version}" jvmversion="1.4+" stubfile="${library.directory}/JavaApplicationStub" />
376         </target>
377
378
379         <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
380         <!-- Build Windows Installer                                                    -->
381         <!--                                                                            -->
382         <!-- Don't forget to set nsis.executable property                               -->
383         <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
384
385         <target name="win.installer.clean" description="Delete Installer and Exe-Wrapper + Temp-files">
386                 <delete failonerror="false" dir="${win.installer.dir}/dist" />
387                 <delete file="${win.installer.dir}/JabRefSetup.exe" />
388         </target>
389
390         <target name="win.installer" description="Copy files in place to be used by the installer" depends="jars">
391
392                 <fail unless="is.windows" message="Not running on windows or NSIS not found. Please make sure that user.properties exists"/>
393                 
394                 <!-- Gather everything that will go into the installer in dist -->
395                 <mkdir dir="${win.installer.dir}/dist" />
396
397                 <copy file="${build.lib}/${build.jar}" 
398                 todir="${win.installer.dir}/dist" />
399
400                 <available property="win.installer.jar.available" file="${win.installer.dir}/dist/${build.jar}"/>
401                 
402                 <fail unless="win.installer.jar.available" message="Did not find jar: ${build.jar}"/>
403                 
404                 <copy todir="${win.installer.dir}/dist">
405                         <fileset dir="${txt.dir}">
406                                 <include name="gpl.txt" />
407                                 <include name="lesser.txt" />
408                                 <include name="README" />
409                         </fileset>
410                 </copy>
411
412                 <!-- "Create Exe-Wrapper" -->
413                 <exec dir="." executable="${nsis.executable}" failonerror="true">
414                         <arg line="'/DJARFILE=${build.jar}' '/DVERSION=${jabref.version}' '/DAPPICON=../../../${images.dir}/JabRef.ico' ${win.installer.dir}/launcher.nsi" />
415                 </exec>
416
417                 <!-- Finally create Windows-Installer -->
418                 <exec dir="." executable="${nsis.executable}" failonerror="true">
419                         <arg line="'/DVERSION=${jabref.version}' ${win.installer.dir}/setup.nsi" />
420                 </exec>
421                 
422                 <delete dir="${win.installer.dir}/dist" />
423                 
424         </target>
425
426         <!--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
427         What's about the software design ?!;-)
428     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-->
429
430         <target name="pmd" description="SOFTWAREDESIGN: Project Mess Detector !;-)">
431                 <echo>Checking Project Mess Detection (PMD) rulesets.</echo>
432                 <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
433                         <classpath>
434                                 <pathelement path="${classpath}" />
435                                 <fileset dir="${library.directory}">
436                                         <include name="*.jar" />
437                                 </fileset>
438                         </classpath>
439                 </taskdef>
440                 <!-- allowed Pretty Much Done rulsets -->
441                 <!-- rulesets/basic.xml -->
442                 <!-- rulesets/braces.xml -->
443                 <!-- rulesets/codesize.xml-->
444                 <!-- rulesets/controversial.xml-->
445                 <!-- rulesets/coupling.xml-->
446                 <!-- rulesets/design.xml -->
447                 <!-- rulesets/experimental.xml -->
448                 <!-- rulesets/favorites.xml -->
449                 <!-- rulesets/imports.xml -->
450                 <!-- rulesets/naming.xml -->
451                 <!-- rulesets/javabean.xml -->
452                 <!-- rulesets/junit.xml -->
453                 <!-- rulesets/scratchpad.xml -->
454                 <!-- rulesets/strictexception.xml -->
455                 <!-- rulesets/strings.xml -->
456                 <!-- rulesets/unusedcode.xml -->
457
458                 <pmd rulesetfiles="rulesets/unusedcode.xml,rulesets/basic.xml" failonerror="no">
459                         <formatter type="html" toFile="${build.dir}/pmd_report.html" />
460                         <fileset dir="${src.dir}">
461                                 <include name="**/*.java" />
462                         </fileset>
463                 </pmd>
464
465                 <!-- check for duplicated code -->
466                 <echo>WARNING: use environment variable: ANT_OPTS=-Xmx512m or this task will fail.</echo>
467                 <echo>Checking for duplicated code using the Copy/Paste Detector (CPD).</echo>
468                 <taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask">
469                         <classpath>
470                                 <pathelement path="${classpath}" />
471                                 <fileset dir="${library.directory}">
472                                         <include name="*.jar" />
473                                 </fileset>
474                         </classpath>
475                 </taskdef>
476                 <cpd format="text" minimumTokenCount="100" outputFile="${build.dir}/duplicated_code_report.txt">
477                         <fileset dir="${src.dir}">
478                                 <include name="**/*.java" />
479                         </fileset>
480                 </cpd>
481         </target>
482
483
484         <target name="javancss" description="SOFTWAREDESIGN: Determining the NCSS and CCN code metrics for JOELib.">
485                 <taskdef name="javancss" classname="javancss.JavancssAntTask">
486                         <classpath>
487                                 <pathelement path="${classpath}" />
488                                 <fileset dir="${library.directory}">
489                                         <include name="*.jar" />
490                                 </fileset>
491                         </classpath>
492                 </taskdef>
493                 <echo>Cyclomatic
494 Complexity             Ease of       Risk
495 Number (CCN)           maintenance
496 (McCabe metric)
497 ---------------------------------------------
498 1-10, simple           easy          minimum
499 11-20, complex         moderate      moderate
500 21-50, more complex    hard          high
501 >50, unstable          very hard     very high
502
503 </echo>
504                 <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" />
505         </target>
506
507         <target name="jalopy" description="SOFTWAREDESIGN: source code formatter using the JOELib convention.">
508                 <taskdef name="jalopy" classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
509                         <classpath>
510                                 <pathelement path="${classpath}" />
511                                 <fileset dir="${library.directory}">
512                                         <include name="*.jar" />
513                                 </fileset>
514                         </classpath>
515                 </taskdef>
516                 <jalopy fileformat="unix" convention="${src.dir}/java/jalopy.format.convention.xml" history="file" historymethod="adler32" loglevel="error" threads="2" classpathref="classpath" backup="bak">
517                         <fileset dir="${src.dir}">
518                                 <include name="java/net/sf/jabref/**/*.java" />
519                         </fileset>
520                 </jalopy>
521         </target>
522
523         <target name="test">
524                 <junit printsummary="yes" fork="yes" haltonfailure="no">
525                         <batchtest fork="yes" todir="/tmp/testres">
526                                 <fileset dir="${build.classes}">
527                                         <include name="**/*Tester.class" />
528                                         <include name="**/*Test.class" />
529                                 </fileset>
530                         </batchtest>
531                         <classpath refid="classpath" />
532                 </junit>
533         </target>
534
535 </project>