Search in sources :

Example 1 with PropertyHelper

use of org.apache.tools.ant.PropertyHelper in project ant by apache.

the class Property method resolveAllProperties.

/**
 * resolve properties inside a properties hashtable
 * @param props properties object to resolve
 */
private void resolveAllProperties(Map<String, Object> props) throws BuildException {
    PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
    new ResolvePropertyMap(getProject(), propertyHelper, propertyHelper.getExpanders()).resolveAllProperties(props, getPrefix(), getPrefixValues());
}
Also used : ResolvePropertyMap(org.apache.tools.ant.property.ResolvePropertyMap) PropertyHelper(org.apache.tools.ant.PropertyHelper)

Example 2 with PropertyHelper

use of org.apache.tools.ant.PropertyHelper in project ant by apache.

the class PropertyHelperTask method execute.

/**
 * Execute the task.
 * @throws BuildException on error.
 */
@Override
public void execute() throws BuildException {
    if (getProject() == null) {
        throw new BuildException("Project instance not set");
    }
    if (propertyHelper == null && delegates == null) {
        throw new BuildException("Either a new PropertyHelper or one or more PropertyHelper delegates are required");
    }
    PropertyHelper ph = propertyHelper;
    if (ph == null) {
        ph = PropertyHelper.getPropertyHelper(getProject());
    } else {
        ph = propertyHelper;
    }
    synchronized (ph) {
        if (delegates != null) {
            for (Object o : delegates) {
                PropertyHelper.Delegate delegate = o instanceof DelegateElement ? ((DelegateElement) o).resolve() : (PropertyHelper.Delegate) o;
                log("Adding PropertyHelper delegate " + delegate, Project.MSG_DEBUG);
                ph.add(delegate);
            }
        }
    }
    if (propertyHelper != null) {
        log("Installing PropertyHelper " + propertyHelper, Project.MSG_DEBUG);
        // TODO copy existing properties to new PH?
        getProject().addReference(MagicNames.REFID_PROPERTY_HELPER, propertyHelper);
    }
}
Also used : PropertyHelper(org.apache.tools.ant.PropertyHelper) BuildException(org.apache.tools.ant.BuildException)

Example 3 with PropertyHelper

use of org.apache.tools.ant.PropertyHelper in project ant by apache.

the class ResourceList method parse.

private Resource parse(final String line) {
    PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
    Object expanded = propertyHelper.parseProperties(line);
    if (expanded instanceof Resource) {
        return (Resource) expanded;
    }
    String expandedLine = expanded.toString();
    int colon = expandedLine.indexOf(':');
    if (colon >= 0) {
        // could be an URL or an absolute file on an OS with drives
        try {
            return new URLResource(expandedLine);
        } catch (BuildException mfe) {
        // a translated MalformedURLException
        // probably it's an absolute path fall back to file
        // resource
        }
    }
    return new FileResource(getProject(), expandedLine);
}
Also used : Resource(org.apache.tools.ant.types.Resource) PropertyHelper(org.apache.tools.ant.PropertyHelper) BuildException(org.apache.tools.ant.BuildException)

Example 4 with PropertyHelper

use of org.apache.tools.ant.PropertyHelper in project ant by apache.

the class Available method execute.

/**
 * Entry point when operating as a task.
 *
 * @exception BuildException if the task is not configured correctly.
 */
@Override
public void execute() throws BuildException {
    if (property == null) {
        throw new BuildException("property attribute is required", getLocation());
    }
    isTask = true;
    try {
        if (eval()) {
            PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject());
            Object oldvalue = ph.getProperty(property);
            if (null != oldvalue && !oldvalue.equals(value)) {
                log("DEPRECATED - <available> used to override an existing" + " property." + StringUtils.LINE_SEP + "  Build file should not reuse the same property" + " name for different values.", Project.MSG_WARN);
            }
            // NB: this makes use of Project#setProperty rather than Project#setNewProperty
            // due to backwards compatibility reasons
            ph.setProperty(property, value, true);
        }
    } finally {
        isTask = false;
    }
}
Also used : PropertyHelper(org.apache.tools.ant.PropertyHelper) BuildException(org.apache.tools.ant.BuildException)

Aggregations

PropertyHelper (org.apache.tools.ant.PropertyHelper)4 BuildException (org.apache.tools.ant.BuildException)3 ResolvePropertyMap (org.apache.tools.ant.property.ResolvePropertyMap)1 Resource (org.apache.tools.ant.types.Resource)1