/** * Run the definition. * This registers the XML namespace (URI) as a namespace for * attributes. */ public void execute() { String componentName = ProjectHelper.nsToComponentName( getURI()); AntTypeDefinition def = new AntTypeDefinition(); def.setName(componentName); def.setClassName(AttributeNamespace.class.getName()); def.setClass(AttributeNamespace.class); def.setRestrict(true); def.setClassLoader(AttributeNamespace.class.getClassLoader()); ComponentHelper.getComponentHelper(getProject()) .addDataTypeDefinition(def); } }
/** * 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); } }
/** * Load ant's tasks. */ private void initTasks() { ClassLoader classLoader = getClassLoader(null); Properties props = getDefaultDefinitions(false); for (String name : props.stringPropertyNames()) { AntTypeDefinition def = new AntTypeDefinition(); def.setName(name); def.setClassName(props.getProperty(name)); def.setClassLoader(classLoader); def.setAdaptToClass(Task.class); def.setAdapterClass(TaskAdapter.class); antTypeTable.put(name, def); } }
/** * 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); }
private void attributeNamespaceDef(String ns) { AntTypeDefinition def = new AntTypeDefinition(); def.setName(ProjectHelper.nsToComponentName(ns)); def.setClassName(OATA + "attribute.AttributeNamespace"); def.setClassLoader(getClass().getClassLoader()); def.setRestrict(true); componentHelper.addDataTypeDefinition(def); }
AntTypeDefinition def = new AntTypeDefinition(); def.setName(name); def.setClassName(classname); def.setClass(cl); def.setAdapterClass(adapterClass); def.setAdaptToClass(adaptToClass); def.setRestrict(restrict); def.setClassLoader(al); if (cl != null) { def.checkClass(getProject());
/** * Adds a new datatype definition. * Attempting to override an existing definition with an * equivalent one (i.e. with the same classname) results in * a verbose log message. Attempting to override an existing definition * with a different one results in a warning log message, but the * definition is changed. * * @param typeName The name of the datatype. * Must not be <code>null</code>. * @param typeClass The full name of the class implementing the datatype. * Must not be <code>null</code>. */ public void addDataTypeDefinition(String typeName, Class<?> typeClass) { final AntTypeDefinition def = new AntTypeDefinition(); def.setName(typeName); def.setClass(typeClass); updateDataTypeDefinition(def); project.log(" +User datatype: " + typeName + " " + typeClass.getName(), Project.MSG_DEBUG); }
/** * 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); }
private AntTypeDefinition getNestedType() { AntElementNode currentNode = antModel.getNode(cursorPosition, false); if (currentNode == null) { return null; } IAntElement parent = currentNode.getParentNode(); if (parent instanceof AntTaskNode) { String parentName = parent.getName(); if (hasNestedElements(parentName)) { AntTypeDefinition taskClass = getTaskClass(parentName); if (taskClass != null) { IntrospectionHelper helper = getIntrospectionHelper(taskClass); if (helper != null) { try { Class<?> nestedType = helper.getElementType(currentNode.getName()); // TODO probably a much better way to find the definition of a nested type than this AntTypeDefinition def = new AntTypeDefinition(); def.setClass(nestedType); def.setClassName(nestedType.getName()); return def; } catch (BuildException be) { // do nothing } } } } } return null; }
if (other == null || getClass() != other.getClass() || !getClassName().equals(other.getClassName()) || !extractClassname(adapterClass).equals( extractClassname(other.adapterClass)) || !extractClassname(adaptToClass).equals( extractClassname(other.adaptToClass)) || restrict != other.restrict) { return false; ClassLoader oldLoader = other.getClassLoader(); ClassLoader newLoader = getClassLoader(); return oldLoader == newLoader || (oldLoader instanceof AntClassLoader
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); }
} else { final String classname = def.getClassName(); antTask = classname.startsWith("org.apache.tools.ant."); boolean optional = classname.startsWith("org.apache.tools.ant.taskdefs.optional"); clazz = def.innerGetTypeClass(); } catch (ClassNotFoundException e) { jars = true; def.innerCreateAndSet(clazz, project);
/** * 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); } }
/** * 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); }
/** * Get the classname of the definition. * @return the name of the class of this definition. */ @Override public String getClassName() { return parent.getClassName(); }
/** * Perform common operations after the object building. */ private void postInit() { taskLinkFinder = new LinkFinderVisitor(this); // Change the component helper to instantiate SubAntHelper for subant // task. final ComponentHelper helper = antProject.getReference("ant.ComponentHelper"); if (helper != null) { final AntTypeDefinition subAntDef = helper.getDefinition("subant"); if (subAntDef == null) { LOG.warn("No definition found for the subant task in ComponentHelper, disabling subant"); } else { subAntDef.setClass(SubAntHelper.class); } final AntTypeDefinition taskDefDef = helper.getDefinition("taskdef"); if (taskDefDef == null) { LOG.warn("No definition found for the taskdef task in ComponentHelper, some file may not load properly"); } else { taskDefDef.setClass(TaskDefHelper.class); } } else { LOG.warn("No component helper in current project"); } }
name = ProjectHelper.genComponentName(getURI(), name); scriptRepository.put(name, this); AntTypeDefinition def = new AntTypeDefinition(); def.setName(name); def.setClass(ScriptDefBase.class); ComponentHelper.getComponentHelper( getProject()).addDataTypeDefinition(def);
/** * 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); }
/** * 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); }
AntTypeDefinition taskClass = getTaskClass(taskName); if (taskClass != null) { if (MACROINSTANCE_NAME.equals(taskClass.getClassName())) { addMacroDefAttributeProposals(taskName, prefix, proposals); } else {