tags:

views:

164

answers:

1

I'd like to have Ant automatically include or import resources matching a particular pattern, but I'm really struggling with the syntax. Here's what I've tried:

<import>
    <fileset dir="${basedir}" includes="*-graph.xml" />
</import>

However, I just get the error message

import requires file attribute or at least one nested resource

The documentation for import (and include) both say that you can use a nested resource collection, and the documentation for resource collections says <fileset> is a resource collection. I've Googled and can't find any useful examples at all.

I'm using Ant 1.8.1 (verified with ant -version)

EDIT

Found the problem. Firstly, SOMETHING has to match the expression. With no files that match, it blows up - even with optional=true, which is odd! Secondly, the matching files have be valid Ant file (even if they just contain <project/> - simply creating an empty file wasn't good enough).

Better error messages, please Apache! :-)

A: 

Try:

<foreach target="-import" param="file.name">
  <fileset dir="${basedir}" includes="*-graph.xml" />
</foreach>

<target name="-import">
  <import file="${file.name}" />
</target>

is in the ant-contrib tasks (http://ant-contrib.sourceforge.net/tasks/tasks/index.html) I'm not sure if this will work, I just came up with it on the fly.

Sagar
I guess it would, but I'm desperately trying to get away from as much ant-contrib stuff as I can. I'm trying to simplify a 20 trillion line build script which uses a huge amount of ant-contrib to try and do procedural stuff instead of just letting ant get on with things declaratively.Ant 1.8 and extension-points are my first step on this route.
dty