<?xml version="1.0" encoding="UTF-8"?>
<!--

    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.
-->
  

<!-- $Rev: 45918 $ $Date: 2005/03/11 21:13:59 $ -->

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

    <!-- ================= -->
    <!-- Global Properties -->
    <!-- ================= -->

    <!-- Determine what the top-level project root is -->
    <j:set var="project.root" value="${pom.parentBasedir().getParentFile().getCanonicalFile()}"/>

    <!-- Load the global properties -->
<!--    
    <ant:property file="${project.root}/etc/global.properties"/> 
-->

    <!-- set the maven.war.final.name by hand here because the variable is not -->
    <!-- expanded correctly when in the global.properties file -->
    <j:set var="maven.war.final.name" value="${pom.artifactId}-${pom.currentVersion}.war"/>

    <!-- convert the version-info.ent into a properties file and load that file -->
<!--
    <copy file="${project.root}/etc/version-info.ent" tofile="${project.root}/etc/version-info.properties" overwrite="true"/>
    <replaceregexp file="${project.root}/etc/version-info.properties"
        match='&lt;!ENTITY  *(.*)-version  *"(.*)"&gt;'
        replace="\1_version=\2"
        byline="true"/>
    <replaceregexp file="${project.root}/etc/version-info.properties"
        match="(..*)-(..*)-(..*).version=(.*)"
        replace="\1_\2_\3_version=\4"
        byline="true"/>
    <replaceregexp file="${project.root}/etc/version-info.properties"
        match="(..*)-(..*).version=(.*)"
        replace="\1_\2_version=\3"
        byline="true"/>
    <ant:property file="${project.root}/etc/version-info.properties"/>
-->
    <!-- ==================== -->
    <!-- Default Global Goals -->
    <!-- ==================== -->

    <goal name="default">
        <attainGoal name="${maven.multiproject.type}:install"/>
    </goal>

    <goal name="build">
        <attainGoal name="default"/>
    </goal>

    <goal name="rebuild">
        <attainGoal name="clean"/>
        <attainGoal name="build"/>
    </goal>

    <!-- Remove classes which depend on changed files, so they will rebuild. -->
    <preGoal name="java:compile">
        <j:if test="${sourcesPresent}">
            <ant:depend srcdir="${maven.compile.source}"
                destdir="${maven.build.dest}"
                dump="false"
                closure="false">
                <j:forEach var="sm" items="${pom.build.sourceModifications}">
                    <ant:available property="classPresent" classname="${sm.className}"/>
                    <j:if test="${classPresent != 'true'}">
                        <j:forEach var="exclude" items="${sm.excludes}">
                            <ant:exclude name="${exclude}"/>
                        </j:forEach>
                        <j:forEach var="include" items="${sm.includes}">
                            <ant:include name="${include}"/>
                        </j:forEach>
                    </j:if>
                </j:forEach>
            </ant:depend>
        </j:if>
    </preGoal>

    <!-- Remove the log files -->
    <goal name="clobber"
        description="Removes all (non-repository installed) build generated files">

        <!-- Let clean:clean do some work first -->
        <attainGoal name="clean:clean"/>

        <j:jelly xmlns="jelly:ant">
            <delete quiet="false" failonerror="false">
                <fileset dir="${basedir}">
                    <include name="maven.log"/>
                    <include name="velocity.log*"/>
                    <include name="junit*.properties"/>
                </fileset>
            </delete>
        </j:jelly>

    </goal>

    <!-- If there is no src/test directory you can
    turn off clover in that module by overriding this goal to do nothing -->
    <goal name="clover.wrapper">
        <attainGoal name="clover"/>
    </goal>

    <preGoal name="clover:test">
        <j:set var="cloveroverride" value="true"/>
    </preGoal>

    <!-- A goal that causes the tests to be skipped -->
    <goal name="test:skip">
        <j:set var="maven.test.skip" value="true"/>
    </goal>

    <!-- Check if the tests need to run -->
    <preGoal name="test:test">
        <j:if test="${context.getVariable('maven.test.force') == null}">
            <j:if test="${cloveroverride != 'true'}">
                <j:set var="uptodatePropName" value="tests.uptodate"/>
                <j:remove var="${uptodatePropName}"/>
                <ant:mkdir dir="${basedir}/target/test-reports/"/>
                <j:set var="uptodateFile" value="${basedir}/target/test-reports/tstamp"/>

                <u:file var="file" name="${basedir}/src"/>
                <j:if test="${file.exists()}" >	    
                    <ant:uptodate property="${uptodatePropName}" targetfile="${uptodateFile}">
                        <ant:srcfiles dir="${basedir}/src/" includes="**/*"/>
                    </ant:uptodate>
	        </j:if>	    

                <j:if test="${context.getVariable(uptodatePropName) == 'true'}">
                    <ant:echo>NOTICE: Skipping tests; they seem to have passed already</ant:echo>
                    <j:set var="maven.test.skip" value="true"/>
                    <j:set var="unitTestSourcesPresent" value="false"/>
                </j:if>
            </j:if>
        </j:if>
    </preGoal>

    <!-- Update the timestamp of the last successful test -->
    <postGoal name="test:test">
        <j:if test="${context.getVariable('maven.test.failure') == null}">
            <ant:touch file="${basedir}/target/test-reports/tstamp"/>
        </j:if>
    </postGoal>

    <!--
    <postGoal name="site">

	<j:set var="module.root" value="${pom.file.parentFile.canonicalFile}"/>

	<j:set var="moduleDirName">${pom.file.parentFile.name}</j:set>
        <j:set var="moduleTypeDirName">${pom.file.parentFile.parentFile.name}</j:set>
	<j:set var="outputDir">${project.root}/target/docs/${moduleTypeDirName}/${moduleDirName}</j:set>

        <ant:echo>Copying site docs to: ${outputDir}...</ant:echo>
        <ant:mkdir dir="${outputDir}"/>
        <ant:copy todir="${outputDir}">
           <ant:fileset dir="${module.root}/target/docs"/>
        </ant:copy>	

    </postGoal>
    -->

    <goal name="install">
    	<attainGoal name="${maven.multiproject.type}:install"/>
    </goal>

    <preGoal name="site">
        <j:set var="maven.test.skip" value="true"/>
    	<attainGoal name="install"/>
        <j:set var="maven.test.skip" value="false"/>
    </preGoal>
    
</project>
