<?xml version="1.0"?>

<jsl:stylesheet select="$doc"
  xmlns:jsl="jelly:jsl"
  xmlns:j="jelly:core"
  xmlns:maven="jelly:maven"
  xmlns:x="jelly:xml"
  xmlns="dummy" trim="false">
  <jsl:template match="cruisecontrol" trim="false">
    <jsl:copy>
      <!-- TODO: more configurable -->
      <project name="${pom.artifactId}">
        <bootstrappers>
          <currentbuildstatusbootstrapper file="${maven.cruisecontrol.logs.dir}/currentbuildstatus.txt"/>
        </bootstrappers>
        <modificationset>
          <!-- FIXME: Shouldn't this use the second element of pom.repository.connection -->
          <maven:pluginVar var="method" plugin='maven-scm-plugin' property='maven.scm.method' />
          <maven:pluginVar var="module" plugin='maven-scm-plugin' property='maven.scm.cvs.module' />
          <j:if test="${method == 'cvs'}">
            <maven:pluginVar var="root" plugin='maven-scm-plugin' property='maven.scm.cvs.root' />
            <cvs cvsroot="${root}" localWorkingCopy="${maven.cruisecontrol.checkout.dir}/${module}" />
          </j:if>
        </modificationset>
        <schedule interval="${maven.cruisecontrol.schedule.interval}">
          <maven mavenscript="${maven.home}/bin/maven" goal="${maven.cruisecontrol.goals}" projectfile="${maven.cruisecontrol.checkout.dir}/${module}/project.xml"/>
        </schedule>
        <log dir="${maven.cruisecontrol.logs.dir}/${pom.artifactId}"/>
        <publishers>
          <currentbuildstatuspublisher file="${maven.cruisecontrol.logs.dir}/currentbuildstatus.txt"/>
          <htmlemail 
              subjectprefix="${maven.cruisecontrol.mail.subjectprefix}" 
              defaultsuffix="${maven.cruisecontrol.mail.defaultsuffix}" 
              mailhost="${maven.cruisecontrol.mail.host}" 
              returnaddress="${pom.build.nagEmailAddress}" 
              logdir="${maven.cruisecontrol.logs.dir}/${pom.artifactId}" 
              css="${maven.cruisecontrol.home}/reporting/jsp/css/cruisecontrol.css" 
              xsldir="${maven.cruisecontrol.home}/reporting/jsp/xsl">
            <!-- need to map ids to emails here -->
            <j:set var="developers" value="${pom.developers}"/>
            <j:if test="${!empty(developers)}">
              <j:forEach var="developer" items="${pom.developers}">
                <map alias="${developer.id}" address="${developer.email}"/>
              </j:forEach>
            </j:if>
            <failure address="${pom.build.nagEmailAddress}" />
          </htmlemail>
        </publishers>
      </project>
      <jsl:applyTemplates select="./project" />
    </jsl:copy>
  </jsl:template>

  <jsl:template match="*" trim="false">
    <j:set var="name"><x:expr select="@name" /></j:set>
    <j:if test="${name != pom.artifactId}">
      <jsl:copy>
        <jsl:applyTemplates />
      </jsl:copy>
    </j:if>
  </jsl:template>

  <jsl:template match="@*" trim="false" />

</jsl:stylesheet>

