<?xml version="1.0"?>
<!--
=
= Copyright 2003-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:define="jelly:define"
  xmlns:util="jelly:util"
  xmlns:maven="jelly:maven"
  xmlns:ant="jelly:ant">

    <ant:path id="plugin.class.path">
        <pathelement path="${plugin.getDependencyPath('commons-attributes:commons-attributes-api')}"/>
        <pathelement path="${plugin.getDependencyPath('commons-attributes:commons-attributes-compiler')}"/>

        <pathelement path="${plugin.getDependencyPath('qdox')}"/>
    </ant:path>

    <ant:taskdef 
        resource="org/apache/commons/attributes/anttasks.properties"
        classpathref="plugin.class.path"/>

    <goal name="commons-attributes:compile">
        <ant:mkdir dir="${maven.build.dir}/commons-attributes"/>

        <ant:attribute-compiler inMaven="true" sourcepathref="maven.compile.src.set"
            destdir="${maven.build.dir}/commons-attributes"
            attributepackages="${org.apache.commons.attributes.attributepackages}"/>

        <ant:path 
            id="jakarta.commons.attributes.generated.dir" 
            location="${maven.build.dir}/commons-attributes"/>

        <maven:addPath 
            id="maven.compile.src.set"  
            refid="jakarta.commons.attributes.generated.dir"/>
    </goal>

    <preGoal name="java:compile"> 
        <j:if test="${sourcesPresent == 'true'}">
            <j:set var="caEnabled" value="${org.apache.commons.attributes.enable}"/>
            <j:if test="${caEnabled == 'true'}">
                <attainGoal name="commons-attributes:compile"/>
            </j:if>            
        </j:if>
    </preGoal>

    <preGoal name="test:compile">
        <j:if test="${unitTestSourcesPresent == 'true'}">
            <j:set var="caEnabled" value="${org.apache.commons.attributes.enable}"/>
            <j:if test="${caEnabled == 'true'}">
                <attainGoal name="commons-attributes:test-compile"/>
            </j:if>            
        </j:if>
    </preGoal>

    <goal name="commons-attributes:test-compile">
        <ant:attribute-compiler 
            inMaven="true" 
            sourcepathref="maven.test.compile.src.set"
            destdir="${maven.build.dir}/commons-attributes-unittest"
            attributepackages="${org.apache.commons.attributes.attributepackages}"/>

        <ant:path 
            id="jakarta.commons.attributes.generated.dir.test" 
            location="${maven.build.dir}/commons-attributes-unittest"/>

        <maven:addPath 
            id="maven.test.compile.src.set"  
            refid="jakarta.commons.attributes.generated.dir.test"/>
    </goal>

    <postGoal name="jar:jar">
        <!--
        For the life of me I can't figure out how to get the
        filename of the snapshot jar that jar:jar has just created.

        The maven.final.name variable is only set locally by the jar:snapshot
        goal, and thus all I see here is the projectname-version.jar name.
        -->
        <j:set var="caIndexEnabled" value="${org.apache.commons.attributes.index.enable}"/>
        <j:if test="${caIndexEnabled == 'true'}">
            <ant:attribute-indexer baseName="${maven.build.dir}/${pom.artifactId}">
                <classpath>
                    <path refid="maven.dependency.classpath"/>
                </classpath>
            </ant:attribute-indexer>
        </j:if>
    </postGoal>
</project>
