From cfd119edd23f56c4aa458d892285c6b038820ce2 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 8 Jun 2001 10:11:28 +0000 Subject: [PATCH] Allow data types to appear inside of targets. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269130 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 + src/main/org/apache/tools/ant/Project.java | 1 + .../org/apache/tools/ant/ProjectHelper.java | 23 ++++++- src/main/org/apache/tools/ant/Target.java | 67 ++++++++++++------- 4 files changed, 66 insertions(+), 27 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 2576c03db..ff3c67c39 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -73,6 +73,8 @@ Other changes: temporary file for sourcefile and package names - helps to defeat command line length limitations. +* Data types like can now be defined inside of s + Fixed bugs: ----------- diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index f04b700ba..2eee4c224 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -1034,6 +1034,7 @@ public class Project { } public void addReference(String name, Object value) { + log("Adding reference: " + name + " -> " + value, MSG_DEBUG); references.put(name,value); } diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java index bb4df2e07..c909060ce 100644 --- a/src/main/org/apache/tools/ant/ProjectHelper.java +++ b/src/main/org/apache/tools/ant/ProjectHelper.java @@ -430,7 +430,11 @@ public class ProjectHelper { } public void startElement(String name, AttributeList attrs) throws SAXParseException { - new TaskHandler(this, target).init(name, attrs); + if (project.getDataTypeDefinitions().get(name) != null) { + new DataTypeHandler(this, target).init(name, attrs); + } else { + new TaskHandler(this, target).init(name, attrs); + } } } @@ -570,10 +574,17 @@ public class ProjectHelper { * Handler for all data types at global level. */ private class DataTypeHandler extends AbstractHandler { + private Target target; private Object element; + private RuntimeConfigurable wrapper = null; public DataTypeHandler(DocumentHandler parentHandler) { + this(parentHandler, null); + } + + public DataTypeHandler(DocumentHandler parentHandler, Target target) { super(parentHandler); + this.target = target; } public void init(String propType, AttributeList attrs) throws SAXParseException { @@ -584,7 +595,13 @@ public class ProjectHelper { } configureId(element, attrs); - configure(element, attrs, project); + if (target != null) { + wrapper = new RuntimeConfigurable(element); + wrapper.setAttributes(attrs); + target.addDataType(wrapper); + } else { + configure(element, attrs, project); + } } catch (BuildException exc) { throw new SAXParseException(exc.getMessage(), locator, exc); } @@ -599,7 +616,7 @@ public class ProjectHelper { } public void startElement(String name, AttributeList attrs) throws SAXParseException { - new NestedElementHandler(this, element, null).init(name, attrs); + new NestedElementHandler(this, element, wrapper).init(name, attrs); } } diff --git a/src/main/org/apache/tools/ant/Target.java b/src/main/org/apache/tools/ant/Target.java index 7ce29bd24..35d884c2b 100644 --- a/src/main/org/apache/tools/ant/Target.java +++ b/src/main/org/apache/tools/ant/Target.java @@ -68,7 +68,7 @@ public class Target { private String ifCondition = ""; private String unlessCondition = ""; private Vector dependencies = new Vector(2); - private Vector tasks = new Vector(5); + private Vector children = new Vector(5); private Project project; private String description = null; @@ -99,15 +99,28 @@ public class Target { } public void addTask(Task task) { - tasks.addElement(task); + children.addElement(task); } - /** - * Get the current set of tasks to be executed by this target. - * + public void addDataType(RuntimeConfigurable r) { + children.addElement(r); + } + + /** + * Get the current set of tasks to be executed by this target. + * * @return The current set of tasks. - */ + */ public Task[] getTasks() { + Vector tasks = new Vector(children.size()); + Enumeration enum = children.elements(); + while (enum.hasMoreElements()) { + Object o = enum.nextElement(); + if (o instanceof Task) { + tasks.addElement(o); + } + } + Task[] retval = new Task[tasks.size()]; tasks.copyInto(retval); return retval; @@ -143,25 +156,31 @@ public class Target { public void execute() throws BuildException { if (testIfCondition() && testUnlessCondition()) { - Enumeration enum = tasks.elements(); + Enumeration enum = children.elements(); while (enum.hasMoreElements()) { - Task task = (Task) enum.nextElement(); - - try { - project.fireTaskStarted(task); - task.maybeConfigure(); - task.execute(); - project.fireTaskFinished(task, null); - } - catch(RuntimeException exc) { - if (exc instanceof BuildException) { - BuildException be = (BuildException) exc; - if (be.getLocation() == Location.UNKNOWN_LOCATION) { - be.setLocation(task.getLocation()); + Object o = enum.nextElement(); + if (o instanceof Task) { + Task task = (Task) o; + + try { + project.fireTaskStarted(task); + task.maybeConfigure(); + task.execute(); + project.fireTaskFinished(task, null); + } + catch(RuntimeException exc) { + if (exc instanceof BuildException) { + BuildException be = (BuildException) exc; + if (be.getLocation() == Location.UNKNOWN_LOCATION) { + be.setLocation(task.getLocation()); + } } + project.fireTaskFinished(task, exc); + throw exc; } - project.fireTaskFinished(task, exc); - throw exc; + } else { + RuntimeConfigurable r = (RuntimeConfigurable) o; + r.maybeConfigure(project); } } } else if (!testIfCondition()) { @@ -175,8 +194,8 @@ public class Target { void replaceTask(UnknownElement el, Task t) { int index = -1; - while ((index = tasks.indexOf(el)) >= 0) { - tasks.setElementAt(t, index); + while ((index = children.indexOf(el)) >= 0) { + children.setElementAt(t, index); } }