oXygen XML Editor

3. The main ant script

This is an XML document meant for Apache ant.

If you don't use ant this won't mean much to you. Be aware that it contains properties (variables?), paths (for java) and targets. Each target is a single task (which may depend on other tasks) for execution, e.g. build the html from the docbook XML source. The targets are self explanatory. The name should make it clear just what they do


  <?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="antprettybuild.xsl"?>
<!-- 
This is the ant build file for use with  docbook v5 rng schema and stylesheets
for use with the Apache resolver classes 
Revision: 1.0
Date    : 2009-05-12T11:45:52Z
Author  : DaveP
To work with ant 1.7 and new resolver from Apache

Built as part of a small tutorial. 
Copyright Dave Pawson 2009


Note: Variable validation uses:

 <property name="prop.message" value="must be defined, preferably in ${basedir}/${properties.file}!"/>
  <fail message="VariableName ${prop.message}" unless="VariableName"/>
Outputs a message and fails if the variable is undefined


 -->

 <!-- Set the base directory to the location of the xml files -->
<project 
    name="setup.docbook"   
    basedir="."              
    default="help">  

  <description>Build docbook  file </description>

<!-- External, global properties
<property file="build.properties"/>


 -->
<property file="build.properties.sh"/>
<property file="website.properties" /> 


<!-- Main input for this project -->  
<property name="main_infile" value="setup.xml"/>              
<property name="infile_basename" value="setup"/>              
<property name="zip_filename" value="${infile_basename}.zip"/>

     
<!-- Primary property file for variables -->      
<property name="properties_file" value="build.properties.sh"/>



<!-- path for xslt processor. 
         Includes resolver and extensions and catalogManager.properties file.  -->
<path id="xslt1.processor.classpath">                                         
  <pathelement path="${java}/${xslt1_jar}"/>  <!-- Saxon jar -->
  <pathelement path="${java}/${resolver_jar}"/> <!-- resolver jar -->
  <pathelement path="${dbsaxonextensions}"/>   <!-- saxon65.jar -->
  <pathelement path="${java}/${xerces_impl_jar}"/> <!-- xinclude -->
  <pathelement path="/sgml"/> <!-- for catalogManager.properties -->
  <!-- For SaxonLiaison.class, see 
       http://vocaro.com/trevor/blog/2007/01/08/how-to-use-saxon-with-ant/
       compiled with 
       $ javac -classpath /apps/ant/lib/ant-trax.jar:/apps/ant/lib/ant.jar SaxonLiaison.java 
  -->


</path>



 

 <!-- path for xslt processor. 
         Includes resolver and extensions and catalogManager.properties file.  -->
 <path id="xslt2.processor.classpath">                                         
  <pathelement path="${java}/${xslt2_jar}"/>  <!-- Saxon jar -->
  <pathelement path="${java}/${resolver_jar}"/> <!-- resolver jar -->
  <pathelement path="${dbsaxonextensions}"/> 
  <pathelement path="${java}/${xerces_jar}"/>
  <pathelement path="/sgml"/> <!-- for catalogManager.properties -->
  <pathelement path="."/>
 </path>




<!--==================================== -->
<!--   Classpath for Jing                -->
<!--==================================== -->
<path id="jing.classpath">
  <pathelement path="${java}/${jing_jar}"/>
  <pathelement path="${java}/${xslt1_jar}"/>
  <pathelement path="${java}/${xerces_jar}"/>
  <pathelement path="${java}/${xerces_api_jar}"/>
</path>
  


<!--==================================== -->
<!--    Oasis catalog path               -->
<!--==================================== -->
 <xmlcatalog id="xmlCatalog">
   <catalogpath>
     <pathelement location="${xmlcatalog}"/>
   </catalogpath>
 </xmlcatalog>
 

<!--==================================== -->
<!--    Classpath for xsl-fo processor   -->
<!--==================================== -->
<path id="xslfo.processor.classpath">
  <pathelement path="/usr/java/default/lib/tools.jar"/>
  <pathelement path="${xephome}/lib/xep.jar"/>
  <pathelement path="${xephome}/lib/saxon.jar"/>
  <pathelement path="${xephome}/lib/xt.jar"/>
</path>






 <!--  -->
 <!--Initial processing: If needed.  -->
 <!--  -->
 <target name="init">
<echo>Check all properties in ${basedir}</echo>






<!-- Now run the xslt script to generate ant build file to check vars in build.xml -->

 <java classname="${xslt2_processor}" 
fork="yes" 
dir="${basedir}"
failonerror="true">
    <classpath refid="xslt2.processor.classpath" />
    <jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
    <jvmarg line="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
    <jvmarg line="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>  
    <arg value="-l"/>
    <arg value="-o"/>
    <arg value="testvars.xml"/>
    <arg line="-x org.apache.xml.resolver.tools.ResolvingXMLReader"/>
    <arg line="-y org.apache.xml.resolver.tools.ResolvingXMLReader"/>
    <arg line="-r org.apache.xml.resolver.tools.CatalogResolver "/>
    <arg line="${basedir}/${build_xml} ${testprops_xsl} " /> 
  </java>

<!-- Now run the newly created ant build file -->
<ant antfile="testvars.xml" />


<!-- Delete  file. Now redundant -->
<delete file="testvars.xml"/>




<echo>All properties checked</echo>

  <tstamp>
   <format property="TODAY_UK" pattern="d-MMM-yyyy" locale="en"/>
  </tstamp>
 <echo>building on ${TODAY_UK}</echo>

 </target>



<!--==================================== -->
<!--  xInclude expansion                 -->
<!--==================================== -->
<target name="xinclude">
  <echo>Expand Xincludes </echo>
  
  
  
  <exec executable="${xmllint}">
    <arg value="-o"/>
    <arg value="tmp.xml"/>
    <arg value="--xinclude"/>
    <arg value="${main_infile}"/>
  </exec>
</target>



<!--==================================== -->
<!--   rng validation using Jing         -->
<!--==================================== -->
<target name="jing" depends="xinclude">
<echo>Validate using Jing</echo>


<java classname="com.thaiopensource.relaxng.util.Driver"
      fork="yes"
      dir="${in_dir}"
      failonerror="false">
  <classpath refid="jing.classpath"/>
  <jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
  <arg value="${my_schema_rng}"/>
  <arg value="tmp.xml"/>

</java>
<echo>${main_infile} is valid</echo>

</target>

<!--==================================== -->
<!--   Expand includes, then validate    -->
<!--==================================== -->
<target name="validate" depends="xinclude, jing">
 <delete file="tmp.xml"/>
</target>









<!--                                           -->
 <!--Clean out the html directory: If needed.  -->
 <!--                                          -->
<target name='clean'>
  <echo>Clean out the ${out_html_dir} directory, from ${basedir}!</echo>
 
  <delete verbose="true">
    <fileset dir="${out_html_dir}" 
     includes="*.html"
     excludes="images/* graphics/* download/*"/>
  </delete>
  
</target>

<!--==================================== -->
<!--   Clean up the pdf directory        -->
<!--==================================== -->
<target name='clean.pdf'>
<echo>Clean out the ${out_pdf_dir} directory</echo>
  <delete>
    <fileset dir="${out_pdf_dir}" 
     includes="*.fo, *.pdf"
     excludes="images/* graphics/* download/*"/>
  </delete>

</target>
   
  
  
    
  
    <!-- ================================================ -->
    <!-- Generic XSLT-processor call (main docbook transform) -->
    <!-- ================================================ -->
    
<target name="docbook" depends="init, clean, validate, listimages">      <!-- depends="init, clean, validate, listimages" -->    
  <java classname="${xslt1_processor}" 
fork="yes" 
dir="${in_dir}"
failonerror="true">
    <classpath refid="xslt1.processor.classpath" /> <!-- within build.xml -->

    <jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
    <jvmarg line="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
    <jvmarg line="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>  
    <jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
   
    <arg line="-x org.apache.xml.resolver.tools.ResolvingXMLReader"/>
    <arg line="-y org.apache.xml.resolver.tools.ResolvingXMLReader"/>
    <arg line="-r org.apache.xml.resolver.tools.CatalogResolver "/>
    <arg value="-l"/>
    <arg value="-o"/>
    <arg value="${out_dir}/${main_outfile}"/>
    <arg line="${in_dir}/${main_infile} ${html_stylesheet} ${param_args_post}" /> 
   
  </java>
  <tstamp>
    <format property="fintim" pattern="E @ H:m a" locale="en,UK"/>
  </tstamp>
  <echo>Finished at ${fintim}</echo>
</target>
    



<!--==================================== -->
<!--    Generate xsl-fo for PDF          -->
<!--==================================== -->
<target name="fo" depends="init, validate, clean.pdf">
<echo>Generate the fo output</echo>
<java classname="${xslt1_processor_class}" 
      fork="yes" 
      dir="${in_dir}"
      failonerror="true">
  <classpath refid="xslt1.processor.classpath" />
  <jvmarg value="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
  <jvmarg value="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
  <jvmarg value="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
<arg value="-l"/>
  <arg value="-o"/>
  <arg value="${out_pdf_dir}/${main_fo_outfile}"/>
  <arg value="-x"/>
  <arg value="org.apache.xml.resolver.tools.ResolvingXMLReader"/>
  <arg value="-y"/>
  <arg value="org.apache.xml.resolver.tools.ResolvingXMLReader"/>
  <arg value="-r"/>
  <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
  <arg value="${in_dir}/${main_infile}"/>
  <arg value="${main_fo_stylesheet}" /> 
</java>
</target>

<!--==================================== -->
<!--     Generate PDF from xsl-fo        -->
<!--==================================== -->
<target name="pdf" depends="fo">
<echo> Generate the pdf in ${out_pdf_dir}</echo>
<java classname="${fo_processor_class}"
      fork='yes'
      dir='${in_dir}'
      failonerror='true'>
      <classpath refid="xslfo.processor.classpath"/>
      <jvmarg value="-Dcom.renderx.xep.CONFIG=${xephome}/xep.xml"/>
      <arg value="-quiet"/>
      <arg value="-fo"/>
<arg value="${out_pdf_dir}/${main_fo_outfile}"/>   <!-- ${main.fo.outfile} -->
      <arg value="-pdf"/>
      <arg value="${out_pdf_dir}/${main_pdf_outfile}"/>
     
</java>
<tstamp>
  <format property="fintim" pattern="E @ H:m a" locale="en,UK"/>
</tstamp>
<echo>Finished on ${fintim}</echo>
</target>




    
 
<!--==================================== -->
<!--  Zip up all the odd files           -->
<!--==================================== -->
<target name='zip'>
<echo>Create ${zip_filename}</echo>
<delete verbose='true' file="${basedir}/upload/${zip_filename}"/>
<echo>Zipping ${zip_file_list}</echo>

  <zip  destfile="${zip_src_directory}/${zip_filename}"
       basedir="${basedir}"   
       update="true"
       includes="${zip_file_list}"   />
        
</target>



<!-- ===================================================  -->
<!-- Copy local images to target, uses imported build file copyimages.xml -->
<!-- =================================================== -->
  
<target name='listimages'>
<echo>Generate a list of images, as an ant task, then run it</echo>
<echo>Run ${listimages_stylesheet} on ${main_infile} to produce ${imagelist_anttask} </echo>
<!-- Generate images using xslt 1 -->

<java classname="${xslt1_processor_class}" 
fork="yes" 
dir="${in_dir}"
failonerror="true">
    <classpath refid="xslt1.processor.classpath" />
    <jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
    <jvmarg line="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
    <jvmarg line="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>  
    <arg value="-l"/>
    <arg value="-o"/>
    <arg value="${in_dir}/${imagelist_anttask}"/> <!-- output file -->
    <arg line="-x org.apache.xml.resolver.tools.ResolvingXMLReader"/>
    <arg line="-y org.apache.xml.resolver.tools.ResolvingXMLReader"/>
    <arg line="-r org.apache.xml.resolver.tools.CatalogResolver "/>
    <arg line="${in_dir}/${main_infile} ${listimages_stylesheet} " /> 
  </java>


<!--  Now run the ant task from here. Must pick up these global variables -->
<echo>Now run ant build file ${imagelist_anttask}</echo>
<ant antfile="${imagelist_anttask}" target="copy"/>

<!--  -->


</target>




    <!-- ================================================   -->
    <!--                upload   to website                  -->
    <!-- ================================================ -->

<target name="upload" depends="docbook, zip">




  <echo>Sending files to ${froot}/${ftp_tgt}</echo>
  <ftp server="${website_target}"
       userid="${user_id}"
       password="${user_password}"
       passive="yes"
       remotedir="${zip_file_tgt}"
       verbose="yes"
       >
    <fileset dir="${basedir}/html">
  
      <include name="*.html"/>
      <include name="*.css"/>

    </fileset>
  </ftp>  

<!-- Now the zip file -->
  <ftp server="${website_target}"
       userid="${user_id}"
       password="${user_password}"
       passive="yes"
       remotedir="${zip_file_tgt}"
       verbose="yes"
       >
    <fileset dir="${basedir}/upload">
      <include name="setup.zip"/>

    </fileset>
  </ftp>  




  <tstamp>
    <format property="fintim" pattern="E @ H:m a" locale="en,UK"/>
  </tstamp>
  <echo>Finished on ${fintim}</echo>
</target>


  <!-- ================================================   -->
    <!--   Print out the help sheet                        -->
    <!-- ================================================ -->
<target name="help">
<echo>Help file for Website v5 documentation</echo>
<echo> </echo>
<echo>Options are as follows:</echo>
<echo>ant init - initialization only</echo>
<echo>ant xinclude - expand includes to 'tmp.xml'</echo>
<echo>ant jing - validate tmp.xml using Jing</echo>
<echo>ant validate - expand includes, then validate</echo>
<echo>ant docbook - process file ${in_dir}/${main_infile}</echo>
<echo>ant fo - process file ${in_dir}/${main_infile} to fo</echo>
<echo>ant pdf - process the fo file through to PDF</echo>
<echo>ant upload  - from dir ./${uploaddir} </echo>
<echo>              to ${website_target}</echo>
<echo>Dependencies: upload runs docbook, docbook runs init. </echo>
<echo>              </echo>

</target>



</project>

 

@TODO. Complete the variable checking! I now have a couple of scripts which sort out all the properties and run a single check as part of the init task, which makes redundant all the duplicated property checking within each task. The idea being to run it once and be done with it. If you have unset properties the build shouldn't run at all. Not yet incorporated. 2009-05-21T06:04:50Z