title: Get Path of File from Ant Using Available
body: <p>I am using Ant 1.10 and I need to find the path to a file up the directory structure from my current location, if the file exists. We are already using <code>ant-contrib</code> in our build environment, so no problem with a recommendation using that.</p>
  
  <p>For example, I have the following directory structure:</p>
  
  <pre><code>~/repos/proj/
            --/build.root
            --/common/math/
                        --/build.xml 
                        --/ivy.xml
            --/build/tools/
                        --/build-shared.xml
                        --/ivy-stuff.xml
            --/products/
                     --/prodA/
                           --/build.xml
                           --/ivy.xml
  </code></pre>
  
  <p>The path I need to retrieve is <code>~/repos/proj</code> as an absolute path (I call this property <code>buildrootdir</code>). I then create a property that is constructed from <code>buildrootdir</code> and the path to <code>build-shared.xml</code>. Currently, the path to the root is hard coded as a series of relative paths (<code>../../../</code>). We're going to be doing a code reorganization soon, and I'd like to get rid of the hard-coded relative paths with a "dynamic" lookup.</p>
  
  <p>My current solution is to use a recursive <code>antcallback</code> to a target in the findroot.xml that sets a property. I have some logic in place to restrict the search through the parent directories until I hit the root level. It works, but it's going to cause code duplication out the wazoo - every build.xml would have a neighboring findroot.xml. Otherwise, I have a hard-coded relative path to a common findroot.xml file which defeats my objective. I <strong>do not</strong> want something like this:</p>
  
  <pre><code>~/repos/proj/
            --/build.root
            --/common/math/
                        --/build.xml 
                        --/ivy.xml
                        --/findroot.xml
            --/build/tools/
                        --/build-shared.xml
                        --/ivy-stuff.xml
                        --/findroot.xml
            --/products/
                     --/prodA/
                           --/build.xml
                           --/ivy.xml
                           --/findroot.xml
  </code></pre>
  
  <p>I was looking at the <a href="https://ant.apache.org/manual/Tasks/available.html" rel="nofollow noreferrer" title="Available"><code>available</code></a> task and noticed that I could set the "searchparents" flag to true and it would recursively search upward. I can use</p>
  
  <pre><code>&lt;available property="found" file="build.root" filepath="${basedir}" searchparents="true"/&gt;
  </code></pre>
  
  <p>and this works to say the file is available. However, I don't know how to get the path to it using available. I look at the debug output, I see the following lines:</p>
  
  <pre><code>[available] Searching /home/user/repos/proj/common/math
  [available] Found: build.root in /home/user/repos/proj
  </code></pre>
  
  <p>I have looked at the <a href="https://sourcecodebrowser.com/ant/1.7.1/classorg_1_1apache_1_1tools_1_1ant_1_1taskdefs_1_1_available.html" rel="nofollow noreferrer" title="Available doxygen">available doxygen</a> and even the <a href="https://sourcecodebrowser.com/ant/1.7.1/_available_8java_source.html" rel="nofollow noreferrer" title="available source">available source code</a> and it does not appear to be possible.</p>
  
  <p>Am I missing something? Is there an alternative to <code>available</code> that would get me this desired behavior?</p>