/** * 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); }
/** * Create an object for a component. * * @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 Object createComponent(String componentName) { AntTypeDefinition def = getDefinition(componentName); return def == null ? null : def.create(project); }
/** * 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()); }
AntTypeDefinition def = getDefinition(componentName); if (def == null) {
/** * 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); }
/** * 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; }
/** * 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"); } }
/** * Returns whether the specified element name is known */ protected boolean isKnownElement(String elementName) { if (elementName.equals("target") || elementName.equals("project") || elementName.equals("extension-point")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return true; } AntProjectNode node = antModel.getProjectNode(); if (node != null) { Project antProject = node.getProject(); ComponentHelper helper = ComponentHelper.getComponentHelper(antProject); if (helper.getDefinition(elementName) != null) { return true; } if (helper.getDefinition(antModel.getNamespaceCorrectName(elementName)) != null) { return true; } // not everything is a task or type (nested elements) if (getDtd().getElement(elementName) != null) { return true; } if (getNestedType() != null) { return true; } } return false; }
private String getTaskTypePart(AntTaskNode node) { AntProjectNode projectNode = node.getProjectNode(); if (projectNode != null) { Project antProject = projectNode.getProject(); AntTypeDefinition definition = ComponentHelper.getComponentHelper(antProject).getDefinition(node.getTask().getTaskName()); if (definition == null) { return null; } String className = definition.getClassName(); if (className.indexOf("taskdef") != -1) { //$NON-NLS-1$ return "Tasks"; //$NON-NLS-1$ } return "Types"; //$NON-NLS-1$ } return null; } }