| Method from org.apache.tools.ant.taskdefs.optional.script.ScriptDef Detail: |
public void add(ResourceCollection resource) {
helper.add(resource);
}
|
public void addAttribute(ScriptDef.Attribute attribute) {
attributes.add(attribute);
}
Add an attribute definition to this script. |
public void addElement(ScriptDef.NestedElement nestedElement) {
nestedElements.add(nestedElement);
}
Add a nested element definition. |
public void addText(String text) {
helper.addText(text);
}
|
public Object createNestedElement(String elementName) {
NestedElement definition
= (NestedElement) nestedElementMap.get(elementName);
if (definition == null) {
throw new BuildException("< " + name + " > does not support "
+ "the < " + elementName + " > nested element");
}
Object instance = null;
String classname = definition.className;
if (classname == null) {
instance = getProject().createTask(definition.type);
if (instance == null) {
instance = getProject().createDataType(definition.type);
}
} else {
/*
// try the context classloader
ClassLoader loader
= Thread.currentThread().getContextClassLoader();
*/
ClassLoader loader = createLoader();
try {
instance = ClasspathUtils.newInstance(classname, loader);
} catch (BuildException e) {
instance = ClasspathUtils.newInstance(classname, ScriptDef.class.getClassLoader());
}
getProject().setProjectReference(instance);
}
if (instance == null) {
throw new BuildException("< " + name + " > is unable to create "
+ "the < " + elementName + " > nested element");
}
return instance;
}
Create a nested element to be configured. |
public void execute() {
if (name == null) {
throw new BuildException("scriptdef requires a name attribute to "
+ "name the script");
}
if (helper.getLanguage() == null) {
throw new BuildException("< scriptdef > requires a language attribute "
+ "to specify the script language");
}
// Check if need to set the loader
if (getAntlibClassLoader() != null || hasCpDelegate()) {
helper.setClassLoader(createLoader());
}
// Now create the scriptRunner
runner = helper.getScriptRunner();
attributeSet = new HashSet();
for (Iterator i = attributes.iterator(); i.hasNext();) {
Attribute attribute = (Attribute) i.next();
if (attribute.name == null) {
throw new BuildException("scriptdef < attribute > elements "
+ "must specify an attribute name");
}
if (attributeSet.contains(attribute.name)) {
throw new BuildException("scriptdef < " + name + " > declares "
+ "the " + attribute.name + " attribute more than once");
}
attributeSet.add(attribute.name);
}
nestedElementMap = new HashMap();
for (Iterator i = nestedElements.iterator(); i.hasNext();) {
NestedElement nestedElement = (NestedElement) i.next();
if (nestedElement.name == null) {
throw new BuildException("scriptdef < element > elements "
+ "must specify an element name");
}
if (nestedElementMap.containsKey(nestedElement.name)) {
throw new BuildException("scriptdef < " + name + " > declares "
+ "the " + nestedElement.name + " nested element more "
+ "than once");
}
if (nestedElement.className == null
&& nestedElement.type == null) {
throw new BuildException("scriptdef < element > elements "
+ "must specify either a classname or type attribute");
}
if (nestedElement.className != null
&& nestedElement.type != null) {
throw new BuildException("scriptdef < element > elements "
+ "must specify only one of the classname and type "
+ "attributes");
}
nestedElementMap.put(nestedElement.name, nestedElement);
}
// find the script repository - it is stored in the project
Map scriptRepository = lookupScriptRepository();
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);
}
|
public void executeScript(Map attributes,
Map elements) {
executeScript(attributes, elements, null);
} Deprecated! since - 1.7.
Use executeScript(attribute, elements, instance) instead.
|
public void executeScript(Map attributes,
Map elements,
ScriptDefBase instance) {
runner.addBean("attributes", attributes);
runner.addBean("elements", elements);
runner.addBean("project", getProject());
if (instance != null) {
runner.addBean("self", instance);
}
runner.executeScript("scriptdef_" + name);
}
Execute the script.
This is called by the script instance to execute the script for this
definition. |
public boolean isAttributeSupported(String attributeName) {
return attributeSet.contains(attributeName);
}
Indicates whether the task supports a given attribute name |
public void setLanguage(String language) {
helper.setLanguage(language);
}
Defines the language (required). |
public void setManager(String manager) {
helper.setManager(manager);
}
|
public void setName(String name) {
this.name = name;
}
set the name under which this script will be activated in a build
file |
public void setProject(Project project) {
super.setProject(project);
helper.setProjectComponent(this);
helper.setSetBeans(false);
}
|
public void setSrc(File file) {
helper.setSrc(file);
}
Load the script from an external file ; optional. |