/** * Resolve the reference, using the associated project if * it set, otherwise use the passed in project. * @param fallback the fallback project to use if the project attribute of * reference is not set. * @return the dereferenced object. * @throws BuildException if the reference cannot be dereferenced. */ public Object getReferencedObject(Project fallback) throws BuildException { if (refid == null) { throw new BuildException("No reference specified"); } Object o = project == null ? fallback.getReference(refid) : project.getReference(refid); if (o == null) { throw new BuildException("Reference " + refid + " not found."); } return o; }
private PropertyHelper.Delegate resolve() { if (refid == null) { throw new BuildException("refid required for generic delegate"); } return (PropertyHelper.Delegate) getProject().getReference(refid); } }
private static CommandLauncher extractLauncher(String referenceName, Project project) { return Optional.ofNullable(project) .map(p -> p.<CommandLauncher> getReference(referenceName)) .orElseGet(() -> getSystemLauncher(referenceName)); }
public Object evaluate(String property, PropertyHelper propertyHelper) { Object o = null; if (property.startsWith(PREFIX) && propertyHelper.getProject() != null) { o = propertyHelper.getProject().getReference(property.substring(PREFIX_LEN)); } return o == null ? null : o.toString(); } };
/** * Return the descriptions from all the targets of * a project. * * @param project the project to get the descriptions for. * @return a string containing the concatenated descriptions of * the targets. */ public static String getDescription(Project project) { List<Target> targets = project.getReference(ProjectHelper2.REFID_TARGETS); if (targets == null) { return null; } StringBuilder description = new StringBuilder(); for (Target t : targets) { concatDescriptions(project, t, description); } return description.toString(); }
public Object evaluate(String prop, PropertyHelper helper) { return prop.startsWith(PREFIX) && helper.getProject() != null ? helper.getProject().getReference(prop.substring(PREFIX_LEN)) : null; } };
private ScriptDef getScript() { String name = getTaskType(); Map<String, ScriptDef> scriptRepository = getProject().getReference(MagicNames.SCRIPT_REPOSITORY); if (scriptRepository == null) { throw new BuildException("Script repository not found for " + name); } ScriptDef definition = scriptRepository.get(getTaskType()); if (definition == null) { throw new BuildException("Script definition not found for " + name); } return definition; }
/** * Finds or creates the script repository - it is stored in the project. * This method is synchronized on the project under {@link MagicNames#SCRIPT_REPOSITORY} * @return the current script repository registered as a reference. */ private Map<String, ScriptDef> lookupScriptRepository() { Map<String, ScriptDef> scriptRepository; Project p = getProject(); synchronized (p) { scriptRepository = p.getReference(MagicNames.SCRIPT_REPOSITORY); if (scriptRepository == null) { scriptRepository = new HashMap<>(); p.addReference(MagicNames.SCRIPT_REPOSITORY, scriptRepository); } } return scriptRepository; }
/** * Convenience overloaded version of {@link #getClassLoaderForPath(Project, Path, * String, boolean)}. * * <p>Delegates to the other one after extracting the referenced * Path from the Project. This checks also that the passed * Reference is pointing to a Path all right.</p> * @param p current Ant project * @param ref Reference to Path structure * @param reverseLoader if set to true this new loader will take * precedence over its parent (which is contra the regular * classloader behaviour) * @return The class loader */ public static ClassLoader getClassLoaderForPath( Project p, Reference ref, boolean reverseLoader) { String pathId = ref.getRefId(); Object path = p.getReference(pathId); if (!(path instanceof Path)) { throw new BuildException( "The specified classpathref %s does not reference a Path.", pathId); } String loaderId = MagicNames.REFID_CLASSPATH_LOADER_PREFIX + pathId; return getClassLoaderForPath(p, (Path) path, loaderId, reverseLoader); }
/** * Get a property. If all hooks return null, the default * tables will be used. * * <p>As of Ant 1.8.0 this method is never invoked by any code * inside of Ant itself.</p> * * @param ns namespace of the sought property. * @param name name of the sought property. * @param user True if this is a user property. * @return The property, if returned by a hook, or null if none. * @deprecated PropertyHelper chaining is deprecated. */ @Deprecated public Object getPropertyHook(String ns, String name, boolean user) { if (getNext() != null) { Object o = getNext().getPropertyHook(ns, name, user); if (o != null) { return o; } } // Experimental/Testing, will be removed if (project != null && name.startsWith("toString:")) { name = name.substring("toString:".length()); Object v = project.getReference(name); return (v == null) ? null : v.toString(); } return null; }
/** * Return the value for the given attribute. * If we are not using semantic attributes, its just the * literal string value of the attribute. * * <p>If we <em>are</em> using semantic attributes, then first * dependent properties are resolved (i.e., ${foo} is resolved * based on the foo property value), and then an appropriate data * type is used. In particular, location-based properties are * resolved to absolute file names. Also for refid values, look * up the referenced object from the project.</p> */ private String getAttributeValue(Node attributeNode) { String nodeValue = attributeNode.getNodeValue().trim(); if (semanticAttributes) { String attributeName = attributeNode.getNodeName(); nodeValue = getProject().replaceProperties(nodeValue); if (LOCATION.equals(attributeName)) { File f = resolveFile(nodeValue); return f.getPath(); } if (REF_ID.equals(attributeName)) { Object ref = getProject().getReference(nodeValue); if (ref != null) { return ref.toString(); } } } return nodeValue; }
private void resolveRefid() { try { if (getProject() == null) { throw new BuildException("Cannot retrieve refid; project unset"); } Object o = getProject().getReference(refid); if (!(o instanceof Resource)) { if (o instanceof ResourceCollection) { ResourceCollection rc = (ResourceCollection) o; if (rc.size() == 1) { o = rc.iterator().next(); } } else { throw new BuildException("Illegal value at '%s': %s", refid, o); } } this.resource = (Resource) o; } finally { refid = null; } }
private InputHandler getInputHandler() { if (type != null) { return type.getInputHandler(); } if (refid != null) { try { return (InputHandler) (getProject().getReference(refid)); } catch (final ClassCastException e) { throw new BuildException( refid + " does not denote an InputHandler", e); } } if (classname != null) { return ClasspathUtils.newInstance(classname, createLoader(), InputHandler.class); } throw new BuildException( "Must specify refid, classname or type"); } }
@Override public void execute() throws BuildException { if (extensionPoint == null) { throw new BuildException("extensionPoint required", getLocation()); } if (getOwningTarget() == null || !getOwningTarget().getName().isEmpty()) { throw new BuildException("bindtargets only allowed as a top-level task"); } if (onMissingExtensionPoint == null) { onMissingExtensionPoint = OnMissingExtensionPoint.FAIL; } final ProjectHelper helper = getProject().getReference( ProjectHelper.PROJECTHELPER_REFERENCE); for (String target : targets) { helper.getExtensionStack().add(new String[] {extensionPoint, target, onMissingExtensionPoint.name()}); } } }
/** * {@inheritDoc} */ public synchronized Object getProxy() { if (getProject() == null) { throw new IllegalStateException(getTaskName() + "Project owner unset"); } hijackId(); if (getProject().hasReference(id)) { Object result = getProject().getReference(id); log("project reference " + id + "=" + String.valueOf(result), Project.MSG_DEBUG); return result; } throw new IllegalStateException("Unknown reference \"" + id + "\""); }
/** * Find a project component for a specific project, creating * it if it does not exist. * @param project the project. * @return the project component for a specific project. */ public static ComponentHelper getComponentHelper(Project project) { if (project == null) { return null; } // Singleton for now, it may change (per/classloader) ComponentHelper ph = project.getReference(COMPONENT_HELPER_REFERENCE); if (ph != null) { return ph; } ph = new ComponentHelper(); ph.setProject(project); project.addReference(COMPONENT_HELPER_REFERENCE, ph); return ph; }
/** * @return true if the reference exists and if type is set, if * the reference is the same type * @exception BuildException if an error occurs */ @Override public boolean eval() throws BuildException { if (ref == null) { throw new BuildException( "No reference specified for isreference condition"); } String key = ref.getRefId(); if (!getProject().hasReference(key)) { return false; } if (type == null) { return true; } Class<?> typeClass = getProject().getDataTypeDefinitions().get(type); if (typeClass == null) { typeClass = getProject().getTaskDefinitions().get(type); } // if the type is unknown, throw exception instead? return typeClass != null && typeClass.isAssignableFrom(getProject().getReference(key).getClass()); }
/** * Factory method to create a property processor. * Users can provide their own or replace it using "ant.PropertyHelper" * reference. User tasks can also add themselves to the chain, and provide * dynamic properties. * * @param project the project for which the property helper is required. * * @return the project's property helper. */ public static synchronized PropertyHelper getPropertyHelper(Project project) { PropertyHelper helper = null; if (project != null) { helper = project.getReference(MagicNames.REFID_PROPERTY_HELPER); } if (helper != null) { return helper; } helper = new PropertyHelper(); helper.setProject(project); if (project != null) { project.addReference(MagicNames.REFID_PROPERTY_HELPER, helper); } return helper; }
/** * Get a localproperties for the given project. * @param project the project to retrieve the localproperties for. * @return the localproperties. */ public static synchronized LocalProperties get(Project project) { LocalProperties l = project.getReference(MagicNames.REFID_LOCAL_PROPERTIES); if (l == null) { l = new LocalProperties(); project.addReference(MagicNames.REFID_LOCAL_PROPERTIES, l); PropertyHelper.getPropertyHelper(project).add(l); } return l; }
/** * Adds descriptive text to the project. * * @param text the descriptive text */ public void addText(String text) { ProjectHelper ph = getProject().getReference(ProjectHelper.PROJECTHELPER_REFERENCE); if (!(ph instanceof ProjectHelperImpl)) { // New behavior for delayed task creation. Description // will be evaluated in Project.getDescription() return; } String currentDescription = getProject().getDescription(); if (currentDescription == null) { getProject().setDescription(text); } else { getProject().setDescription(currentDescription + text); } }