Browse Source

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
master
Stefan Bodewig 24 years ago
parent
commit
cfd119edd2
4 changed files with 66 additions and 27 deletions
  1. +2
    -0
      WHATSNEW
  2. +1
    -0
      src/main/org/apache/tools/ant/Project.java
  3. +20
    -3
      src/main/org/apache/tools/ant/ProjectHelper.java
  4. +43
    -24
      src/main/org/apache/tools/ant/Target.java

+ 2
- 0
WHATSNEW View File

@@ -73,6 +73,8 @@ Other changes:
temporary file for sourcefile and package names - helps to defeat temporary file for sourcefile and package names - helps to defeat
command line length limitations. command line length limitations.


* Data types like <path> can now be defined inside of <target>s

Fixed bugs: Fixed bugs:
----------- -----------




+ 1
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -1034,6 +1034,7 @@ public class Project {
} }


public void addReference(String name, Object value) { public void addReference(String name, Object value) {
log("Adding reference: " + name + " -> " + value, MSG_DEBUG);
references.put(name,value); references.put(name,value);
} }




+ 20
- 3
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -430,7 +430,11 @@ public class ProjectHelper {
} }


public void startElement(String name, AttributeList attrs) throws SAXParseException { 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. * Handler for all data types at global level.
*/ */
private class DataTypeHandler extends AbstractHandler { private class DataTypeHandler extends AbstractHandler {
private Target target;
private Object element; private Object element;
private RuntimeConfigurable wrapper = null;


public DataTypeHandler(DocumentHandler parentHandler) { public DataTypeHandler(DocumentHandler parentHandler) {
this(parentHandler, null);
}

public DataTypeHandler(DocumentHandler parentHandler, Target target) {
super(parentHandler); super(parentHandler);
this.target = target;
} }


public void init(String propType, AttributeList attrs) throws SAXParseException { public void init(String propType, AttributeList attrs) throws SAXParseException {
@@ -584,7 +595,13 @@ public class ProjectHelper {
} }
configureId(element, attrs); 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) { } catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), locator, exc); throw new SAXParseException(exc.getMessage(), locator, exc);
} }
@@ -599,7 +616,7 @@ public class ProjectHelper {
} }


public void startElement(String name, AttributeList attrs) throws SAXParseException { 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);
} }
} }




+ 43
- 24
src/main/org/apache/tools/ant/Target.java View File

@@ -68,7 +68,7 @@ public class Target {
private String ifCondition = ""; private String ifCondition = "";
private String unlessCondition = ""; private String unlessCondition = "";
private Vector dependencies = new Vector(2); private Vector dependencies = new Vector(2);
private Vector tasks = new Vector(5);
private Vector children = new Vector(5);
private Project project; private Project project;
private String description = null; private String description = null;


@@ -99,15 +99,28 @@ public class Target {
} }


public void addTask(Task task) { 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. * @return The current set of tasks.
*/
*/
public Task[] getTasks() { 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()]; Task[] retval = new Task[tasks.size()];
tasks.copyInto(retval); tasks.copyInto(retval);
return retval; return retval;
@@ -143,25 +156,31 @@ public class Target {


public void execute() throws BuildException { public void execute() throws BuildException {
if (testIfCondition() && testUnlessCondition()) { if (testIfCondition() && testUnlessCondition()) {
Enumeration enum = tasks.elements();
Enumeration enum = children.elements();
while (enum.hasMoreElements()) { 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()) { } else if (!testIfCondition()) {
@@ -175,8 +194,8 @@ public class Target {


void replaceTask(UnknownElement el, Task t) { void replaceTask(UnknownElement el, Task t) {
int index = -1; int index = -1;
while ((index = tasks.indexOf(el)) >= 0) {
tasks.setElementAt(t, index);
while ((index = children.indexOf(el)) >= 0) {
children.setElementAt(t, index);
} }
} }




Loading…
Cancel
Save