<!-- version: $Id: build-common.xml,v 1.5 2005/05/11 16:14:37 nthx Exp $ -->

<!--
   | Each target in main buildfile should depend on this one
-->
<target name="common:init"
        depends="common:read_params,
                 common:prepare,
                 common:resources" />

<target name="common:read_params">
    <property file="build.properties"/>

    <path id="run_classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>
        <pathelement path="${build.classes.dir}" />
    </path>

    <taskdef name="annotationc" classname="org.jboss.aop.ant.AnnotationC"
    classpathref="run_classpath"/>
    <taskdef name="aopc" classname="org.jboss.aop.ant.AopC"
    classpathref="run_classpath" />

    <available property="junit.present" classname="junit.framework.TestCase" />
</target>

<!--
   | JUnit & ANT - a try to solve problem magically
-->
<target name="junit-check">
    <echo>
    Every target using JUnit tests REQUIRES `junit.jar' in your ANT_HOME/lib
    directory.
    This script will try to automatically handle the problem.
    If it fails, copy `junit.jar' into your ANT_HOME/lib.

    If it fails all the time you're probably running inside IDE. Check docs how
    to solve problem with Eclipse, IDEA (problems.html).
    </echo>
    <antcall target="junit-check-copy" />
</target>

<target name="junit-check-copy" depends="common:read_params"
        unless="junit.present" if="ant.home">
    <!-- solve great problem of Ant and JUnit - two most popular tools of
    development. Come on people! -->
    <copy todir="${ant.home}/lib" file="${lib.dir}/junit.jar" />
    <fail message="It's OK to fail Ant 1st time.." />
</target>

<target name="common:prepare" depends="common:read_params">
    <!-- create necessary directories -->
    <mkdir dir="${build.dir}" />
    <mkdir dir="${build.classes.dir}" />

    <!-- directories for all databases used by Ant targets -->
    <mkdir dir="${repository.dir}/tests" />
    <mkdir dir="${repository.dir}/demo" />
    <mkdir dir="${repository.dir}/skeleton-app" />
    <mkdir dir="${repository.dir}/performance" />
    <tstamp/>
</target>

<!--
   | Other helpful targets...
-->
<target name="common:resources" depends="common:read_params">
    <copy todir="${build.classes.dir}" includeEmptyDirs="no">
        <fileset dir="${etc.dir}">
            <patternset>
                <include name="*.properties" />
                <include name="*.xml" />
            </patternset>
        </fileset>
    </copy>
</target>


<target name="clean" depends="common:read_params"
        description="Cleans ${build.classes.dir}">
    <delete dir="${build.classes.dir}" />
    <delete dir="${dist.dir}" />
</target>