<!--
   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="configurations" default="run.dev" 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="compile.path.id">
        <fileset dir="${lib.dir}/compile"/>
    </path>
    <path id="lib.run.dev.id">
        <path location="${build.dir}"/>
        <fileset dir="${lib.dir}/rundev"/>
    </path>
    <path id="lib.run.prod.id">
        <path location="${build.dir}"/>
        <fileset dir="${lib.dir}/runprod"/>
    </path>

    <!-- =================================
          target: resolve
         ================================= -->
    <target name="resolve" description="--> retreive dependencies with ivy">
        <!-- conf="*" will copy artifacts defined for each conf in a dir matching conf name -->
        <ivy:retrieve pattern="${ivy.lib.dir}/[conf]/[artifact]-[revision].[ext]"/>
    </target>

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

    <!-- =================================
         target: run.dev
         ================================= -->
    <target name="run.dev" depends="resolve" description="--> compile and run the project">
        <mkdir dir="${build.dir}"/>
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.run.dev.id" includeAntRuntime="false"/>
        <copy todir="${build.dir}">
            <fileset dir="${src.dir}" includes="**/*.properties"></fileset>
        </copy>
        <java classpathref="lib.run.dev.id" classname="example.ConfigurationsExample" fork="true">
            <arg value="--dev"/>
        </java>
    </target>

    <!-- =================================
         target: run.prod
         ================================= -->
    <target name="run.prod" depends="resolve" description="--> compile and run the project">
        <mkdir dir="${build.dir}"/>
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.run.prod.id" includeAntRuntime="false"/>
        <copy todir="${build.dir}">
            <fileset dir="${src.dir}" includes="**/*.properties"></fileset>
        </copy>
        <java classpathref="lib.run.prod.id" classname="example.ConfigurationsExample" 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"/>
            </fileset>
        </delete>
    </target>

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