use of org.apache.tools.ant.UnknownElement in project ant by apache.
the class MacroInstance method copy.
private UnknownElement copy(UnknownElement ue, boolean nested) {
UnknownElement ret = new UnknownElement(ue.getTag());
ret.setNamespace(ue.getNamespace());
ret.setProject(getProject());
ret.setQName(ue.getQName());
ret.setTaskType(ue.getTaskType());
ret.setTaskName(ue.getTaskName());
ret.setLocation(macroDef.getBackTrace() ? ue.getLocation() : getLocation());
if (getOwningTarget() == null) {
Target t = new Target();
t.setProject(getProject());
ret.setOwningTarget(t);
} else {
ret.setOwningTarget(getOwningTarget());
}
RuntimeConfigurable rc = new RuntimeConfigurable(ret, ue.getTaskName());
rc.setPolyType(ue.getWrapper().getPolyType());
Map<String, Object> m = ue.getWrapper().getAttributeMap();
for (Map.Entry<String, Object> entry : m.entrySet()) {
rc.setAttribute(entry.getKey(), macroSubs((String) entry.getValue(), localAttributes));
}
rc.addText(macroSubs(ue.getWrapper().getText().toString(), localAttributes));
Enumeration<RuntimeConfigurable> e = ue.getWrapper().getChildren();
while (e.hasMoreElements()) {
RuntimeConfigurable r = e.nextElement();
UnknownElement unknownElement = (UnknownElement) r.getProxy();
String tag = unknownElement.getTaskType();
if (tag != null) {
tag = tag.toLowerCase(Locale.ENGLISH);
}
MacroDef.TemplateElement templateElement = getNsElements().get(tag);
if (templateElement == null || nested) {
UnknownElement child = copy(unknownElement, nested);
rc.addChild(child.getWrapper());
ret.addChild(child);
} else if (templateElement.isImplicit()) {
if (unknownElements.isEmpty() && !templateElement.isOptional()) {
throw new BuildException("Missing nested elements for implicit element %s", templateElement.getName());
}
for (Task task : unknownElements) {
UnknownElement child = copy((UnknownElement) task, true);
rc.addChild(child.getWrapper());
ret.addChild(child);
}
} else {
UnknownElement presentElement = presentElements.get(tag);
if (presentElement == null) {
if (!templateElement.isOptional()) {
throw new BuildException("Required nested element %s missing", templateElement.getName());
}
continue;
}
String presentText = presentElement.getWrapper().getText().toString();
if (!presentText.isEmpty()) {
rc.addText(macroSubs(presentText, localAttributes));
}
List<UnknownElement> list = presentElement.getChildren();
if (list != null) {
for (UnknownElement unknownElement2 : list) {
UnknownElement child = copy(unknownElement2, true);
rc.addChild(child.getWrapper());
ret.addChild(child);
}
}
}
}
return ret;
}
use of org.apache.tools.ant.UnknownElement in project ant by apache.
the class CommonsLoggingListener method taskFinished.
/**
* @see BuildListener#taskFinished
* {@inheritDoc}.
*/
@Override
public void taskFinished(final BuildEvent event) {
if (initialized) {
final Task task = event.getTask();
Object real = task;
if (task instanceof UnknownElement) {
final Object realObj = ((UnknownElement) task).getTask();
if (realObj != null) {
real = realObj;
}
}
final Log log = getLog(real.getClass().getName(), null);
if (event.getException() == null) {
if (log.isTraceEnabled()) {
realLog(log, "Task \"" + task.getTaskName() + "\" finished.", Project.MSG_VERBOSE, null);
}
} else {
realLog(log, "Task \"" + task.getTaskName() + "\" finished with error.", Project.MSG_ERR, event.getException());
}
}
}
use of org.apache.tools.ant.UnknownElement in project ant by apache.
the class Description method concatDescriptions.
private static void concatDescriptions(Project project, Target t, StringBuilder description) {
if (t == null) {
return;
}
for (Task task : findElementInTarget(t, "description")) {
if (task instanceof UnknownElement) {
UnknownElement ue = (UnknownElement) task;
String descComp = ue.getWrapper().getText().toString();
if (descComp != null) {
description.append(project.replaceProperties(descComp));
}
}
}
}
Aggregations