<?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:j="jelly:core"
         xmlns:ant="jelly:ant"
         xmlns:antlr="jelly:antlr"
         xmlns:util="jelly:util"
         xmlns:maven="jelly:maven">

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

  <goal name="antlr:prepare-filesystem"
        description="Make any necessary directories for antlr processing">
    <j:if test="${!antlrSrcDir.equals('MAVEN_ANTLR_SRC_DIR_NOT_SET')}">
      <ant:mkdir dir="${maven.antlr.target.dir}"/>
    </j:if>
  </goal>

  <goal name="antlr:generate"
        description="Generate source from antlr grammars"
        prereqs="antlr:prepare-filesystem">
    <j:if test="${!antlrSrcDir.equals('MAVEN_ANTLR_SRC_DIR_NOT_SET')}">

      <ant:path id="maven.antlr.compile.src.set"
            location="${maven.antlr.target.dir}"/>

      <maven:addPath id="maven.compile.src.set"
                     refid="maven.antlr.compile.src.set"/>

      <util:tokenize var="grammars" delim=" ">
         ${maven.antlr.grammars}
      </util:tokenize>

      <antlr:antlr outputDir="${maven.antlr.target.dir}">
        <j:forEach var="grammar" items="${grammars.iterator()}">
          <antlr:grammar>${grammar}</antlr:grammar>
        </j:forEach>
      </antlr:antlr>
    </j:if>
  </goal>

  <preGoal name="java:compile">
    <j:if test="${!antlrSrcDir.equals('MAVEN_ANTLR_SRC_DIR_NOT_SET')}">
      <attainGoal name="antlr:generate"/>
    </j:if>
  </preGoal>

</project>
