views:

28

answers:

1

How does ant behave if I define a path with a pathelement which points to a non-existent directory?

<path id="foo.bar">
   <pathelement location="this/might/not/exist/">
</path>

The scenario is that the ant file is used for several projects - some have this additional folder, and some do not.

Does ant just ignore it, or does it fail?

+1  A: 

It depends on the context.

When used as a classpath for the javac task, the missing directories are simply ignored:

This task will drop all entries that point to non-existent files/directories from the classpath it passes to the compiler.

But if you use a path containing a non-existent directory, say as the source for a copy, you'll get an error. For example, here directories 'one' and 'three' exist, but 'two' does not:

<path id="mypath">
    <pathelement path="one" />
    <pathelement path="two" />
    <pathelement path="three" />
</path>

<copy todir="dest">
    <path refid="mypath" />
</copy>

BUILD FAILED
/.../build.xml:14: Warning: Could not find resource file ".../two" to copy.

You could use a dirset to filter out the missing items perhaps:

<pathconvert property="dirs.list" pathsep="," refid="mypath">
    <map from="${basedir}/" to="" />
</pathconvert>
<dirset id="exists.dirs" dir="." includes="${dirs.list}" />    
<copy todir="dest">
    <dirset refid="exists.dirs" />
</copy>

 [copy] Copied 2 empty directories to 2 empty directories under /.../dest
martin clayton
oh sorry I forgot the context.
Emerson
I want to use it in the <junit><classpath> section
Emerson