Fields Summary |
---|
private org.apache.tools.ant.util.ScriptRunnerHelper | helperscript runner helper |
private org.apache.tools.ant.util.ScriptRunnerBase | runnerUsed to run the script |
private String | namethe name by which this script will be activated |
private List | attributesAttributes definitions of this script |
private List | nestedElementsNested Element definitions of this script |
private Set | attributeSetThe attribute names as a set |
private Map | nestedElementMapThe nested element definitions indexed by their names |
Methods Summary |
---|
public void | addAttribute(org.apache.tools.ant.taskdefs.optional.script.ScriptDef$Attribute attribute)Add an attribute definition to this script.
attributes.add(attribute);
|
public void | addElement(org.apache.tools.ant.taskdefs.optional.script.ScriptDef$NestedElement nestedElement)Add a nested element definition.
nestedElements.add(nestedElement);
|
public void | addText(java.lang.String text)Set the script text.
helper.addText(text);
|
public java.lang.Object | createNestedElement(java.lang.String elementName)Create a nested element to be configured.
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;
|
public void | execute()Define the script.
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 = null;
Project p = getProject();
synchronized (p) {
scriptRepository =
(Map) p.getReference(MagicNames.SCRIPT_REPOSITORY);
if (scriptRepository == null) {
scriptRepository = new HashMap();
p.addReference(MagicNames.SCRIPT_REPOSITORY,
scriptRepository);
}
}
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(java.util.Map attributes, java.util.Map elements)Execute the script.
executeScript(attributes, elements, null);
|
public void | executeScript(java.util.Map attributes, java.util.Map elements, ScriptDefBase instance)Execute the script.
This is called by the script instance to execute the script for this
definition.
runner.addBean("attributes", attributes);
runner.addBean("elements", elements);
runner.addBean("project", getProject());
if (instance != null) {
runner.addBean("self", instance);
}
runner.executeScript("scriptdef_" + name);
|
public boolean | isAttributeSupported(java.lang.String attributeName)Indicates whether the task supports a given attribute name
return attributeSet.contains(attributeName);
|
public void | setLanguage(java.lang.String language)Defines the language (required).
helper.setLanguage(language);
|
public void | setManager(java.lang.String manager)Defines the manager.
helper.setManager(manager);
|
public void | setName(java.lang.String name)set the name under which this script will be activated in a build
file
this.name = name;
|
public void | setProject(org.apache.tools.ant.Project project)Set the project.
super.setProject(project);
helper.setProjectComponent(this);
helper.setSetBeans(false);
|
public void | setSrc(java.io.File file)Load the script from an external file ; optional.
helper.setSrc(file);
|