<?xml version="1.0"?>
<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->


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

  <j:set var="latexSrcDir" value="${maven.latex.src.dir}"/>


  <goal name="latex:prepare-filesystem"
    description="Prepare the filesystem for latex processing">
    <j:if test="${!latexSrcDir.equals('MAVEN_LATEX_SRC_DIR_NOT_SET')}">
      <ant:mkdir dir="${maven.build.dir}/docs/pdf/"/>
    </j:if>
  </goal>

  <goal name="latex:generate"
        prereqs="latex:prepare-filesystem"
        description="Generate documentation from latex source">

    <j:if test="${!latexSrcDir.equals('MAVEN_LATEX_SRC_DIR_NOT_SET')}">
      <ant:taskdef name="latex" classname="de.prima.shire.anttex.LaTeX"/>
      <ant:echo>scanning: ${latexSrcDir}</ant:echo>

      <ant:copy todir="${maven.build.dir}/latex">
        <ant:fileset dir="${latexSrcDir}" includes="**/*.tex,**/*.bib"/>
      </ant:copy>

      <ant:fileScanner var="latexFiles">
        <ant:fileset dir="${maven.build.dir}/latex">
          <ant:patternset>
            <ant:include name="**/*.tex"/>
          </ant:patternset>
        </ant:fileset>
      </ant:fileScanner>

      <j:forEach var="file" items="${latexFiles.iterator()}">

        <u:tokenize var="docs" delim=" ">${maven.latex.docs}</u:tokenize>

        <j:forEach var="doc" items="${docs}"> 
          <j:if test="${doc.equals(file.name)}">
            <ant:echo>Generating from ${file}</ant:echo>
            <ant:latex latexfile="${file.path}"
                   pdftex="on"
                   bibtex="on"
                   verbose="on"
                   directory="${file.parentFile.path}"/>
          </j:if>
        </j:forEach>
      </j:forEach>

      <ant:copy todir="${maven.build.dir}/docs/pdf/" flatten="true">
        <ant:fileset dir="${maven.build.dir}/latex" includes="**/*.pdf"/>
      </ant:copy>
    </j:if>
  </goal>

  <preGoal name="xdoc">
    <j:if test="${!latexSrcDir.equals('MAVEN_LATEX_SRC_DIR_NOT_SET')}">
      <attainGoal name="latex:generate"/>
    </j:if>
  </preGoal>


</project>
