<?xml version="1.0"?>

<project 
  xmlns:define="jelly:define" 
  xmlns:gump="gump"
  xmlns:j="jelly:core" 
  xmlns:u="jelly:util">

  <!-- ================================================================== -->
  <!-- G U M P  D E S C R I P T O R                                       -->
  <!-- ================================================================== -->
  <!-- Converts a Maven descriptor to Gump format so that projects        -->
  <!-- using Maven can easily participate in Gump builds. This also       -->
  <!-- means that the Gump descriptor will be accurate because if         -->
  <!-- the project builds with Maven then the descriptor generated        -->
  <!-- for Gump will be correct. Distribution of responsibility.          -->
  <!-- ================================================================== -->

  <goal name="gump"
           description="Generate Gump descriptor from Maven descriptor"
           prereqs="gump:generate-descriptor"/>


  <define:taglib uri="gump">
    <define:tag name="name" trim="yes">
      <u:properties var="map" file="${plugin.resources}/maven2gump.properties" />
      <j:set var="gumpName" value="${map.getProperty(project)}" />
      <j:if test="${empty(gumpName)}">${project}</j:if>
      <j:if test="${!empty(gumpName)}">${gumpName}</j:if>
    </define:tag>
  </define:taglib>
  
  <goal name="gump:generate-descriptor"
           description="Generate Gump descriptor from Maven descriptor">

    <j:set var="gumpProject"><gump:name project="${pom.artifactId}"/></j:set>
    <j:file name="gump.xml" prettyPrint="true" xmlns="dummy">
<module name="${gumpProject}">

  <description>${pom.shortDescription}</description>
  <url href="${pom.url}"/>

  <u:tokenize var="scmTokens" delim=":">${pom.repository.connection}</u:tokenize>
  <cvs repository="${pom.gumpRepositoryId}"
       module="${scmTokens[5]}" />
  
  <!-- This is really the cvs module. We need to change this but -->
  <!-- I will leave this for now until everything works.         -->
  
  <project name="${gumpProject}">
    
    <!-- Standard Maven target to produce Javadocs, source -->
    <!-- and binary distributions.                         -->
    <ant buildfile="build.xml" target="dist">
      <property name="final.name" value="${pom.artifactId}-@@DATE@@"/>
    </ant>
    
    <package>${pom.package}</package>

    <j:new var="dependentProjects" className="java.util.TreeSet" />
    <!-- All Maven projects need Ant and Xerces to build. -->
    <j:set var="dummy" value="${dependentProjects.add('jakarta-ant')}" />
    <j:set var="dummy" value="${dependentProjects.add('xml-xerces')}"/>
    
    <!-- 
       Add project dependencies to the set, using project Id only
       If there is a gump project mapping for the named maven
       dependency, use that for the project in the depend tag
       otherwise just use the project id
      -->
    <j:forEach var="dependency" items="${pom.dependencies}">
      <j:set var="gumpDepName"><gump:name project="${dependency.groupId}" /></j:set>
      <j:set var="dummy">${dependentProjects.add(gumpDepName)}</j:set>
    </j:forEach>

    <!-- dump out the set of dependencies -->
    <j:forEach var="dependency" items="${dependentProjects}">
      <depend project="${dependency}" />
    </j:forEach>

    <work nested="target/classes"/>
    <home nested="target"/>
    <jar name="${pom.artifactId}-@@DATE@@.jar"/>
    
    <u:tokenize var="moduleTokens" delim="/">${scmTokens[5]}</u:tokenize>
    <javadoc nested="target/docs/apidocs" module="${moduleTokens[0]}"/>

    <nag from="${pom.artifactId} development &lt;${pom.build.nagEmailAddress}&gt;"
         to="${pom.build.nagEmailAddress}"/>
    
  </project>

</module>
    </j:file>
  
  </goal>
  
</project>
