<!--
 * Copyright 2002-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 name="Macros" default="all">
    <property name="jaxme.properties.location.1" location="${user.home}/.jaxme.properties"/>
    <property name="jaxme.properties.location.2" location="${basedir}/jaxme.properties"/>
    <available file="${jaxme.properties.location.1}" property="jaxme.properties.location" value="${jaxme.properties.location.1}"/>
    <property name="jaxme.properties.location" location="${basedir}/jaxme.properties"/>
    <echo>Loading custom properties from ${jaxme.properties.location}</echo>
    <property file="${jaxme.properties.location}"/>

    <property name="build" location="build"/>
    <property name="dist" location="${basedir}/dist"/>
    <property name="preqs" location="${basedir}/prerequisites"/>

    <condition property="have14" value="true">
      <not>
        <or>
          <equals arg1="${ant.java.version}" arg2="1.1"/>
          <equals arg1="${ant.java.version}" arg2="1.2"/>
          <equals arg1="${ant.java.version}" arg2="1.3"/>
        </or>
      </not>
    </condition>

    <condition property="have50">
      <and>
        <equals arg1="${have14}" arg2="true"/>
        <not> 
          <equals arg1="${ant.java.version}" arg2="1.4"/>
        </not>
      </and>
	</condition>

    <macrodef name="jc">
        <attribute name="srcdir"/>
        <attribute name="destdir"/>
        <attribute name="classpathref"/>
        <attribute name="excludes"/>
        <attribute name="java14classes"/>
        <sequential>
            <mkdir dir="@{destdir}"/>
            <javac destdir="@{destdir}" srcdir="@{srcdir}" debug="${debug}"
                optimize="${optimize}" classpathref="@{classpathref}"
                excludes="@{excludes}" source="1.3" target="1.3">
                <exclude name="@{java14classes}" unless="have14"/>
            </javac>
        </sequential>
    </macrodef>

    <macrodef name="jarzip">
        <attribute name="filename"/>
        <attribute name="classesdir"/>
        <attribute name="srcdir"/>
        <sequential>
            <mkdir dir="${dist}"/>
            <jar destfile="${dist}/@{filename}-${version}.jar" basedir="@{classesdir}"/>
            <zip destfile="${dist}/@{filename}-src-${version}.zip" basedir="@{srcdir}"/>
        </sequential>
    </macrodef>

    <macrodef name="runtests">
        <attribute name="reportsdir"/>
        <attribute name="classpathref"/>
        <element name="tests"/>
        <element name="properties" optional="true"/>
        <sequential>
            <mkdir dir="@{reportsdir}"/>
            <junit printsummary="yes" haltonfailure="yes">
                <classpath refid="@{classpathref}"/>
                <formatter type="plain"/>
                <batchtest todir="@{reportsdir}">
                    <tests/>
                </batchtest>
                <properties/>   
            </junit>
        </sequential>
    </macrodef>

    <target name="all"/>
</project>
