<?xml version="1.0"?>
<project name="getlibraries" basedir="." default="init">




  <!-- use the normal one at ibiblio-->
  <mavenrepository id="maven"/>

  
    <!-- configure an HTTP proxy -->
  <target name="setproxy" unless="setproxy.disabled" >
    <!-- put your proxy settings here -->
    <property file="${user.home}/.ant/proxy.properties" />
    <property name="proxy.host" value="" />
    <property name="proxy.port" value="80" />
    <property name="proxy.user" value="" />
    <property name="proxy.pass" value="" />
    <echo level="verbose">
      proxy: ${proxy.host}:${proxy.port} [${proxy.user}/${proxy.pass}]
    </echo>
      <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
        proxyuser="${proxy.user}" proxypassword="${proxy.pass}" />
  </target> 
  
  <target name="init" depends="setproxy">
    <property name="lib.dir" value="getlib"/>
    
    <property name="commons.logging.project" value="commons-logging"/>
    <property name="version" value="1.0.4"/>
    <property name="commons.logging.filename"
      value="${commons.logging.project}-${version}.jar"/>
    <property name="commons.logging"
      value="${commons.logging.project}/jars/${commons.logging.filename}"/>

    <property name="maven.repository.dir"
        location="${user.home}/.maven/repository" />      
      
    <presetdef name="gl1">
      <libraries destDir="${lib.dir}">
      </libraries>
    </presetdef>

    <presetdef name="getlib">
      <gl1 destDir="${lib.dir}">
        <library archive="commons-logging" project="commons-logging"
          version="${version}"/>
      </gl1>
    </presetdef>

    <macrodef name="assert-downloaded">
      <attribute name="library" default="${commons.logging}"/>
      <attribute name="repository" default="${lib.dir}"/>
      <sequential>
        <fail >
          Not found: "@{repository}/@{library}"
          <condition>
            <not>
              <available file="@{repository}/@{library}"/>
            </not>
          </condition>
        </fail>
      </sequential>
    </macrodef>
    
<!--     <macrodef name="assert-downloaded">
      <attribute name="library" default="${commons.logging}"/>
      <sequential>
        <property name="@{library}.path" location="${lib.dir}/@{library}" />
        <available property="@{library}.exists"
          file="${@{library}.path}"/>
        <fail unless="@{library}.exists">
          Not found: ${@{library}.path}
        </fail>
      </sequential>
    </macrodef> -->

    <macrodef name="assert-not-downloaded">
      <attribute name="library" default="${commons.logging}"/>
      <attribute name="repository" default="${lib.dir}"/>
      <sequential>
        <fail>
          Unexpectedly found: "@{repository}/@{library}"
          <condition>
            <available file="@{repository}/@{library}"/>
          </condition>
        </fail>
      </sequential>
    </macrodef>
    
  </target>

  <target name="cleanup"  depends="init">
    <delete dir="${lib.dir}"/>
  </target>

  <target name="teardown"  depends="cleanup"/>
  
  <target name="testEmpty" depends="init">
    <libraries/>
  </target>

  <target name="testEmpty2" depends="init">
    <libraries destDir="${lib.dir}">

    </libraries>
  </target>

  <target name="testEmpty3" depends="init">
    <libraries destDir="${lib.dir}">
      <repository/>
    </libraries>
  </target>

  <target name="testNoRepo" depends="init">
    <getlib/>
    <assert-downloaded/>
  </target>

  <target name="testUnknownReference" depends="init">
    <getlib>
      <repository refid="unknown"/>
    </getlib>
  </target>

  <target name="testFunctionalInline" depends="init">
    <getlib repositoryref="maven">
    </getlib>
    <assert-downloaded/>
  </target>

  <target name="testMavenInline" depends="init">
    <getlib>
      <mavenrepository/>
    </getlib>
    <assert-downloaded/>
  </target>

  <target name="testTwoRepositories" depends="init">
    <getlib>
      <mavenrepository/>
      <mavenrepository/>
    </getlib>
  </target>


  <target name="testMavenInlineBadURL" depends="init">
    <getlib>
      <mavenrepository url="http://invalid.example.org"/>
    </getlib>
  </target>

  <target name="testRenaming" depends="init">
    <getlib>
      <mavenrepository/>
      <library archive="commons-logging" project="commons-logging" version="${version}"
        destinationName="renamed.jar"
        />
    </getlib>
    <assert-downloaded/>
    <assert-downloaded library="renamed.jar"/>
  </target>


  <target name="testOverwrite" depends="init">
    <getlib>
      <mavenrepository/>
      <assertdownloaded count="1" />
    </getlib>
    <getlib>
      <mavenrepository/>
      <assertdownloaded count="0" />
    </getlib>
  </target>

  <target name="testIf" depends="init">
    <gl1>
      <mavenrepository/>
      <library archive="commons-logging" project="commons-logging" version="${version}" enabled="true"/>
    </gl1>
    <assert-downloaded/>
  </target>

  <target name="testUnless" depends="init">
    <gl1>
      <mavenrepository/>
      <library archive="commons-logging" project="commons-logging" version="${version}"
        enabled="false"/>
    </gl1>
    <assert-not-downloaded/>
  </target>

  <target name="testPathID" depends="init">
    <getlib pathid="commons.logging">
      <mavenrepository/>
    </getlib>
    <available
      property="logging.found"
      classname="org.apache.commons.logging.Log"
      classpathref="commons.logging"
      ignoresystemclasses="true" />
    <fail unless="logging.found">
      Did not find commons logging in the path
    </fail>
  </target>

  <target name="testSecurity" depends="init">
    <getlib>
      <mavenrepository checkMD5="true"/>
    </getlib>
    <assert-downloaded/>
  </target>
  
  <target name="testSchedule" depends="init">
    <getlib >
      <mavenrepository/>
      <schedule days="1" markerFile="${lib.dir}/marker.txt"/>
      <assertdownloaded count="1" />
    </getlib>
    <getlib >
      <mavenrepository/>
      <schedule days="1" markerFile="${lib.dir}/marker.txt"/>
      <assertdownloaded count="0" />
    </getlib>
  </target>

  <target name="testForceEnabled" depends="init">
    <getlib>
      <mavenrepository/>
      <force enabled="true" />
      <assertdownloaded count="1" />
    </getlib>
    <getlib>
      <mavenrepository/>
      <force enabled="true" />
      <assertdownloaded count="1" />
    </getlib>    
  </target>

  <target name="testForceDisabled" depends="init">
    <getlib>
      <force enabled="true" />
      <assertdownloaded count="1" />
    </getlib>
    <getlib >
      <force enabled="false" />
      <assertdownloaded count="0" />
    </getlib>
  </target>

  <target name="testAbsentFiles" depends="init">
    <getlib >
      <absentfiles enabled="true" />
      <assertdownloaded count="1" />
    </getlib>
  </target>

  <target name="testAbsentFilesTwice" depends="testAbsentFiles">
    <getlib >
      <absentfiles enabled="true" />
      <assertdownloaded count="0" />
    </getlib>
  </target>

  <target name="testNoUpdate" depends="init">
    <getlib >
      <mavenrepository/>
      <force />
      <noupdate />
      <assertdownloaded count="0" />
    </getlib>
  </target>

  <target name="testTimestamp" depends="testAbsentFiles">
    <getlib >
      <mavenrepository/>
      <timestamp />
      <assertdownloaded count="0" />
    </getlib>
  </target>

  <target name="testAssertDownloadedCountSet" depends="init">
    <getlib>
      <mavenrepository/>
      <assertdownloaded />
    </getlib>
  </target>

  <target name="testAssertDownloadedCountTested" depends="init">
    <getlib>
      <mavenrepository/>
      <assertdownloaded count="152" />
    </getlib>
  </target>  
  
  
  <target name="testNoArchiveName" depends="init">
    <gl1 destDir="${lib.dir}" >
      <library project="commons-logging" version="${version}"/>
      <mavenrepository/>
      <assertdownloaded count="1"/>
    </gl1>
  </target>

  <target name="testNoVersion" depends="init">
    <gl1 destDir="${lib.dir}" offline="true">
      <library project="commons-logging" />
      <mavenrepository/>
    </gl1>
  </target>

  <target name="testNoProject" depends="init">
    <gl1 destDir="${lib.dir}" offline="true">
      <library archive="commons-logging" version="${version}"/>
      <mavenrepository/>
    </gl1>
  </target>

  <target name="testNewSuffix" depends="init">
    <gl1 destDir="${lib.dir}">
      <library project="commons-logging" version="${version}"
        suffix=".jar.asc"/>
      <mavenrepository checkMD5="false"/>
      <assertdownloaded count="1"/>
    </gl1>
  </target>

  <target name="testNoSuffix" depends="init">
    <gl1 destDir="${lib.dir}">
      <library project="commons-logging" version="snapshot-version" suffix=""/>
      <assertdownloaded count="1"/>
      <mavenrepository checkMD5="false"/>
    </gl1>
  </target>

  <target name="testEmptyArchive" depends="init">
    <gl1 destDir="${lib.dir}">
      <library project="commons-logging" version="${version}"
        archive=""/>
      <assertdownloaded count="1"/>
      <mavenrepository/>
    </gl1>
  </target>

  <target name="testFlatten" depends="init">
    <getlib flatten="true">
      <mavenrepository/>
      <assertdownloaded count="1"/>
    </getlib>
    <assert-downloaded library="${commons.logging.filename}"/>
  </target>
</project>

