/** * Create a list of all definitions that match a prefix, usually the URI * of a library * @param prefix prefix to match off * @return the (possibly empty) list of definitions */ private List<AntTypeDefinition> findTypeMatches(String prefix) { synchronized (antTypeTable) { return antTypeTable.values().stream().filter(def -> def.getName().startsWith(prefix)) .collect(Collectors.toList()); } } }
/** * update the restricted definition table with a new or * modified definition. */ private void updateRestrictedDefinition(AntTypeDefinition def) { String name = def.getName(); List<AntTypeDefinition> list = null; synchronized (restrictedDefinitions) { list = restrictedDefinitions.computeIfAbsent(name, k -> new ArrayList<>()); } // Check if the classname is already present and remove it // if it is synchronized (list) { for (Iterator<AntTypeDefinition> i = list.iterator(); i.hasNext();) { AntTypeDefinition current = i.next(); if (current.getClassName().equals(def.getClassName())) { i.remove(); break; } } list.add(def); } }
/** * Used with creating child projects. Each child * project inherits the component definitions * from its parent. * @param helper the component helper of the parent project. */ public void initSubProject(ComponentHelper helper) { // add the types of the parent project @SuppressWarnings("unchecked") final Hashtable<String, AntTypeDefinition> typeTable = (Hashtable<String, AntTypeDefinition>) helper.antTypeTable.clone(); synchronized (antTypeTable) { for (AntTypeDefinition def : typeTable.values()) { antTypeTable.put(def.getName(), def); } } // add the parsed namespaces of the parent project Set<String> inheritedCheckedNamespace = helper.getCheckedNamespace(); synchronized (this) { checkedNamespaces.addAll(inheritedCheckedNamespace); } Map<String, List<AntTypeDefinition>> inheritedRestrictedDef = helper.getRestrictedDefinition(); synchronized (restrictedDefinitions) { restrictedDefinitions.putAll(inheritedRestrictedDef); } }
out.println("The definitions in the namespace " + uri + " are:"); for (AntTypeDefinition def : matches) { String local = ProjectHelper.extractNameFromComponentName(def.getName()); out.println(" " + local);
/** * 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); }
/** * Checks if the attributes are correct. * <ul> * <li>if the class can be created.</li> * <li>if an adapter class can be created</li> * <li>if the type is assignable from adapter</li> * <li>if the type can be used with the adapter class</li> * </ul> * @param project the current project. */ public void checkClass(Project project) { if (clazz == null) { clazz = getTypeClass(project); if (clazz == null) { throw new BuildException( "Unable to create class for " + getName()); } } // check adapter if (adapterClass != null && (adaptToClass == null || !adaptToClass.isAssignableFrom(clazz))) { TypeAdapter adapter = (TypeAdapter) createAndSet( project, adapterClass); adapter.checkProxyClass(clazz); } }
/** * 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); } }