Blessed Geek
Blessed Geek

Reputation: 21624

Ant target dependency tree viewer

IS there a piece of software (or an eclipse plug-in) which,

given a target, would allow me to view the target dependency as a tree?

The tree does not need to be graphical, could be text based - just a tool that would help me traverse thro someone's mesh of ant files to debug them.

Does not need to be an Eclipse plug-in. However, would be nice when a node is clicked would throw the source of that target onto an editor.

Upvotes: 8

Views: 10316

Answers (3)

kunterbunt
kunterbunt

Reputation: 41

I created a java command line tool that can analyze ant build scrips and the dependencies between the targets. I am analyzing an ant script that calls other build scripts adn in total they have over 1000 ant targets. A tool was the only way to get through that mess. It can print ant target dependency trees and mark unused targets. https://github.com/kunterbunt2/antanalyzer Maybe this is what you where looking for. Feel free to ask questions in case the readme is nto good enough. There are also some unit test to showcase the tool.

Upvotes: 0

user3286293
user3286293

Reputation: 736

I wanted the same thing, but, like David, I ended up just writing a bit of code (Python):

from xml.etree import ElementTree

build_file_path = r'/path/to/build.xml'
root = ElementTree.parse(build_file_path)

# target name to list of names of dependencies
target_deps = {}

for t in root.iter('target'):
  if 'depends' in t.attrib:
    deps = [d.strip() for d in t.attrib['depends'].split(',')]
  else:
    deps = []
  name = t.attrib['name']
  target_deps[name] = deps

def print_target(target, depth=0):
  indent = '  ' * depth
  print indent + target
  for dep in target_deps[target]:
    print_target(dep, depth+1)

for t in target_deps:
  print
  print_target(t)

Upvotes: 5

Kelly S. French
Kelly S. French

Reputation: 12334

Similar to question ant debugging in Eclipse.

Based on Apache's ANT manual, you can start with the -projecthelp option. It might be more difficult after that because the various targets may have cross-dependencies and thus be impossible to represent the hierarchy as a tree at all.

You could modify the build.xml to detect an environment variable, e.g. NO_PRINT which is tested in each project target and if found, only print out the project name and nothing else. The depencies for the project would remain and allow ANT to walk the tree and produce a printout of the different targets that would get touched.

Upvotes: 4

Related Questions