<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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

     https://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="myapp" default="run-cc" xmlns:ivy="antlib:org.apache.ivy.ant">
    <!-- some variables used -->
    <property name="lib.dir" value="lib"/>
    <property name="build.dir" value="build"/>
    <property name="src.dir" value="src"/>

    <!-- paths used for compilation and run  -->
    <path id="lib.path.id">
        <fileset dir="${lib.dir}/build"/>
    </path>
    <path id="run.hm.path.id">
        <path location="${build.dir}"/>
        <fileset dir="${lib.dir}/noexternaljar"/>
    </path>
    <path id="run.cc.path.id">
        <path location="${build.dir}"/>
        <fileset dir="${lib.dir}/withexternaljar"/>
    </path>

    <!-- =================================
          target: resolve
         ================================= -->
    <target name="resolve" description="--> retrieve dependencies with ivy">
        <ivy:retrieve pattern="${ivy.lib.dir}/[conf]/[artifact].[ext]"/>
    </target>

    <!-- =================================
          target: report
         ================================= -->
    <target name="report" depends="resolve" description="--> generates a report of dependencies">
        <ivy:report todir="${build.dir}"/>
    </target>

    <!-- =================================
         target: build
         ================================= -->
    <target name="build" depends="resolve" description="--> compile the project">
        <mkdir dir="${build.dir}"/>
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path.id" includeAntRuntime="false"/>
    </target>

    <!-- =================================
         target: run with home made implementation
         ================================= -->
    <target name="run-hm" depends="build" description="--> run the project with ome made implementation">
        <java classpathref="run.hm.path.id" classname="myapp.Main" fork="true"/>
    </target>

    <!-- =================================
         target: run with ext lib implementation
         ================================= -->
    <target name="run-cc" depends="build" description="--> run the project with ext lib implementation">
        <java classpathref="run.cc.path.id" classname="myapp.Main" fork="true"/>
    </target>

    <!-- =================================
         target: clean
         ================================= -->
    <target name="clean" description="--> clean the project">
        <delete includeemptydirs="true">
            <fileset dir="${basedir}">
                <exclude name="src/**"/>
                <exclude name="build.xml"/>
                <exclude name="ivy.xml"/>
                <exclude name=".*"/>
            </fileset>
        </delete>
    </target>

    <!-- =================================
          target: clean-cache
         ================================= -->
    <target name="clean-cache" description="--> clean the ivy cache">
        <ivy:cleancache/>
    </target>
</project>
