ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashley Williams <>
Subject How do I walk the task tree from Java?
Date Fri, 28 Oct 2005 16:04:59 GMT

I'm trying to write a method in java that takes a root target and  
then walks down the task tree until it comes to the desired object,  
but don't seem to find the api to do this. I sort of got it to work  
in Ant 1.6.2 but wasn't really happy with the results as I still  
don't fully understand what I've written:

However I need to use Ant 1.5.2 which is missing two crucial methods:  
RuntimeConfigurableWrapper.getChildren and  
RuntimeConfigurable.getProxy() - is there anything I should be using  
in it's place? Is my strategy the right one?

I have a hunch that I'm doing the wrong thing as no tree should be  
this difficult to walk as i seem to have made it.

Many Thanks
- AW

          * Recursively searches the given task until a match is  
found for the given path.
          * @param searchTask
          * @param pathComponents
          * @param pathIndex
          * @return
         private Object findInTask(Task searchTask, String[]  
pathComponents, int pathIndex) {
             Object resultObj;

             boolean morePathComponents = pathIndex <  
             if (morePathComponents) {
                 resultObj = null;
                 Enumeration children =  

                 while (children.hasMoreElements()) {
                     RuntimeConfigurable child =  
(RuntimeConfigurable) children.nextElement();
                     if (child.getElementTag().equals(pathComponents 
[pathIndex])) {
                         // we have a match but need to check if  
there are more children to recurse
                         Object childProxy = child.getProxy();
                         if (childProxy instanceof Task) {
                             resultObj = findInTask((Task)  
childProxy, pathComponents, pathIndex + 1);
                         } else {
                             resultObj = childProxy;
                         break search;
             } else {
                 resultObj = searchTask;

             return resultObj;

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message