<?xml version="1.0"?>
<project name="jibx-ivy" default="retrieve" xmlns:ivy="antlib:org.apache.ivy.ant">

  <property name="lib.dir" value="../lib" />
  <property name="ivy.install.version" value="2.2.0" />
  <property name="ivy.jar.dir" value="${user.home}/.ivy2" />
  <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy-${ivy.install.version}.jar" />
  <available property="ivy.jar.exists" file="${ivy.jar.file}" />

  <target name="-ivy-download" unless="ivy.jar.exists">
    <mkdir dir="${ivy.jar.dir}" />
    <property name="ivy.url"
              value="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" />
    <get src="${ivy.url}" dest="${ivy.jar.file}" usetimestamp="true" />
  </target>

  <target name="-ivy-install" depends="-ivy-download">
    <path id="ivy.lib.path">
      <fileset dir="${ivy.jar.dir}" includes="ivy-${ivy.install.version}.jar" />
    </path>
    <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" />
  </target>

  <!-- Use Ivy to download dependencies, which will be stored in the lib directory. -->
  <target name="retrieve" description="Download the dependencies" depends="-ivy-install">
    <echo>Retrieving files using Ivy</echo>
    <ivy:resolve file="ivy/jibx-bind-ivy.xml" />
    <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" />
    
    <ivy:resolve file="ivy/jibx-extras-ivy.xml" />
    <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" />

    <ivy:resolve file="ivy/jibx-run-ivy.xml" />
    <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" />
    
    <ivy:resolve file="ivy/jibx-schema-ivy.xml" />
    <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" />
    
    <ivy:resolve file="ivy/jibx-tools-ivy.xml" />
    <ivy:retrieve pattern="${lib.dir}/[artifact].[ext]" />
  </target>
  
</project>
