Search in sources :

Example 11 with UnknownElement

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;
}
Also used : Task(org.apache.tools.ant.Task) UnknownElement(org.apache.tools.ant.UnknownElement) Target(org.apache.tools.ant.Target) RuntimeConfigurable(org.apache.tools.ant.RuntimeConfigurable) ArrayList(java.util.ArrayList) List(java.util.List) BuildException(org.apache.tools.ant.BuildException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with UnknownElement

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());
        }
    }
}
Also used : Task(org.apache.tools.ant.Task) Log(org.apache.commons.logging.Log) UnknownElement(org.apache.tools.ant.UnknownElement)

Example 13 with UnknownElement

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));
            }
        }
    }
}
Also used : Task(org.apache.tools.ant.Task) UnknownElement(org.apache.tools.ant.UnknownElement)

Aggregations

UnknownElement (org.apache.tools.ant.UnknownElement)13 BuildException (org.apache.tools.ant.BuildException)8 Task (org.apache.tools.ant.Task)8 Method (java.lang.reflect.Method)2 Log (org.apache.commons.logging.Log)2 RuntimeConfigurable (org.apache.tools.ant.RuntimeConfigurable)2 Target (org.apache.tools.ant.Target)2 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 ComponentHelper (org.apache.tools.ant.ComponentHelper)1 DynamicAttribute (org.apache.tools.ant.DynamicAttribute)1 Project (org.apache.tools.ant.Project)1 ProjectHelper (org.apache.tools.ant.ProjectHelper)1