<?xml version="1.0"?>

<project 
  xmlns:j="jelly:core"
  xmlns:maven="jelly:maven"
  xmlns:ant="jelly:ant"
  xmlns:doc="doc">
  
  <!-- ==================================================================
         Generate CVS statistics on the current CVS project
         
         Note: Needs JDK 1.4+
         
         TODO: Specify a range for the cvs log command.
         TODO: Bug if there are files not in CVS as statcvs need a fist 
               empty line. This have bee reported as a bug to StatCVS 
               team
       ================================================================== -->

  <goal name="maven-statcvs-plugin:register">
    <available property="jdk14" classname="java.lang.CharSequence"/>

    <j:if test="${jdk14 == 'true'}">
      <doc:registerReport 
        name="StatCVS Report" 
        pluginName="maven-statcvs-plugin"
        link="statcvs/index"
        description="Show some statistics about the CVS repository"/>
    </j:if>
  </goal>
  
  <goal name="maven-statcvs-plugin:deregister">
    <j:if test="${jdk14 == 'true'}">
      <doc:deregisterReport name="StatCVS Report"/>
    </j:if>
  </goal>
  
  <goal name="maven-statcvs-plugin:report">
    <attainGoal name="statcvs"/>
  </goal>
  
  <goal name="statcvs" prereqs="statcvs:generate"
    description="Generate CVS statistics for the current CVS project"/>

  <goal name="statcvs:generate"
    description="Generate CVS statistics for the current CVS project">

    <available property="jdk14" classname="java.lang.CharSequence"/>

    <j:choose>
      <j:when test="${jdk14 == 'true'}">

        <ant:mkdir dir="${maven.build.dir}"/>
        <property name="statcvs.logfile" value="${maven.build.dir}/statcvs.log"/>

        <!-- FIXME : We must use, with cvs, the connection string define in project.xml -->
        <cvs command="-q log" output="${statcvs.logfile}"/>

        <property name="maven.docs.dest" value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.dest')}"/>
        <ant:mkdir dir="${maven.docs.dest}"/>
  
        <java jar="${plugin.getDependencyPath('statcvs')}" fork="true">
          <arg value="${pom.name}"/>
          <arg value="${statcvs.logfile}"/>
          <arg value="${basedir}"/>
          <arg value="${maven.docs.dest}/statcvs"/>
          <classpath>
            <pathelement location="${plugin.getDependencyPath('statcvs')}"/>
            <pathelement location="${plugin.getDependencyPath('jfreechart')}"/>
          </classpath>
        </java>
      </j:when>

      <j:otherwise>
        <echo>Sorry, it needs JDK 1.4+ ...</echo>
      </j:otherwise>
    </j:choose>

  </goal>

</project>
