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