<?xml version="1.0"?>
<!DOCTYPE project [
    <!ENTITY common SYSTEM "file:../build-common.xml">
]>

<!--
  =============================================================================
    Build file for the Cactus Documentation (it builds the Cactus web pages
    which serves both as the Cactus Web Site and as local documentation).

    $Id: build.xml 239151 2005-04-14 08:45:29Z vmassol $
  =============================================================================
-->
<project name="Cactus Documentation" default="dist" basedir="..">

  <description>
 Cactus Documentation
 ---------------------------------------------------------
 Contains the documentation and web site of Cactus as XML
 documents, as well as the XSLT stylesheets for
 transformation to HTML.
  </description>

  <!-- Base directory for all file related operations -->
  <property name="base.dir" location="documentation"/>

  <!-- Include properties and targets common to the different subprojects -->
  &common;

  <!-- Global project properties -->
  <property name="project.name.text" value="Cactus Documentation"/>
  <property name="project.name.file" value="cactus-doc"/>

  <!--
     ========================================================================
       Initialize source, target and dist properties
     ========================================================================
  -->
  <target name="properties">

    <!-- Set the properties related to the source tree -->
    <property name="src.dir" location="${base.dir}/src"/>
    <property name="src.java.dir" location="${src.dir}/java"/>
    <property name="doc.dir" location="${base.dir}/docs"/>
    <property name="doc.dtd.dir" location="${doc.dir}/dtds"/>
    <property name="doc.skin.dir" location="${doc.dir}/skins"/>
    <property name="doc.xdoc.dir" location="${doc.dir}/xdocs"/>
    <property name="build.dir" location="${base.dir}/."/>
    <property name="conf.dir" location="${base.dir}/conf"/>

    <!-- Locations of javadocs that need to be included if javadoc.include
         is defined -->
    <property name="dist.framework.javadoc.12" 
        location="framework/dist-12/doc/api"/>
    <property name="dist.framework.javadoc.13" 
        location="framework/dist-13/doc/api"/>
    <property name="dist.integration.ant.javadoc"
        location="integration/ant/dist-13/doc/api"/>             

    <!-- Set the properties related to the target area -->
    <property name="target.classes.dir" location="${target.dir}/classes"/>
    <property name="target.classes.java.dir"
        location="${target.classes.dir}/java"/>
    <property name="target.doc.dir" location="${target.dir}/doc"/>
    <property name="target.xdoc.dir" location="${target.dir}/xdocs"/>

  </target>

  <!--
     ========================================================================
       Initialize the build. Must be called by all targets
     ========================================================================
  -->
  <target name="init" depends="init.common,properties">

    <echo>clover.enable (optional) = ${clover.enable}</echo>

    <xmlcatalog id="documentation.dtds">
      <dtd publicId="-//Apache Software Foundation//DTD Cactus Navigation V1.0//EN"
          location="${doc.dtd.dir}/navigation-v10.dtd"/>
      <dtd publicId="-//Apache Software Foundation//DTD Cactus Sitemap V1.0//EN"
          location="${doc.dtd.dir}/sitemap-v10.dtd"/>
    </xmlcatalog>

    <condition property="offline">
      <or>
        <isset property="offline"/>
        <not>
          <http url="http://jakarta.apache.org/"/>
        </not>
      </or>
    </condition>

  </target>

  <!--
     ========================================================================
       Compile utility Java code
     ========================================================================
  -->
  <target name="compile" depends="init"
      description="Compile utility Java code">

    <mkdir dir="${target.classes.java.dir}"/>

    <javac srcdir="${src.java.dir}" destdir="${target.classes.java.dir}"
        deprecation="${deprecation}" optimize="${optimize}"
        debug="${debug}" classpath="${java.class.path}"/>

  </target>

  <!--
     ========================================================================
       Generate the documentation
     ========================================================================
  -->
  <target name="doc.validate" depends="doc.prepare">

    <xmlvalidate warn="yes">
      <xmlcatalog refid="documentation.dtds"/>
      <fileset dir="${doc.xdoc.dir}">
        <include name="sitemap.xml"/>
        <include name="**/navigation.xml"/>
      </fileset>
    </xmlvalidate>

  </target>

  <target name="doc.prepare" depends="init">

    <mkdir dir="${target.xdoc.dir}"/>
    <mkdir dir="${target.doc.dir}"/>
    <mkdir dir="${target.doc.dir}/images"/>

    <!-- Copy all files that may contain token filters or that are not 
         binary files -->
    <copy todir="${target.xdoc.dir}" filtering="on">
      <fileset dir="${doc.xdoc.dir}">
        <exclude name="original/**"/>
        <exclude name="misc/**"/>
        <exclude name="images/**"/>
        <exclude name="sitemap.xml"/>
      </fileset>
    </copy>

    <!-- Copy the images -->
    <copy todir="${target.doc.dir}/images" filtering="off">
      <fileset dir="${doc.xdoc.dir}/images"/>
      <fileset dir="${doc.skin.dir}/jakarta.apache.org/images"/>
    </copy>

    <!-- Copy the css -->
    <copy todir="${target.doc.dir}/css" filtering="on">
      <fileset dir="${doc.skin.dir}/jakarta.apache.org/css"/>
    </copy>

    <!-- Copy the misc doc files needed by the web site -->
    <copy todir="${target.doc.dir}/misc" filtering="off">
      <fileset dir="${doc.xdoc.dir}/misc"/>
    </copy>

    <!-- Copy the version.txt file -->
    <copy file="${conf.dir}/version.txt" todir="${target.doc.dir}"
        filtering="on"/>

   <!-- Copy the RDF file for RSS syndicators -->
   <copy todir="${target.doc.dir}" file="${doc.xdoc.dir}/news.rdf"/>

    <!-- Copy the announcement file -->
    <copy file="ANNOUNCEMENT.txt" todir="${target.doc.dir}"/>

  </target>

  <target name="doc.cvschangelog" 
      depends="doc.cvschangelog.offline,doc.cvschangelog.online"/>

  <target name="doc.cvschangelog.offline" if="offline">
    <echo>No changelog generation as it appears we are offline</echo>
  </target>

  <target name="doc.cvschangelog.online" depends="init" unless="offline">
    <echo>Generating web site changelogs</echo>

    <!-- Generate CVS log -->
    <mkdir dir="${target.xdoc.dir}/cvslog"/>
    <cvschangelog dir="${doc.xdoc.dir}" daysinpast="15"
        usersfile="${doc.xdoc.dir}/cvslog/users.properties"
        destfile="${target.xdoc.dir}/cvslog/cvslog.xml">
      <fileset dir="${doc.xdoc.dir}">
        <exclude name="**/navigation.xml"/>
        <exclude name="sitemap.xml"/>
        <exclude name="participating/todo.xml"/>
        <exclude name="changes.xml"/>
        <exclude name="**/cvslog.xml"/>
        <include name="**/*.xml"/>
      </fileset>
    </cvschangelog>

  </target>

  <target name="doc.generate" depends="doc.prepare,doc.cvschangelog">

    <property name="cvslog.file"
        location="${target.xdoc.dir}/cvslog/cvslog.xml"/>
    <property name="sitemap.file" location="${doc.xdoc.dir}/sitemap.xml"/>
    <basename property="xdoc.dir.name" file="${target.xdoc.dir}"/>

    <!-- Transform sitemap -->
    <style in="${doc.xdoc.dir}/sitemap.xml"
        out="${target.xdoc.dir}/sitemap.xml"
        style="${doc.skin.dir}/jakarta.apache.org/stylesheets/sitemap2document.xsl">
      <xmlcatalog refid="documentation.dtds"/>
    </style>

    <!-- Transform RDF news -->
    <style in="${doc.xdoc.dir}/news.rdf"
        out="${target.xdoc.dir}/news.xml"
        style="${doc.skin.dir}/jakarta.apache.org/stylesheets/rdf2document.xsl">
    </style>
   
    <!-- Generate the docs -->
    <style basedir="${target.xdoc.dir}" destdir="${target.doc.dir}"
        style="${doc.skin.dir}/jakarta.apache.org/stylesheets/document2html.xsl">
      <xmlcatalog refid="documentation.dtds"/>
      <include name="**/*.xml"/>
      <exclude name="**/navigation.xml"/>
      <exclude name="**/cvslog.xml"/>
      <param name="software" expression="Cactus"/>
      <param name="title" expression="Cactus Documentation"/>
      <param name="copyright"
          expression="${year} The Apache Software Foundation"/>
      <param name="project.version" expression="${project.doc.version}"/>
      <param name="project.version.previous"
          expression="${project.doc.version.previous}"/>
      <param name="last.updated.date" expression="${TODAY}"/>
      <!-- Location of the xdoc directory relative to where the
           stylesheet is located. Note: this path MUST be relative as it 
           is used as a relative URI from within the stylesheet -->
      <param name="xdocdir" expression="../../../${xdoc.dir.name}"/>
      <!-- Location of the sitemap.xml file -->
      <param name="sitemapFile" expression="${sitemap.file}"/>
      <!-- Location of the cvslog.xml file -->
      <param name="cvslogfile" expression="${cvslog.file}"/>
    </style>

  </target>

  <target name="doc.checksitemap" depends="compile,doc.prepare">

    <taskdef name="checksitemap"
        classname="org.apache.cactus.build.documentation.CheckSitemapTask">
      <classpath>
        <pathelement location="${target.classes.java.dir}"/>
      </classpath>
    </taskdef>

    <!-- Check the sitemap for invalid links -->
    <checksitemap sitemap="${doc.xdoc.dir}/sitemap.xml"
        outputDir="${target.doc.dir}">
      <xmlcatalog refid="documentation.dtds"/>
    </checksitemap>

  </target>

  <target name="doc" depends="doc.validate,doc.generate,doc.checksitemap"/>

  <!--
     ========================================================================
       Copy the javadoc from other subprojects if javadoc.include is defined
     ========================================================================
  -->
  <target name="dist.javadoc.check" depends="init" if="javadoc.include">

    <condition property="javadoc.include.ok" value="true">
      <and>
        <available file="${dist.framework.javadoc.12}/index.html"/>
        <available file="${dist.framework.javadoc.13}/index.html"/>
        <available file="${dist.integration.ant.javadoc}/index.html"/>
      </and>
    </condition>

    <fail unless="javadoc.include.ok">One of the javadoc has not been 
generated. Run 'ant dist.javadoc -verbose' to find out what the problem is.</fail>

  </target>

  <target name="dist.javadoc" depends="dist.javadoc.check" 
      if="javadoc.include.ok">

    <copy todir="${dist.doc.api.dir}/framework-12">
      <fileset dir="${dist.framework.javadoc.12}"/>
    </copy>
    <copy todir="${dist.doc.api.dir}/framework-13">
      <fileset dir="${dist.framework.javadoc.13}"/>
    </copy>
    <copy todir="${dist.doc.api.dir}/integration/ant">
      <fileset dir="${dist.integration.ant.javadoc}"/>
    </copy>

  </target>

  <!--
     ========================================================================
       Copy clover files and generate the Clover report.
     ========================================================================
  -->
  <target name="dist.clover.check.12"
      depends="init, init.clover"
      if="clover.enable">

    <condition property="clover.enable.ok.12" value="true">
      <and>
        <available file="${clover.initstring.12}"/>
      </and>
    </condition>

  </target>

  <target name="dist.clover.12"
      depends="dist.clover.check.12" 
      if="clover.enable.ok.12">
      
    <clover-setup initstring="${clover.initstring.12}"/>
    <clover-report>
      <current title="Cactus ${project.doc.version} for J2EE API 1.2"
          outfile="${dist.doc.dir}/clover-12">
        <format type="html"/>
      </current>
    </clover-report>

  </target>

  <target name="dist.clover.check.13"
      depends="init, init.clover"
      if="clover.enable">

    <condition property="clover.enable.ok.13" value="true">
      <and>
        <available file="${clover.initstring.13}"/>
      </and>
    </condition>

  </target>

  <target name="dist.clover.13"
      depends="dist.clover.check.13" 
      if="clover.enable.ok.13">
      
    <clover-setup initstring="${clover.initstring.13}"/>
    <clover-report>
      <current title="Cactus ${project.doc.version} for J2EE API 1.3"
          outfile="${dist.doc.dir}/clover-13">
        <format type="html"/>
      </current>
    </clover-report>

  </target>

  <target name="dist.clover" depends="dist.clover.12,dist.clover.13"/>

  <!--
     ========================================================================
       Generate the artifacts.
     ========================================================================
  -->  
  <target name="dist" depends="doc,dist.javadoc,dist.clover" 
      description="Generate the documentation">

    <mkdir dir="${dist.doc.dir}"/>

    <!-- Copy generated web site docs -->
    <copy todir="${dist.doc.dir}">
      <fileset dir="${target.doc.dir}"/>
    </copy>

  </target>

  <!--
     ========================================================================
       Generate the release
     ========================================================================
  -->
  <target name="zip" depends="init">

    <mkdir dir="${release.dir}"/>
    <zip destfile="${release.dir}/${main.release.name}.zip">
      <zipfileset dir="${dist.doc.dir}" 
          prefix="${main.release.name}"/>
    </zip>

  </target>

  <target name="release" depends="clean,dist,zip"
      description="Generate the release files"/>

  <!--
     ========================================================================
       Clean generated files (including distributables)
     ========================================================================
  -->
  <target name="clean" depends="init.display,init.properties"
    description="Clean all generated files">

    <delete dir="${target.dir}"/>
    <delete dir="${dist.dir}"/>
    <delete dir="${release.dir}"/>

  </target>

  <!--
     ========================================================================
       Upload the documentation to the Cactus web site on Jakarta
     ========================================================================
  -->
  <target name="upload.check" depends="init">

    <!-- Check that the zip is ready -->
    <available file="${release.dir}/${main.release.name}.zip" 
        property="upload.zip.ok"/>
    
    <fail message="You need to run 'ant release' first." 
        unless="upload.zip.ok"/>

    <!-- Check if we are online -->
    <fail message="You need to be online." if="offline"/>
    
    <!-- Check that needed properties have been set -->

    <echo>jakarta.username = ${jakarta.username}</echo>
    <echo>scp = ${scp}</echo>
    <echo>ssh = ${ssh}</echo>

    <condition property="upload.ok" value="true">
      <and>
        <isset property="jakarta.username"/>
        <isset property="scp"/>
        <isset property="ssh"/>
     </and>
    </condition>

    <fail unless="upload.ok">One of the needed property is not set. Run 
'ant upload -verbose' to know what the problem is.</fail>

  </target>

  <target name="upload.init" depends="upload.check">

    <property name="cactus.homepage"
        value="/www/jakarta.apache.org/cactus"/>

    <condition property="is.dev.version">
      <contains string="${project.version}" substring="dev"/>
    </condition>

    <exec dir="." executable="${scp}">
      <arg value="${release.dir}/${main.release.name}.zip"/>
      <arg value="${jakarta.username}@people.apache.org:/tmp"/>
    </exec>

  </target>
  
  <target name="upload.release" depends="upload.init" 
      unless="is.dev.version">

    <echo>Deploying release version to ${cactus.homepage}/${project.version} ...</echo>
    <exec dir="." executable="${ssh}">
      <arg line="-l ${jakarta.username} people.apache.org 'cd /tmp;rm -Rf ${main.release.name};unzip ${main.release.name}.zip;mkdir ${cactus.homepage}/${project.version};cp -Rfv ${main.release.name}/* ${cactus.homepage}/${project.version};rm -Rf ${main.release.name}.zip;rm -Rf ${main.release.name};cd ${cactus.homepage}/${project.version};chmod -R g+u * .'"/>
    </exec>

  </target>

  <target name="upload.dev" depends="upload.init" 
      if="is.dev.version">

    <echo>Deploying dev version to ${cactus.homepage} ...</echo>
    <exec dir="." executable="${ssh}">
      <arg line="-l ${jakarta.username} people.apache.org 'cd /tmp;rm -Rf ${main.release.name};unzip ${main.release.name}.zip;cp -Rfv ${main.release.name}/* ${cactus.homepage};rm -Rf ${main.release.name}.zip;rm -Rf ${main.release.name};cd ${cactus.homepage};chmod -R g+u * .'"/>
    </exec>

  </target>

  <target name="upload" depends="zip,upload.release,upload.dev"
      description="Upload the Cactus web site"/>

</project>
