<?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.
-->

<project default="default"
    xmlns:j="jelly:core"
    xmlns:u="jelly:util"
    xmlns:ant="jelly:ant"
    xmlns:maven="jelly:maven"
    xmlns:define="jelly:define"
    xmlns:velocity="jelly:velocity"
    >

    <!-- ================= -->
    <!-- Global Properties -->
    <!-- ================= -->

    <!-- Determine what the top-level project root is -->
    <j:set var="project.root" value="${pom.parentBasedir().getParentFile().getCanonicalFile()}"/>

    <!-- ==================== -->
    <!-- Default Global Goals -->
    <!-- ==================== -->

    <goal name="default">
        <attainGoal name="jar:install"/>
    </goal>

    <goal name="build">
        <attainGoal name="default"/>
    </goal>

    <goal name="rebuild">
        <attainGoal name="clean"/>
        <attainGoal name="build"/>
    </goal>

    <postGoal name="java:prepare-filesystem">
      <u:file var="file" name="${maven.home}/lib/jalopy.jar"/>
      <j:if test="${file.exists()}">
        <ant:path id="jalopy.library">
          <ant:fileset dir="${maven.home}/lib">
            <ant:include name="jalopy.jar"/>
          </ant:fileset>
        </ant:path>
        <maven:addPath id="maven.dependency.classpath" refid="jalopy.library"/>
      </j:if>
    </postGoal>

    

    <!-- Construct dependency lists for inclusion in generated jar. -->
    <!-- putting this goal here produces a circular dependency -->

    <!-- 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>

    <!-- Cleanse source files -->
    <goal name="cleanse-sources"
        description="Cleanse source files, removing tabs and translating CRLF -> LF">

        <j:scope xmlns="jelly:ant">

            <!-- Cleanse sources -->
            <j:set var="srcdir" value="${basedir}/src/java"/>
            <u:available file="">
                <fixcrlf srcdir="${srcdir}" eol="lf" eof="remove" tab="remove" tablength="4">
                    <include name="**/*.java"/>
                </fixcrlf>
                <fixcrlf srcdir="${basedir}" eol="lf" eof="remove" tab="remove" tablength="4">
                    <include name="**/*.xml"/>
                    <include name="**/*.html"/>
                </fixcrlf>
            </u:available>

            <!-- Cleanse test sources -->
            <j:set var="srcdir" value="${basedir}/src/test"/>
            <u:available file="${srcdir}">
                <fixcrlf srcdir="${srcdir}" eol="lf" eof="remove" tab="remove" tablength="4">
                    <include name="**/*.java"/>
                    <include name="**/*.xml"/>
                    <include name="**/*.html"/>
                </fixcrlf>
                <fixcrlf srcdir="${srcdir}" eol="lf" eof="remove" tab="remove" tablength="4">
                    <include name="**/*.xml"/>
                    <include name="**/*.html"/>
                </fixcrlf>
            </u:available>

            <!-- Cleanse xdocs -->
            <j:set var="srcdir" value="${basedir}/src/xdocs"/>
            <u:available file="${srcdir}">
                <fixcrlf srcdir="${srcdir}" eol="lf" eof="remove" tab="remove" tablength="4">
                    <include name="**/*.xml"/>
                    <include name="**/*.html"/>
                </fixcrlf>
            </u:available>

            <!-- Cleanse build files -->
            <fixcrlf srcdir="." eol="lf" tab="remove" eof="remove" tablength="4">
                <include name="project.xml"/>
                <include name="maven.xml"/>
            </fixcrlf>

            <!-- Cleanse scripts -->
            <j:set var="srcdir" value="${basedir}/src/bin"/>
            <u:available file="${srcdir}">
                <fixcrlf srcdir="${srcdir}" eol="lf" eof="remove" tab="remove" tablength="4">
                    <include name="**/*"/>
                </fixcrlf>
            </u:available>

        </j:scope>

    </goal>    
</project>
