<?xml version="1.0"?>

<project 
  xmlns:ant="jelly:ant"
  xmlns:define="jelly:define"
  xmlns:doc="doc"
  xmlns:j="jelly:core"  
  xmlns:jxr="jxr"
  xmlns:util="jelly:util">

  <define:taglib uri="jxr">
    <define:jellybean
      name="jxr"
      className="org.apache.maven.jxr.JxrBean"
      method="xref"
      />
  </define:taglib>

  <goal name="maven-jxr-plugin:register">
    <j:if test="${sourcesPresent}">
      <doc:registerReport 
        name="Source Xref" 
        pluginName="maven-jxr-plugin" 
        link="xref/index"
        description="A set of browsable cross-referenced sources."/>
      <j:if test="${unitTestSourcesPresent}">
      <doc:registerReport 
          name="Test Xref" 
          pluginName="maven-jxr-plugin" 
          link="xref-test/index"
          description="A set of browsable cross-referenced test sources."/>
      </j:if>
    </j:if>
  </goal>
  
  <goal name="maven-jxr-plugin:deregister">
    <doc:deregisterReport name="Source Xref"/>
    <doc:deregisterReport name="Test Xref"/>
  </goal>

  <!-- ================================================================== -->
  <!-- C R O S S  R E F E R E N C E  S O U R C E S                        -->
  <!-- ================================================================== -->

  <!-- Should we deprecate it to use only 'jxr' ? -->
  <goal
    name="maven-jxr-plugin:report"
    description="Generate HTML cross reference sources">

    <j:if test="${sourcesPresent == 'true'}">

      <ant:mkdir dir="${maven.jxr.destdir}"/>

      <!-- If the 'startDir' attribute changes we need to update
           CodeTransform.java in o.a.m.jxr, this will be fixed. -->

      <ant:echo>${maven.sourcesPresent}</ant:echo>

      <j:set var="javadocDestdir"
        value="${pom.getPluginContext('maven-javadoc-plugin').getVariable('maven.javadoc.destdir')}"/>

      <ant:property
        name="copyright"
        value="Copyright &amp;copy; ${year} ${pom.organization.name}. All Rights Reserved."
      />

      <ant:property
        name="title"
        value="${pom.name} ${pom.currentVersion} Reference"
      />

      <ant:copy file="${maven.jxr.stylesheet}"
        tofile="${maven.jxr.destdir}/stylesheet.css"/>
        
      <!-- XXX This is a dirty hack until the semantics of pom.build.sourceDirectory are cleared up -->
      <j:set var="sourceDir" value="${pom.build.sourceDirectory}"/>  
      <util:file var="sourceDirFile" name="${sourceDir}"/>
    
      <j:if test="${!sourceDirFile.isAbsolute()}">
        <j:set var="sourceDir" value="${basedir}/${sourceDir}"/>
      </j:if>
    
      <jxr:jxr
        sourceDir="${sourceDir}"
        destDir="${maven.jxr.destdir}"
        templateDir="${maven.jxr.templateDir}"
        javadocDir="${javadocDestdir}"
        windowTitle="${title}"
        docTitle="${title}"
        bottom="${copyright}">
      </jxr:jxr>

      <j:if test="${unitTestSourcesPresent == 'true'}">
        <ant:mkdir dir="${maven.jxr.destdir.test}"/>
        <j:set var="testSourceDir" value="${pom.build.unitTestSourceDirectory}"/>  
        <util:file var="testSourceDirFile" name="${testSourceDir}"/>
    
        <j:if test="${!testSourceDirFile.isAbsolute()}">
          <j:set var="testSourceDir" value="${basedir}/${testSourceDir}"/>
        </j:if>
      
        <ant:copy file="${maven.jxr.stylesheet}"
          tofile="${maven.jxr.destdir.test}/stylesheet.css"/>

        <jxr:jxr
          sourceDir="${testSourceDir}"
          destDir="${maven.jxr.destdir.test}"
          templateDir="${maven.jxr.templateDir}"
          javadocDir="${null}"
          windowTitle="${title}"
          docTitle="${title}"
          bottom="${copyright}">
        </jxr:jxr>

      </j:if>

    </j:if>
    
  </goal>

</project>
