/** * Get the exposed class for this definition. * @param project the current project. * @return the exposed class. */ @Override public Class<?> getExposedClass(Project project) { return parent.getExposedClass(project); }
/** * Return the class of the component name. * * @param componentName the name of the component, if * the component is in a namespace, the * name is prefixed with the namespace uri and ":". * @return the class if found or null if not. */ public Class<?> getComponentClass(String componentName) { AntTypeDefinition def = getDefinition(componentName); return def == null ? null : def.getExposedClass(project); }
/** * Check if definition is a valid definition--it may be a * definition of an optional task that does not exist. * @param def the definition to test. * @return true if exposed type of definition is present. */ private boolean validDefinition(AntTypeDefinition def) { return !(def.getTypeClass(project) == null || def.getExposedClass(project) == null); }
/** * Equality method for this definition (assumes the names are the same). * * @param other another definition. * @param project the project the definition. * @return true if the definitions are the same. */ public boolean sameDefinition(AntTypeDefinition other, Project project) { return (other != null && other.getClass() == getClass() && other.getTypeClass(project).equals(getTypeClass(project)) && other.getExposedClass(project).equals(getExposedClass(project)) && other.restrict == restrict && other.adapterClass == adapterClass && other.adaptToClass == adaptToClass); }
/** * Returns the current type definition hashtable. The returned hashtable is * "live" and so should not be modified. * * @return a map of from type name to implementing class * (String to Class). */ public Hashtable<String, Class<?>> getDataTypeDefinitions() { synchronized (typeClassDefinitions) { synchronized (antTypeTable) { if (rebuildTypeClassDefinitions) { typeClassDefinitions.clear(); antTypeTable.entrySet().stream() .filter(e -> e.getValue().getExposedClass(project) != null && !Task.class.isAssignableFrom(e.getValue().getExposedClass(project))) .forEach(e -> typeClassDefinitions.put(e.getKey(), e.getValue().getTypeClass(project))); rebuildTypeClassDefinitions = false; } } } return typeClassDefinitions; }
/** * Returns the current task definition hashtable. The returned hashtable is * "live" and so should not be modified. Also, the returned table may be * modified asynchronously. * * @return a map of from task name to implementing class * (String to Class). */ public Hashtable<String, Class<?>> getTaskDefinitions() { synchronized (taskClassDefinitions) { synchronized (antTypeTable) { if (rebuildTaskClassDefinitions) { taskClassDefinitions.clear(); antTypeTable.entrySet().stream() .filter(e -> e.getValue().getExposedClass(project) != null && Task.class.isAssignableFrom(e.getValue().getExposedClass(project))) .forEach(e -> taskClassDefinitions.put(e.getKey(), e.getValue().getTypeClass(project))); rebuildTaskClassDefinitions = false; } } } return taskClassDefinitions; }
/** * Returns a description of the type of the given element. * <p> * This is useful for logging purposes. * * @param o The element to describe. * Must not be <code>null</code>. * @param brief whether to use a brief description. * @return a description of the element type. * * @since Ant 1.7 */ public String getElementName(Object o, boolean brief) { // PR: I do not know what to do if the object class // has multiple defines // but this is for logging only... Class<?> elementClass = o.getClass(); String elementClassname = elementClass.getName(); synchronized (antTypeTable) { for (AntTypeDefinition def : antTypeTable.values()) { if (elementClassname.equals(def.getClassName()) && (elementClass == def.getExposedClass(project))) { String name = def.getName(); return brief ? name : "The <" + name + "> type"; } } } return getUnmappedElementName(o.getClass(), brief); }
final Class<?> exposedClass = d.getExposedClass(helper.getProject()); if (exposedClass == null) { continue;
/** * Update the component definition table with a new or * modified definition. * @param def the definition to update or insert. */ private void updateDataTypeDefinition(AntTypeDefinition def) { String name = def.getName(); synchronized (antTypeTable) { rebuildTaskClassDefinitions = true; rebuildTypeClassDefinitions = true; final AntTypeDefinition old = antTypeTable.get(name); if (old != null) { if (sameDefinition(def, old)) { return; } Class<?> oldClass = old.getExposedClass(project); boolean isTask = oldClass != null && Task.class.isAssignableFrom(oldClass); project.log("Trying to override old definition of " + (isTask ? "task " : "datatype ") + name, (def.similarDefinition(old, project)) ? Project.MSG_VERBOSE : Project.MSG_WARN); } project.log(" +Datatype " + name + " " + def.getClassName(), Project.MSG_DEBUG); antTypeTable.put(name, def); } }
private MethodAndObject createRestricted( final ComponentHelper helper, final String elementName, final List<Method> addTypeMethods) { final Project project = helper.getProject(); final AntTypeDefinition restrictedDefinition = findRestrictedDefinition(helper, elementName, addTypeMethods); if (restrictedDefinition == null) { return null; } final Method addMethod = findMatchingMethod( restrictedDefinition.getExposedClass(project), addTypeMethods); if (addMethod == null) { throw new BuildException("Ant Internal Error - contract mismatch for " + elementName); } final Object addedObject = restrictedDefinition.create(project); if (addedObject == null) { throw new BuildException( "Failed to create object " + elementName + " of type " + restrictedDefinition.getTypeClass(project)); } return new MethodAndObject(addMethod, addedObject); }
/** * test for a task or other ant type existing in the current project * @param typename the name of the type * @return true if the typename exists */ protected boolean doesTypeExist(String typename) { ComponentHelper helper = ComponentHelper.getComponentHelper(getProject()); String componentName = ProjectHelper.genComponentName(uri, typename); AntTypeDefinition def = helper.getDefinition(componentName); if (def == null) { return false; } //now verify that the class has an implementation boolean found = def.getExposedClass(getProject()) != null; if (!found) { String text = helper.diagnoseCreationFailure(componentName, "type"); log(text, Project.MSG_VERBOSE); } return found; }
private IntrospectionHelper getIntrospectionHelper(AntTypeDefinition taskClass) { Project p = antModel.getProjectNode().getProject(); Class<?> clazz = taskClass.getExposedClass(p); if (clazz != null) { IntrospectionHelper helper = null; try { helper = IntrospectionHelper.getHelper(antModel.getProjectNode().getProject(), clazz); } catch (NoClassDefFoundError e) { // ignore as a task may require additional classpath components } return helper; } return null; }