Search in sources :

Example 1 with MacroInstance

use of org.apache.tools.ant.taskdefs.MacroInstance in project JikesRVM by JikesRVM.

the class ForEachTask method execute.

public void execute() {
    validate();
    final MacroDef.Attribute attribute = new MacroDef.Attribute();
    attribute.setName(property);
    macroDef.addConfiguredAttribute(attribute);
    final String[] values = list.split(" ");
    for (String value : values) {
        final MacroInstance i = new MacroInstance();
        i.setProject(getProject());
        i.setOwningTarget(getOwningTarget());
        i.setMacroDef(macroDef);
        i.setDynamicAttribute(property, value);
        i.execute();
    }
}
Also used : MacroDef(org.apache.tools.ant.taskdefs.MacroDef) MacroInstance(org.apache.tools.ant.taskdefs.MacroInstance)

Example 2 with MacroInstance

use of org.apache.tools.ant.taskdefs.MacroInstance in project JikesRVM by JikesRVM.

the class IfTask method execute.

public void execute() {
    validate();
    if (conditions.getCondition().eval()) {
        final MacroInstance i = new MacroInstance();
        i.setProject(getProject());
        i.setOwningTarget(getOwningTarget());
        i.setMacroDef(macroDef);
        i.execute();
    }
}
Also used : MacroInstance(org.apache.tools.ant.taskdefs.MacroInstance)

Example 3 with MacroInstance

use of org.apache.tools.ant.taskdefs.MacroInstance in project cassandra by apache.

the class TestHelper method execute.

public void execute() {
    Project project = getProject();
    String sep = project.getProperty("path.separator");
    String[] allTestClasses = project.getProperty("all-test-classes").split(sep);
    Sequential seqTask = (Sequential) project.createTask("sequential");
    for (int i = 0; i < allTestClasses.length; i++) {
        if (allTestClasses[i] == null)
            continue;
        MacroInstance task = (MacroInstance) project.createTask(property);
        task.setDynamicAttribute("test.file.list", ' ' + allTestClasses[i]);
        seqTask.addTask(task);
    }
    seqTask.perform();
}
Also used : Project(org.apache.tools.ant.Project) Sequential(org.apache.tools.ant.taskdefs.Sequential) MacroInstance(org.apache.tools.ant.taskdefs.MacroInstance)

Example 4 with MacroInstance

use of org.apache.tools.ant.taskdefs.MacroInstance in project ant by apache.

the class RuntimeConfigurable method maybeConfigure.

/**
 * Configures the wrapped element.  The attributes and text for
 * the wrapped element are configured.  Each time the wrapper is
 * configured, the attributes and text for it are reset.
 * <p>
 * If the element has an <code>id</code> attribute, a reference
 * is added to the project as well.
 * </p>
 *
 * @param p The project containing the wrapped element.
 *          Must not be <code>null</code>.
 *
 * @param configureChildren ignored.
 *
 * @exception BuildException if the configuration fails, for instance due
 *            to invalid attributes, or text being added to
 *            an element which doesn't accept it.
 */
public synchronized void maybeConfigure(Project p, boolean configureChildren) throws BuildException {
    if (proxyConfigured) {
        return;
    }
    // Configure the object
    Object target = (wrappedObject instanceof TypeAdapter) ? ((TypeAdapter) wrappedObject).getProxy() : wrappedObject;
    IntrospectionHelper ih = IntrospectionHelper.getHelper(p, target.getClass());
    ComponentHelper componentHelper = ComponentHelper.getComponentHelper(p);
    if (attributeMap != null) {
        for (Map.Entry<String, Object> entry : attributeMap.entrySet()) {
            String name = entry.getKey();
            // skip restricted attributes such as if:set
            AttributeComponentInformation attributeComponentInformation = isRestrictedAttribute(name, componentHelper);
            if (attributeComponentInformation.isRestricted()) {
                continue;
            }
            Object value = entry.getValue();
            // reflect these into the target, defer for
            // MacroInstance where properties are expanded for the
            // nested sequential
            Object attrValue;
            if (value instanceof Evaluable<?>) {
                attrValue = ((Evaluable<?>) value).eval();
            } else {
                attrValue = PropertyHelper.getPropertyHelper(p).parseProperties(value.toString());
            }
            if (target instanceof MacroInstance) {
                for (Attribute attr : ((MacroInstance) target).getMacroDef().getAttributes()) {
                    if (attr.getName().equals(name)) {
                        if (!attr.isDoubleExpanding()) {
                            attrValue = value;
                        }
                        break;
                    }
                }
            }
            try {
                ih.setAttribute(p, target, name, attrValue);
            } catch (UnsupportedAttributeException be) {
                // id attribute must be set externally
                if ("id".equals(name)) {
                // Do nothing
                } else if (getElementTag() == null) {
                    throw be;
                } else {
                    throw new BuildException(getElementTag() + " doesn't support the \"" + be.getAttribute() + "\" attribute", be);
                }
            } catch (BuildException be) {
                if ("id".equals(name)) {
                // Assume that this is an not supported attribute type
                // thrown for example by a dynamic attribute task
                // Do nothing
                } else {
                    throw be;
                }
            }
        }
    }
    if (characters != null) {
        ProjectHelper.addText(p, wrappedObject, characters.substring(0));
    }
    if (id != null) {
        p.addReference(id, wrappedObject);
    }
    proxyConfigured = true;
}
Also used : Attribute(org.apache.tools.ant.taskdefs.MacroDef.Attribute) EnableAttribute(org.apache.tools.ant.attribute.EnableAttribute) MacroInstance(org.apache.tools.ant.taskdefs.MacroInstance) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

MacroInstance (org.apache.tools.ant.taskdefs.MacroInstance)4 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Project (org.apache.tools.ant.Project)1 EnableAttribute (org.apache.tools.ant.attribute.EnableAttribute)1 MacroDef (org.apache.tools.ant.taskdefs.MacroDef)1 Attribute (org.apache.tools.ant.taskdefs.MacroDef.Attribute)1 Sequential (org.apache.tools.ant.taskdefs.Sequential)1