<?xml version="1.0" encoding="iso-8859-1"?>
<!--
    Copyright 2004 Johan Känngård, http://dev.kanngard.net

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->
<project name="Common build file" default="all" basedir="">

    <description>
        This is a common Ant build file for projects. Version 1.1
        
        Copyright 2004 Johan Känngård, http://dev.kanngard.net
    </description>

    <target name="init" depends="project_init" description="Initialize environment">
        <property name="path.bin" value="bin"/>
        <property name="path.build" value="build"/>
        <property name="path.build.lib" value="build/lib"/>
        <property name="path.dist" value="dist"/>
        <property name="path.dist.classes" value="dist/classes"/>
        <property name="path.dist.lib" value="dist/lib"/>
        <property name="path.docs" value="docs"/>
        <property name="path.docs.api" value="docs/api"/>
        <property name="path.lib" value="lib"/>
        <property name="path.src" value="src"/>
        <property name="path.src.java" value="src/java"/>
        <property name="path.src.java.test" value="src/java_test"/>
        <property name="compile.debug" value="true"/>
        <property name="compile.deprecation" value="true"/>
        <property name="compile.jdk-version.source" value="1.4"/>
        <property name="compile.jdk-version.target" value="1.4"/>
        <property name="compile.optimize" value="true"/>
        <property file="${basedir}/build.properties"/>

        <path id="compile.classpath">
            <fileset dir="${path.build.lib}">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${path.lib}">
                <include name="*.jar"/>
            </fileset>
        </path>

    </target>

    <target name="project_prepare" description="Project-level prepare phase"/>

    <target name="make_directories" description="Creates all project directories" depends="init">
        <mkdir dir="${path.bin}"/>
        <mkdir dir="${path.build}"/>
        <mkdir dir="${path.build.lib}"/>
        <mkdir dir="${path.dist}"/>
        <mkdir dir="${path.dist.classes}"/>
        <mkdir dir="${path.dist.lib}"/>
        <mkdir dir="${path.docs}"/>
        <mkdir dir="${path.docs.api}"/>
        <mkdir dir="${path.lib}"/>
        <mkdir dir="${path.src}"/>
        <mkdir dir="${path.src.java}"/>
        <mkdir dir="${path.src.java.test}"/>
    </target>

    <target name="prepare" depends="init, make_directories, project_prepare" description="Prepare build directory">

    </target>

    <target name="compile" depends="prepare" description="Compile source">
        <javac debug="${compile.debug}" deprecation="${compile.deprecation}" destdir="${path.dist.classes}" target="${compile.jdk-version.target}" source="${compile.jdk-version.source}" optimize="${compile.optimize}" srcdir="${path.src}">
            <classpath refid="compile.classpath"/>
        </javac>
    </target>

    <target name="project_clean" description="Project-level prepare phase"/>

    <target name="clean" depends="init,project_clean" description="Wipeout all generated files">
        <delete dir="${path.dist.classes}"/>
        <delete dir="${path.dist.lib}"/>
    </target>

    <target name="all" depends="clean,compile" description="Clean and compile all components"/>

    <target name="javadoc" depends="compile" description="Create component Javadoc documentation">
        <delete dir="${path.docs.api}"/>
        <mkdir dir="${path.docs.api}"/>
        <javadoc author="true" bottom="${component.title}" destdir="${path.docs.api}" source="${compile.jdk-version.source}" doctitle="${component.title}" packagenames="*" access="protected" sourcepath="${path.src.java}" version="true" windowtitle="${component.title} (Version ${component.version})">
            <classpath refid="compile.classpath"/>
        </javadoc>
    </target>

    <target name="build-test" depends="compile" description="Compiles test components">
        <javac debug="${compile.debug}" deprecation="${compile.deprecation}" destdir="${path.test.classes}" target="${compile.jdk-version.target" source="${compile.jdk-version.source}" optimize="${compile.optimize}" srcdir="${path.src.java.test}">
            <classpath refid="compile.classpath"/>
        </javac>
    </target>

    <target name="jar" depends="compile,checkstyle" description="Create binary distribution">
        <copy file="LICENSE" todir="${path.dist.classes}"/>
        <delete>
            <fileset dir="${path.dist.lib}" includes="*.jar"/>
        </delete>
        <jar basedir="${path.dist.classes}" jarfile="${path.dist.lib}/${component.name}-${component.version}.jar">
            <include name="**/*.classes"/>
        </jar>

        <delete>
            <fileset dir="${path.dist.classes}">
                <include name="LICENSE"/>
            </fileset>
        </delete>
    </target>

    <target name="src-zip" depends="compile" description="Creates source distribution">
        <copy file="LICENSE" todir="${path.src.java}"/>
        <delete>
            <fileset dir="${path.dist.lib}" includes="*-src.zip"/>
        </delete>
        <zip basedir="." destfile="${path.dist.lib}/${component.name}-${component.version}-src.zip" whenempty="fail">
            <include name="**/*.*"/>
            <include name="*"/>
            <include name="**/*"/>
            <exclude name="${path.dist}/**/*.*"/>
            <exclude name="*.*~"/>      <!-- JEdit backups -->
            <exclude name=".nbattrs"/>  <!-- Netbeans filesystem attributes -->
            <exclude name="*.old"/>
        </zip>
    </target>

    <target name="dist" depends="jar,src-zip,checkstyle"/>

    <target name="checkstyle" depends="init">
        <taskdef resource="checkstyletask.properties" classpath="${path.build.lib}/checkstyle-all-3.4.jar"/>
        <checkstyle config="${path.build}/checkstyle_checks.xml">
            <fileset dir="${path.src.java}" includes="**/*.java"/>
            <property key="checkstyle.cache.file" file="${path.build}/checkstyle.cache"/>
            <classpath refid="compile.classpath"/>
        </checkstyle>
    </target>
</project>