-1

I've got a situation where we're generating an Ant <path> which may contain some directories which don't actually exist. Unfortunately this is being fed into bnd, which blows up if anything in the path is missing.

So what I want is a way to filter a <path> to keep only those path elements which actually exist.

Is there a simple way to say this in Ant, or do I have to write a task?

keshlam
  • 7,931
  • 2
  • 19
  • 33

1 Answers1

0

I believe I have found an answer:

    <path id="bnd.cp.existing">
        <restrict>
            <path refid="bnd.cp"/>
            <exists/>
        </restrict>
    </path>

    <!-- To see when it happens, add the following: -->
    <echo message="bnd classpath is: ${toString:bnd.cp.existing}"/>
    <iff>
        <not>
           <equals arg1="${toString:bnd.cp.existing}"
                   arg2="${toString:bnd.cp}"/>
        </not>
        <then>
           <echo message="    trimmed from: ${toString:bnd.cp}"/>
        </then>
    </iff>

The restrict operation can take a path-like structure as input and return a version of it with the requested filtering applied -- in this case keep only the path elements which actually exist. This is then re-bound to a new ID for use by the <bnd> operation.

keshlam
  • 7,931
  • 2
  • 19
  • 33