source: trunk/lib/docbook/ant-build-docbook.xml @ 3349

Last change on this file since 3349 was 3349, checked in by Martin Svensson, 14 years ago

Fixes #603 Done some clean-up

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.6 KB
Line 
1<?xml version="1.0" encoding="UTF-8" ?>
2
3<project name="Docbook styler module for ANT" default="help" basedir=".">
4  <property name="undefined"               value="__UNDEFINED__VALUE__" />
5
6  <!-- ## (DW 20040307) Added explicit property 'ant.docbook.styler.dir'. This
7       will be autoinitialized by default, but just in case somebody wants to
8       override the defaults...
9    -->
10  <property name="ant.docbook.styler.dir"  value="${basedir}" />
11
12  <!-- A directory where your docbook XMLs are -->
13  <property name="docbook.xml.dir"         value="${undefined}" />
14 
15  <!-- A directory where all the figures are -->
16  <property name="docbook.resources.dir"   value="${undefined}" />
17 
18  <!-- A directory for output files -->
19  <property name="distribution.dir"        location="${undefined}" />
20
21  <!-- A temp directory -->
22  <property name="build.dir"               location="${undefined}" />
23
24  <!-- Output file name for the rendered docbook file -->
25  <property name="manual.name"             value="index" />
26 
27  <!-- Start file for Docbook processing. -->
28  <property name="index.name"              value="${manual.name}" />
29 
30  <!-- Ouput file name for the docbook pdf file-->
31  <property name="pdf.name"         value="base"/>
32 
33  <property name="docbook.style"           value="plain" />
34
35  <!-- ## override these properties, if needed -->
36  <property name="temp:docbook.ready.file" location="${build.dir}/docbook-ready-file.tmp"/>
37  <property name="temp:fo.ready.file"      location="${build.dir}/fo-ready-file.tmp" />
38  <!-- ## (MM 20040303) moved all styles (for docbook and for website into sub-folders
39       ## of the styles folder -->
40  <property name="docbook.styles"          location="${ant.docbook.styler.dir}/custom-styles/docbook" />
41 
42  <!-- The version of base2 -->
43  <property name="base.version" value="${undefined}"/>
44
45  <path id="ant-extensions">
46    <fileset dir="${ant.docbook.styler.dir}/ant-extensions" includes="**/*.jar" />
47    <pathelement path="${ant.docbook.styler.dir}/ant-extensions" />
48  </path>
49
50  <!-- ##################################### -->
51  <!-- ### {{{ CHECK REQUIRED PROPS      ### -->
52  <!-- ##################################### -->
53 
54  <target name="check.required-properties">
55 
56    <condition property="tmp:ant.docbook.styler.dir" value="true">
57        <and>
58            <!-- ## (dw 20040307) check that we really point at the base directory
59                 of ant-docbook-styler -->
60            <available file="${ant.docbook.styler.dir}" type="dir" />
61            <available file="${ant.docbook.styler.dir}/custom-styles" type="dir" />
62            <available file="${ant.docbook.styler.dir}/docbook" type="dir" />
63        </and>
64    </condition>
65    <fail message="### 'ant.docbook.styler.dir' does not point at the styler's installation directory: ${ant.docbook.styler.dir}"
66        unless="tmp:ant.docbook.styler.dir"/>
67 
68    <condition property="tmp:docbook.xml.dir.ok" value="true">
69        <and>
70            <not>
71                <equals arg1="${docbook.xml.dir}" arg2="${undefined}" />
72            </not>
73            <available file="${docbook.xml.dir}" type="dir" />
74        </and>
75    </condition>
76    <fail message="### Define 'docbook.xml.dir' property pointing at Docbook XMLs folder."
77          unless="tmp:docbook.xml.dir.ok" />
78
79    <condition property="tmp:docbook.resources.dir.ok" value="true">
80        <and>
81            <not>
82                <equals arg1="${docbook.resources.dir}" arg2="${undefined}" />
83            </not>
84            <available file="${docbook.resources.dir}" type="dir" />
85        </and>
86    </condition>
87    <fail message="### Define 'docbook.resources.dir' property pointing at your resources folder."
88          unless="tmp:docbook.resources.dir.ok" />
89
90    <condition property="tmp:docbook.startfile.ok" value="true">
91        <and>
92            <available file="${docbook.xml.dir}/${index.name}.xml" type="file" />
93        </and>
94    </condition>
95    <fail message="### Cannot find root docbook file: ${docbook.xml.dir}/${index.name}.xml"
96          unless="tmp:docbook.startfile.ok" />
97
98    <condition property="tmp:docbook.build.dir.ok" value="true">
99        <and>
100            <not>
101                <equals arg1="${build.dir}" arg2="${undefined}" />
102            </not>
103            <available file="${build.dir}" type="dir" />
104        </and>
105    </condition>
106    <fail message="### Define 'build.dir' property pointing at a temporary folder (will be erased!)."
107          unless="tmp:docbook.build.dir.ok" />         
108
109    <condition property="tmp:docbook.distribution.dir.ok" value="true">
110        <and>
111            <not>
112                <equals arg1="${distribution.dir}" arg2="${undefined}" />
113            </not>
114            <available file="${distribution.dir}" type="dir" />
115        </and>
116    </condition>
117    <fail message="### Define 'distribution.dir' property pointing at your destination folder."
118          unless="tmp:docbook.distribution.dir.ok" />         
119  </target>
120
121  <target name="clean">
122    <delete failonerror="false" quiet="true" includeEmptyDirs="true">
123        <fileset dir="docbook">
124        <include name="dtd/**" />
125        <include name="xsl/**" />
126        </fileset>
127    </delete>
128  </target> 
129
130  <!-- }}} -->
131
132
133  <!-- ##################################### -->
134  <!-- ### {{{ PREPARE OUTPUT PATHS      ### -->
135  <!-- ##################################### -->
136
137  <target name="prepare" depends="modules.detection, check.required-properties, xsltprocessor">
138  </target>
139 
140  <target name="modules.detection">
141    <available file="${ant.docbook.styler.dir}/module-fop" type="dir"
142               property="module.fop.present" value="true" />
143  </target>
144
145  <!-- }}} --> 
146
147
148  <!-- ########################################################## -->
149  <!-- ### {{{ Prepare for building with docbook              ### -->
150  <!-- ########################################################## -->
151  <target name="copyResources-distribution" unless="resources.nocopy">
152    <copy todir="${distribution.dir}/css" includeemptydirs="false">
153        <fileset dir="${docbook.styles}/${docbook.style}/css"/>
154    </copy>
155    <copy todir="${distribution.dir}/gfx/admonitions" includeemptydirs="false">
156        <fileset dir="${docbook.styles}/${docbook.style}/admonitions" />
157    </copy>
158    <copy todir="${distribution.dir}/figures" includeemptydirs="false">
159        <fileset dir="${docbook.resources.dir}" includes="**/*" />
160    </copy>
161  </target>
162  <target name="copyResources-build">
163    <copy todir="${build.dir}/css" includeemptydirs="false">
164        <fileset dir="${docbook.styles}/${docbook.style}/css"/>
165    </copy>
166    <copy todir="${build.dir}/gfx/admonitions" includeemptydirs="false">
167        <fileset dir="${docbook.styles}/${docbook.style}/admonitions" />
168    </copy>
169    <copy todir="${build.dir}/figures" includeemptydirs="false">
170        <fileset dir="${docbook.resources.dir}" includes="**/*" />
171    </copy>
172  </target>
173
174  <target name="disable.resources.copy">
175    <property name="resources.nocopy" value="true" />
176  </target>
177   
178  <target name="docbook.consolidate"
179          depends="prepare, copyResources-build, copyResources-distribution, create.styler.uri">
180
181    <copy todir="${build.dir}" overwrite="true" filtering="false">
182        <fileset dir="${docbook.xml.dir}" />
183    </copy>
184
185    <property name="catalog.location" location="${ant.docbook.styler.dir}/preprocess/catalog.xml" />
186   
187    <!-- (MM 20040314) make the Java XSLT use the same catalog as the XSLTProc -->
188    <!-- works only with ant 1.6 and newer, but avoids problems when upgrading
189         from Java XSLT to XSLTProc later                                      -->
190    <xmlcatalog id="dtdcatalog">
191            <catalogpath>
192                <fileset file="${catalog.location}"/>
193            </catalogpath>
194    </xmlcatalog>
195
196    <style
197        in      = "${build.dir}/${index.name}.xml"
198        style   = "${ant.docbook.styler.dir}/preprocess/preprocess.xsl"
199        out     = "${temp:docbook.ready.file}"
200        processor = "${xslt.processor}"
201        >
202        <xmlcatalog refid="dtdcatalog"/>
203        <classpath refid="ant-extensions" />
204
205        <!-- <param name="xsltproc.option.debug"  expression="" /> -->
206        <param name="xsltproc.catalog" expression="${catalog.location}" />
207        <param name="xsltproc.option.--nonet"  expression="" />
208    </style>
209  </target>
210  <!-- }}} -->
211
212
213  <!-- ########################################################## -->
214  <!-- ### {{{ builds PDF documentation using FOP             ### -->
215  <!-- ########################################################## -->
216  <property name="module.fop.basedir" location="${ant.docbook.styler.dir}/module-fop" />
217  <target name="pdf.fop" depends="modules.detection,pdf.fop.internal">
218    <fail unless="module.fop.present">
219    ### ERROR: module for PDF FOP rendering not installed. Please download
220    it, and reinstall the styler using 'ant -f ant-build.docbook.xml install'.
221    </fail>
222  </target>
223
224  <target name="pdf.fop.internal" depends="disable.resources.copy,docbook.consolidate" if="module.fop.present">
225   
226    <!-- Get the revision number and the datetime when the latest file was commited -->
227    <svn>
228    <status path="../../doc/src/docbook" lastChangedRevisionProperty="doc.revision" />
229      <status path="../../doc/src/docbook" lastChangedDateProperty="doc.last.modified" />
230  </svn>
231
232    <copy file="${module.fop.basedir}/conf/config.xml"
233      tofile="${build.dir}/config.xml"
234      overwrite="true"
235    >
236        <filterset refid="filterset.fileuris" />
237    </copy>
238   
239    <copy file="${docbook.styles}/${docbook.style}/xsl/customized.pdf-fop.xsl"
240          tofile="${build.dir}/customized.pdf-fop.xsl.tmp"
241          overwrite="true"
242    >
243        <filterset refid="filterset.fileuris" />
244      <filterset>
245          <filter token="doc.revision" value="${doc.revision}" />
246          <filter token="doc.last.modified" value="${doc.last.modified}" />
247          <filter token="base.version" value="${base.version}" />
248        </filterset>
249    </copy>
250
251    <style
252        in      = "${temp:docbook.ready.file}"
253        style   = "${build.dir}/customized.pdf-fop.xsl.tmp"
254        out     = "${build.dir}/fop-ready.fo"
255        processor = "${xslt.processor}"
256        >
257        <classpath refid="ant-extensions" />
258    </style>
259
260    <taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop">
261             <classpath>
262                <fileset dir="${module.fop.basedir}">
263                    <include name="**/*.jar" />
264                </fileset>
265              <fileset dir="../dist">
266                <include name="commons-logging-1.0.4.jar" />
267              </fileset>
268             </classpath>
269    </taskdef>
270
271    <fop format     = "application/pdf" 
272         fofile     = "${build.dir}/fop-ready.fo"
273         outfile    = "${distribution.dir}/${pdf.name}_${base.version}.pdf"
274         messagelevel = "warn"
275         userconfig = "${build.dir}/config.xml"
276       basedir="${build.dir}"
277        />
278
279  </target>
280  <!-- }}} -->
281   
282  <!-- ########################################################## -->
283  <!-- ### {{{ builds HTML documentation (single and chunked) ### -->
284  <!-- ########################################################## -->
285
286  <target name="html.single" depends="docbook.consolidate"
287          description="Renders a docbook documentation to a single HTML file.">
288
289    <copy file="${docbook.styles}/${docbook.style}/xsl/customized.single.xsl"
290          tofile="${build.dir}/customized.single.xsl.tmp"
291          overwrite="true"
292    >
293        <filterset refid="filterset.fileuris" />
294    </copy>
295
296    <style
297        in      = "${temp:docbook.ready.file}"
298        style   = "${build.dir}/customized.single.xsl.tmp"
299        out     = "${distribution.dir}/${manual.name}.html"
300        processor = "${xslt.processor}"
301        >
302        <classpath refid="ant-extensions" />
303    </style>
304   
305    <delete file="${build.dir}/customized.single.xsl.tmp" />
306
307  </target>
308
309
310  <target name="html.chunked" depends="docbook.consolidate" 
311          description="Renders the manual to a set of HTML files (sectioned).">
312 
313    <pathconvert property="docbook:tmp:chunked.dir" pathSep="," dirSep="/">
314        <path>
315            <pathelement location="${distribution.dir}" />
316        </path>
317    </pathconvert>
318   
319    <!-- Get the revision number and the datetime when the latest file was commited -->
320    <svn>
321    <status path="../../doc/src/docbook" lastChangedRevisionProperty="doc.revision" />
322      <status path="../../doc/src/docbook" lastChangedDateProperty="doc.last.modified" />
323  </svn>
324   
325    <copy file="${docbook.styles}/${docbook.style}/xsl/customized.chunked.xsl"
326          tofile="${build.dir}/customized.chunked.xsl.tmp"
327          overwrite="true"
328    >
329        <filterset refid="filterset.fileuris" />
330        <filterset>
331            <!-- (MM20040315) base.dir and root.filename are tokens used in customized.chunked.xsl
332                 to set the xsl:params correctly there -->
333            <filter token="base.dir" value="${docbook:tmp:chunked.dir}" />
334            <filter token="root.filename" value="${manual.name}" />
335          <filter token="doc.revision" value="${doc.revision}" />
336          <filter token="doc.last.modified" value="${doc.last.modified}" />
337          <filter token="base.version" value="${base.version}" />
338        </filterset>
339    </copy>
340
341    <style
342        in      = "${temp:docbook.ready.file}"
343        style   = "${build.dir}/customized.chunked.xsl.tmp"
344        out     = "${distribution.dir}/docbook-ref-file.tmp"
345        processor = "${xslt.processor}"
346        >
347
348        <classpath refid="ant-extensions" />
349        <!-- <param name="chunker.output.encoding" expression="'UTF-8'" /> -->
350    </style>
351   
352    <delete file="${build.dir}/customized.chunked.xsl.tmp" />
353
354  </target>
355
356  <!-- }}} -->
357
358  <!-- ########################################################################## -->
359  <!-- ### {{{ XSLT processor recognition. If xsltproc[.exe] is found in path,    -->
360  <!-- ### it will be used for stylesheet processing (much faster than Xalan)     -->
361  <!-- ########################################################################## -->
362  <target name="xsltprocessor">
363    <property environment="env"/>
364
365    <condition  property="executable.file.extension"
366                value=".exe">
367            <os family="windows"/>
368    </condition>
369    <condition  property="executable.file.extension"
370                value="">
371            <os family="unix"/>
372    </condition>
373   
374    <condition  property="tmp:xsltproc.available"
375                value="xsltproc${executable.file.extension}">
376        <or>
377            <and>
378                <os family="windows"/>
379                <available file="xsltproc${executable.file.extension}" filepath="${env.Path}" />
380            </and>
381            <and>
382                <os family="unix"/>
383                <available file="xsltproc${executable.file.extension}" filepath="${env.PATH}" />
384            </and>
385        </or>
386    </condition>
387   
388    <condition property="xslt.processor" value="com.dawidweiss.ant.taskdefs.XsltProcLiaison">
389        <and>
390            <isset property="tmp:xsltproc.available" />
391            <not>
392                <isset property="disable.xsltproc" />
393            </not>
394        </and>
395    </condition>
396   
397    <condition property="xslt.processor" value="com.dawidweiss.ant.taskdefs.SaxonLiaison">
398        <not>
399            <isset property="disable.saxon" />
400        </not>
401    </condition>
402
403    <condition property="xslt.processor" value="trax">
404        <not>
405        <and>
406                <isset property="tmp:xsltproc.available" />
407                <not>
408                    <isset property="disable.xsltproc" />
409                </not>
410        </and>
411        </not>
412    </condition>
413
414    <antcall target="displayXsltProcessorInfo" />
415  </target>
416
417  <target name="displayXsltProcessorInfo"
418          if="tmp:xsltproc.available"
419          unless="disable.xsltproc">
420    <echo>
421   
422#####################################################
423XSLTProc has been found in your path and will be used
424for processing XSLT transformations. If you experience
425any problems, you can switch to Java's default XSLT
426processor by defining 'disable.xsltproc' property.
427#####################################################
428
429    </echo>
430  </target>
431 
432 
433  <target name="create.styler.uri">
434    <pathconvert dirsep="/" property="tmp:ant.docbook.styler.abs">
435        <path>
436        <pathelement location="${ant.docbook.styler.dir}" />
437        </path>
438    </pathconvert>
439    <condition  property="tmp:file.uri.prefix"
440                value="file:///">
441            <os family="windows"/>
442    </condition>
443    <condition  property="tmp:file.uri.prefix"
444                value="file://">
445            <os family="unix"/>
446    </condition>
447    <property name="tmp:ant.docbook.styler.uri"
448        value="${tmp:file.uri.prefix}${tmp:ant.docbook.styler.abs}" />
449
450    <pathconvert dirsep="/" property="tmp:style.abs">
451        <path>
452        <pathelement location="${docbook.styles}/${docbook.style}" />
453        </path>
454    </pathconvert>
455    <property name="tmp:style.uri"
456        value="${tmp:file.uri.prefix}${tmp:style.abs}" />
457     
458    <filterset id="filterset.fileuris">
459        <filter token="ant.docbook.styler.fileuri" value="${tmp:ant.docbook.styler.uri}" />
460        <filter token="docbook.style.fileuri" value="${tmp:style.uri}" />
461    </filterset>
462
463  </target>
464  <!-- }}} -->
465 
466 
467
468
469  <!-- ##################################### -->
470  <!-- ### {{{ HELP ON THIS FILE             ### -->
471  <!-- ##################################### -->
472  <target name="help" description="Displays help about the project.">
473    <echo>
474    Project name: ${ant.project.name}
475    (c) Dawid Weiss, Poznań University of Technology.
476
477    Current JDK: ${ant.java.version}
478    Basedir    : ${basedir}
479    -----------------------------------
480   
481    Use ant -projecthelp for description of available tasks.
482    See the test folder for an example of use.
483
484    </echo>
485  </target>
486  <!-- }}} -->
487
488</project>
Note: See TracBrowser for help on using the repository browser.