<?xml version="1.0" ?>
<project name="XDoclet" default="main">

  <!--
    Give user a chance to override without editing this file
    (and without typing -D each time he compiles it)
  -->
  <property file=".ant.properties"/>
  <property file="${user.home}/.ant.properties"/>

  <property name="log4j.jar" location="lib/log4j-core.jar"/>
  <property name="xdoclet.jar" location="lib/xdoclet.jar"/>

  <property name="src.dir"
            location="../../src/main/org/apache/tools/ant"/>
  <property name="src.root"
            location="../../src/main"/>
  <property name="docs.src"
            location="../../xdocs"/>
  <property name="build.dir" location="build"/>
  <property name="gen.dir" location="${build.dir}/gen"/>

  <property name="template.dir" location="templates"/>
  <property name="task.properties.template"
            location="${template.dir}/task_defaults_properties.template"/>
  <property name="type.properties.template"
            location="${template.dir}/type_defaults_properties.template"/>
  <property name="task_xdoc.template"
            location="${template.dir}/task_xdoc.template"/>
  <property name="datatype_xdoc.template"
            location="${template.dir}/datatype_xdoc.template"/>


  <target name="init">
    <mkdir dir="${build.dir}" />
    <mkdir dir="${gen.dir}" />

    <!-- hack, this should be outside a target but ${build.dir} gets stripped ?? -->
    <path id="xdoclet.classpath">
      <pathelement location="${log4j.jar}"/>
      <pathelement location="${xdoclet.jar}"/>

      <!-- javadoc is needed -->
      <pathelement path="${java.class.path}"/>
      <pathelement location="${build.dir}"/>
    </path>

    <taskdef name="document"
             classname="xdoclet.doc.DocumentDocletTask"
             classpathref="xdoclet.classpath"/>

  </target>


  <target name="clean">
    <delete dir="${build.dir}"/>
  </target>

  <target name="compile" depends="init">
    <javac srcdir="src" destdir="${build.dir}"
           debug="true" classpathref="xdoclet.classpath"/>
    <taskdef name="xdocs"
             classname="org.apache.tools.ant.xdoclet.AntXDocletTask"
             classpathref="xdoclet.classpath"/>
  </target>

  <target name="gen" depends="compile">
    <xdocs sourcepath="${src.root}"
           destdir="${gen.dir}"
           mergedir="${basedir}/src"
           classpathref="xdoclet.classpath">
      <fileset dir="${src.dir}">
        <include name="**/*.java" unless="class.name"/>
        <include name="**/${class.name}.java" if="class.name"/>
      </fileset>

      <!-- Generate XML task descriptor files -->
      <tasks templateFile="${task_xdoc.template}"
             destinationfile="{0}.xml"/>

      <!-- Generate XML datatype descriptor files -->
      <datatypes templateFile="${datatype_xdoc.template}"
                 destdir="${gen.dir}/datatypes"
                 destinationfile="{0}.xml"/>

      <!-- @todo - with some additional logic in these subtasks, they
           could be used similar to above instead of <template> -->
      <!-- Generate task defaults.properties -->
      <template subTaskClassName="org.apache.tools.ant.xdoclet.TaskSubTask"
                templateFile="${task.properties.template}"
                destinationfile="task_defaults.properties"/>

      <!-- Generate datatype defaults.properties -->
      <template subTaskClassName="org.apache.tools.ant.xdoclet.DatatypeSubTask"
                templateFile="${type.properties.template}"
                destinationfile="type_defaults.properties"/>

      <!-- Generate to-do list -->
      <info destdir="${gen.dir}/todo/ant"
            header="To-do List"
            projectname="Ant"/>
    </xdocs>

  </target>

  <target name="document" depends="init">
    <document sourcepath="${basedir}/src"
           destdir="${gen.dir}"
           mergedir="${basedir}/src"
           classpathref="xdoclet.classpath">
      <fileset dir="${basedir}/src">
        <include name="**/*.java" unless="class.name"/>
        <include name="**/${class.name}.java" if="class.name"/>
      </fileset>

      <info destdir="${gen.dir}/todo/xdocs"/>

      <!-- This is currently broken, checking into...
      <documenttags/> -->

    </document>
  </target>

  <target name="docs"> <!-- depends=gen -->
    <mkdir dir="${build.dir}/docs" />
    <!-- Copy stuff so things are in the correct relative location. -->
    <copy todir="${build.dir}/docs">
      <fileset dir="${basedir}/../../docs" includes="artwork/**" />
    </copy>
    <mkdir dir="${basedir}/xdocs" />
    <copy todir="${basedir}/xdocs">
      <fileset dir="${docs.src}" includes="stylesheets/project.xml" />
    </copy>
    <!-- Generate HTML using DVSL -->
    <ant dir="dvsl"/>
  </target>

  <target name="main" depends="gen,document"/>

</project>

