/** * Add 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(final String typeName, final Class<?> typeClass) { ComponentHelper.getComponentHelper(this).addDataTypeDefinition(typeName, typeClass); }
/** * Return true if this Resource is selected. * @param r the Resource to check. * @return whether the Resource was selected. * @throws BuildException if an error occurs. */ public boolean isSelected(Resource r) { if ((clazz == null) == (type == null)) { throw new BuildException(ONE_ONLY); } Class<?> c = clazz; if (type != null) { if (project == null) { throw new BuildException( "No project set for InstanceOf ResourceSelector; the type attribute is invalid."); } AntTypeDefinition d = ComponentHelper.getComponentHelper( project).getDefinition(ProjectHelper.genComponentName(uri, type)); if (d == null) { throw new BuildException("type %s not found.",type); } try { c = d.innerGetTypeClass(); } catch (ClassNotFoundException e) { throw new BuildException(e); } } return c.isAssignableFrom(r.getClass()); }
/** * Return the current datatype definition hashtable. The returned * hashtable is "live" and so should not be modified. * * @return a map of from datatype name to implementing class * (String to Class). */ public Hashtable<String, Class<?>> getDataTypeDefinitions() { return ComponentHelper.getComponentHelper(this).getDataTypeDefinitions(); }
/** * Return the current task definition hashtable. The returned hashtable is * "live" and so should not be modified. * * @return a map of from task name to implementing class * (String to Class). */ public Hashtable<String, Class<?>> getTaskDefinitions() { return ComponentHelper.getComponentHelper(this).getTaskDefinitions(); }
/** * Create a new instance of a data type. * * @param typeName The name of the data type to create an instance of. * Must not be <code>null</code>. * * @return an instance of the specified data type, or <code>null</code> if * the data type name is not recognised. * * @exception BuildException if the data type name is recognised but * instance creation fails. */ public Object createDataType(final String typeName) throws BuildException { return ComponentHelper.getComponentHelper(this).createDataType(typeName); }
/** * Make a new definition. */ @Override public void execute() { if (nestedTask == null) { throw new BuildException("Missing nested element"); } if (name == null) { throw new BuildException("Name not specified"); } name = ProjectHelper.genComponentName(getURI(), name); ComponentHelper helper = ComponentHelper.getComponentHelper( getProject()); String componentName = ProjectHelper.genComponentName( nestedTask.getNamespace(), nestedTask.getTag()); AntTypeDefinition def = helper.getDefinition(componentName); if (def == null) { throw new BuildException( "Unable to find typedef %s", componentName); } PreSetDefinition newDef = new PreSetDefinition(def, nestedTask); newDef.setName(name); helper.addDataTypeDefinition(newDef); log("defining preset " + name, Project.MSG_VERBOSE); }
/** * Removes any type definitions that no longer exist in the buildfile */ private void reconcileTaskAndTypes() { if (fCurrentNodeIdentifiers == null || fDefinerNodeIdentifierToDefinedTasks == null) { return; } Iterator<String> iter = fDefinerNodeIdentifierToDefinedTasks.keySet().iterator(); ComponentHelper helper = ComponentHelper.getComponentHelper(fProjectNode.getProject()); while (iter.hasNext()) { String key = iter.next(); if (fCurrentNodeIdentifiers.get(key) == null) { removeDefinerTasks(key, helper.getAntTypeTable()); } } }
/** * 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; }
AntTypeDefinition def = getDefinition(componentName); if (def == null) { printUnknownDefinition(out, componentName, dirListing); definitions = true; } else { definitions = true; printClassNotFound(out, classname, optional, dirListing); } catch (NoClassDefFoundError ncdfe) { jars = true; printNotLoadDependentClass(out, optional, ncdfe, dirListing);
/** * Convenient way to get some element name even when you may not have a * Project context. * @param p The optional Project instance. * @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 static String getElementName(Project p, Object o, boolean brief) { if (p == null) { p = Project.getProject(o); } return p == null ? getUnmappedElementName(o.getClass(), brief) : getComponentHelper(p) .getElementName(o, brief); }
public void close() { Project project = getProject(); project.fireBuildFinished(null); ComponentHelper helper = ComponentHelper.getComponentHelper(project); helper.getAntTypeTable().clear(); helper.getDataTypeDefinitions().clear(); project.getReferences().clear(); }
ComponentHelper.getComponentHelper(project); helper.enterAntLib(uri); URLResource antlibResource = new URLResource(antlibUrl); try { return antlib; } finally { helper.exitAntLib();
"Not allowed to use the polymorphic form for this element"); final ComponentHelper helper = ComponentHelper.getComponentHelper(project); nestedObject = helper.createComponent(polyType); if (nestedObject == null) { throw new BuildException("Unable to create object of type " + polyType);
/** * Create a new instance of a task, adding it to a list of * created tasks for later invalidation. This causes all tasks * to be remembered until the containing project is removed * @param taskType The name of the task to create an instance of. * Must not be <code>null</code>. * * @return an instance of the specified task, or <code>null</code> if * the task name is not recognised. * * @exception BuildException if the task name is recognised but task * creation fails. */ public Task createTask(final String taskType) throws BuildException { return ComponentHelper.getComponentHelper(this).createTask(taskType); }
/** * Return a description of the type of the given element, with * special handling for instances of tasks and data types. * <p> * This is useful for logging purposes. * * @param element The element to describe. * Must not be <code>null</code>. * * @return a description of the element type. * * @since 1.95, Ant 1.5 */ public String getElementName(final Object element) { return ComponentHelper.getComponentHelper(this).getElementName(element); }
/** * Add a new task definition to the project. * 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 and * invalidates any tasks which have already been created with the * old definition. * * @param taskName The name of the task to add. * Must not be <code>null</code>. * @param taskClass The full name of the class implementing the task. * Must not be <code>null</code>. * * @exception BuildException if the class is unsuitable for being an Ant * task. An error level message is logged before * this exception is thrown. * * @see #checkTaskClass(Class) */ public void addTaskDefinition(final String taskName, final Class<?> taskClass) throws BuildException { ComponentHelper.getComponentHelper(this).addTaskDefinition(taskName, taskClass); }
/** * Initialise the project. * * This involves setting the default task definitions and loading the * system properties. * * @exception BuildException if the default task list cannot be loaded. */ public void init() throws BuildException { initProperties(); ComponentHelper.getComponentHelper(this).initDefaultDefinitions(); }
/** * Set the namespace of the XML element associated with this component. * This method is typically called by the XML processor. * If the namespace is "ant:current", the component helper * is used to get the current antlib uri. * * @param namespace URI used in the xmlns declaration. */ public void setNamespace(String namespace) { if (namespace.equals(ProjectHelper.ANT_CURRENT_URI)) { ComponentHelper helper = ComponentHelper.getComponentHelper( getProject()); namespace = helper.getCurrentAntlibUri(); } this.namespace = namespace == null ? "" : namespace; }
/** * Returns a very verbose exception for when a task/data type cannot * be found. * * @param what The kind of thing being created. For example, when * a task name could not be found, this would be * <code>"task"</code>. Should not be <code>null</code>. * @param name The name of the element which could not be found. * Should not be <code>null</code>. * * @return a detailed description of what might have caused the problem. */ protected BuildException getNotFoundException(String what, String name) { ComponentHelper helper = ComponentHelper.getComponentHelper(getProject()); String msg = helper.diagnoseCreationFailure(name, what); return new BuildException(msg, getLocation()); }
/** * 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); }