File f = getBuildFile(event);
if (f.exists()) {
if (onlyOnce && isBuilt(f)) {
Message.verbose("target build file already built, skipping: " + f);
} else {
Ant ant = new Ant();
Project project = (Project) IvyContext.getContext().peek(
IvyTask.ANT_PROJECT_CONTEXT_KEY);
if (project == null) {
project = new Project();
project.init();
}
ant.setProject(project);
ant.setTaskName("ant");
ant.setAntfile(f.getAbsolutePath());
ant.setInheritAll(false);
String target = getTarget();
if (target != null) {
ant.setTarget(target);
}
Map atts = event.getAttributes();
for (Iterator iter = atts.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
String value = (String) atts.get(key);
Property p = ant.createProperty();
p.setName(prefix == null ? key : prefix + key);
p.setValue(value);
}
Message.verbose("triggering build: " + f + " target=" + target + " for " + event);
MessageImpl impl = IvyContext.getContext().getMessageImpl();
try {
IvyContext.getContext().setMessageImpl(null);
try {
ant.execute();
} catch (BuildException e) {
Message.verbose("Exception occurred while executing target " + target);
e.printStackTrace(); // TODO: remove when finished debugging
throw e;
}