<?xml version="1.0" encoding="iso-8859-1" ?>

<project name="test" default="test" basedir="."
	xmlns:artifact="urn:maven-artifact-ant">
	<macrodef name="echo-fileset">
		<attribute name="filesetref" />
		<sequential>
			<pathconvert pathsep=" "
				property="@{filesetref}.echopath">
				<path>
					<fileset refid="@{filesetref}" />
				</path>
			</pathconvert>
			<echo>------- echoing fileset @{filesetref} -------</echo>
			<echo>${@{filesetref}.echopath}</echo>
		</sequential>
	</macrodef>

	<target name="clean">
		<delete includeEmptyDirs="true" quiet="true">
			<fileset dir="localRepository" />
			<fileset dir="checkDir" />
		</delete>
	</target>

	<target name="download">
		<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
			uri="urn:maven-artifact-ant">
			<classpath>
				<pathelement location="maven-ant-tasks-2.0.7.jar" />
			</classpath>
		</typedef>

		<artifact:pom id="pom" file="pom.xml" />
		<artifact:remoteRepository id="repository" url="file:./repository" />

		<artifact:dependencies filesetId="compile.dependency.fileset" useScope="compile" verbose="true">
			<pom refid="pom" />
			<remoteRepository refid="repository" />
			<localRepository path="./localRepository" />
		</artifact:dependencies>

		<echo message="============================================================" />
		<echo-fileset filesetref="compile.dependency.fileset" />

		<echo message="============================================================" />
		<echo message="   ------- Prepare the check -------" />
		<delete includeEmptyDirs="true" quiet="true">
			<fileset dir="checkDir" />
		</delete>
		<mkdir dir="checkDir" />
		<copy todir="checkDir">
			<fileset refid="compile.dependency.fileset" />
			<flattenmapper />
		</copy>
		<available property="fileIsPresent" file="./checkDir/d-1.2.jar" />
	</target>

	<target name="checkTrue" if="fileIsPresent">
		<echo message="problem SOLVE." />
	</target>

	<target name="checkFalse" unless="fileIsPresent">
		<echo message="ERROR : library 'd' isn't in the compile fileset" />
	</target>

	<target name="test" depends="download, checkTrue, checkFalse" />
</project>

