<?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:maven="jelly:maven"
    >


    <goal name="javacc:javacc-generate"
        description="Generate source from javacc grammar">


        <j:set var="packageName" value="${maven.javacc.javacc.package}"/>
        <j:if test="${packageName == null or packageName.length() eq 0}">
            <j:set var="packageName" value="${pom.package}"/>
        </j:if>
        <j:useBean var="javacc"
            generatedSourceDirectory="${basedir}/target/generated-src/main/java"
            class="org.apache.maven.javacc.JavaccBean"
            javaccPackageName="${packageName}"
            grammar="${maven.javacc.javacc.grammar}"
            header="${maven.javacc.javacc.header}"
            />

        <j:set var="dummy" value="${javacc.generate()}"/>
    </goal>

    <goal name="javacc:jjtree-generate">

        <j:set var="jjtreePackageName" value="${maven.javacc.jjtree.package}"/>
        <j:if test="${jjtreePackageName == null or jjtreePackageName.length() eq 0}">
            <j:set var="jjtreePackageName" value="${pom.package}"/>
        </j:if>
        <j:set var="javaccPackageName" value="${maven.javacc.javacc.package}"/>
        <j:if test="${javaccPackageName == null or jtreePackageName.length() eq 0}">
            <j:set var="javaccPackageName" value="${pom.package}"/>
        </j:if>

        <echo>javaccPackageName:${javaccPackageName}</echo>
        <echo>jjtreePackageName:${jjtreePackageName}</echo>
        <j:useBean var="jjtree"
            generatedSourceDirectory="${basedir}/target/generated-src/main/java"
            class="org.apache.maven.javacc.JJTreeBean"
            javaccPackageName="${javaccPackageName}"
            jjtreePackageName="${jjtreePackageName}"
            grammar="${maven.javacc.jjtree.grammar}"
            header="${maven.javacc.jjtree.header}"
            />

        <j:set var="dummy" value="${jjtree.generate()}"/>

        <j:set var="maven.javacc.javacc.grammar" value="${jjtree.javaccGrammar}"/>
        <echo>${maven.javacc.javacc.grammar}</echo>

    </goal>

    <goal name="javacc">
        <j:set var="jjtreeGrammar" value="${maven.javacc.jjtree.grammar}"/>
        <echo>jjtree grammar: ${jjtreeGrammar}</echo>
        <j:if test="${jjtreeGrammar != null and jjtreeGrammar.length() gt 0}">
            <attainGoal name="javacc:jjtree-generate"/>
        </j:if>
        <attainGoal name="javacc:javacc-generate"/>

        <ant:path id="maven.javacc.compile.src.set"
            location="${basedir}/target/generated-src/main/java"/>
        <maven:addPath id="maven.compile.src.set"
            refid="maven.javacc.compile.src.set"/>
    </goal>


</project>
