You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/12/14 12:15:43 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant Project.java RuntimeConfigurable.java Target.java Task.java UnknownElement.java
bodewig 01/12/14 03:15:42
Modified: src/main/org/apache/tools/ant Project.java
RuntimeConfigurable.java Target.java Task.java
UnknownElement.java
Log:
Fix taskdef testcase in a rather hacky way. This one doesn't address
child elements of user defined tasks that override built-in tasks.
Revision Changes Path
1.89 +48 -3 jakarta-ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- Project.java 2001/12/13 11:53:43 1.88
+++ Project.java 2001/12/14 11:15:42 1.89
@@ -114,6 +114,7 @@
private String defaultTarget;
private Hashtable dataClassDefinitions = new Hashtable();
private Hashtable taskClassDefinitions = new Hashtable();
+ private Hashtable createdTasks = new Hashtable();
private Hashtable targets = new Hashtable();
private FilterSet globalFilterSet = new FilterSet();
private FilterSetCollection globalFilters = new FilterSetCollection(globalFilterSet);
@@ -589,9 +590,18 @@
* conditions, that will cause the task execution to fail.
*/
public void addTaskDefinition(String taskName, Class taskClass) throws BuildException {
- if (null != taskClassDefinitions.get(taskName)) {
- log("Trying to override old definition of task "+taskName,
- MSG_WARN);
+ Class old = (Class)taskClassDefinitions.get(taskName);
+ if (null != old) {
+ if (old.equals(taskClass)) {
+ log("Ignoring override for task " + taskName
+ + ", it is already defined by the same class.",
+ MSG_VERBOSE);
+ return;
+ } else {
+ log("Trying to override old definition of task "+taskName,
+ MSG_WARN);
+ invalidateCreatedTasks(taskName);
+ }
}
String msg = " +User task: " + taskName + " " + taskClass.getName();
@@ -751,11 +761,46 @@
String msg = " +Task: " + taskType;
log (msg, MSG_DEBUG);
+ addCreatedTask(taskType, task);
return task;
} catch (Throwable t) {
String msg = "Could not create task of type: "
+ taskType + " due to " + t;
throw new BuildException(msg, t);
+ }
+ }
+
+ /**
+ * Keep a record of all tasks that have been created so that they
+ * can be invalidated if a taskdef overrides the definition.
+ */
+ private void addCreatedTask(String type, Task task) {
+ synchronized (createdTasks) {
+ Vector v = (Vector) createdTasks.get(type);
+ if (v == null) {
+ v = new Vector();
+ createdTasks.put(type, v);
+ }
+ v.addElement(task);
+ }
+ }
+
+ /**
+ * Mark tasks as invalid which no longer are of the correct type
+ * for a given taskname.
+ */
+ private void invalidateCreatedTasks(String type) {
+ synchronized (createdTasks) {
+ Vector v = (Vector) createdTasks.get(type);
+ if (v != null) {
+ Enumeration enum = v.elements();
+ while (enum.hasMoreElements()) {
+ Task t = (Task) enum.nextElement();
+ t.markInvalid();
+ }
+ v.removeAllElements();
+ createdTasks.remove(type);
+ }
}
}
1.11 +8 -2 jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
Index: RuntimeConfigurable.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RuntimeConfigurable.java 2001/11/27 18:04:51 1.10
+++ RuntimeConfigurable.java 2001/12/14 11:15:42 1.11
@@ -138,7 +138,7 @@
* Configure the wrapped element and all children.
*/
public void maybeConfigure(Project p) throws BuildException {
- String id = null;
+ String id = null;
if (attributes != null) {
ProjectHelper.configure(wrappedObject, attributes, p);
@@ -152,7 +152,13 @@
Enumeration enum = children.elements();
while (enum.hasMoreElements()) {
RuntimeConfigurable child = (RuntimeConfigurable) enum.nextElement();
- child.maybeConfigure(p);
+ if (child.wrappedObject instanceof Task) {
+ Task childTask = (Task) child.wrappedObject;
+ childTask.setRuntimeConfigurableWrapper(child);
+ childTask.maybeConfigure();
+ } else {
+ child.maybeConfigure(p);
+ }
ProjectHelper.storeChild(p, wrappedObject, child.wrappedObject, child.getElementTag().toLowerCase(Locale.US));
}
1.30 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/Target.java
Index: Target.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- Target.java 2001/12/12 09:17:36 1.29
+++ Target.java 2001/12/14 11:15:42 1.30
@@ -210,7 +210,7 @@
}
}
- void replaceChild(UnknownElement el, Object o) {
+ void replaceChild(Task el, Object o) {
int index = -1;
while ((index = children.indexOf(el)) >= 0) {
children.setElementAt(o, index);
1.23 +54 -15 jakarta-ant/src/main/org/apache/tools/ant/Task.java
Index: Task.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Task.java 2001/08/06 09:57:33 1.22
+++ Task.java 2001/12/14 11:15:42 1.23
@@ -68,6 +68,7 @@
protected String taskName = null;
protected String taskType = null;
protected RuntimeConfigurable wrapper;
+ private boolean invalid = false;
/**
* Sets the target object of this task.
@@ -174,8 +175,12 @@
* Configure this task - if it hasn't been done already.
*/
public void maybeConfigure() throws BuildException {
- if (wrapper != null) {
- wrapper.maybeConfigure(project);
+ if (!invalid) {
+ if (wrapper != null) {
+ wrapper.maybeConfigure(project);
+ }
+ } else {
+ getReplacement();
}
}
@@ -211,22 +216,56 @@
* Perform this task
*/
public final void perform() {
- try {
- project.fireTaskStarted(this);
- maybeConfigure();
- execute();
- project.fireTaskFinished(this, null);
- }
- catch(RuntimeException exc) {
- if (exc instanceof BuildException) {
- BuildException be = (BuildException) exc;
- if (be.getLocation() == Location.UNKNOWN_LOCATION) {
- be.setLocation(getLocation());
+ if (!invalid) {
+ try {
+ project.fireTaskStarted(this);
+ maybeConfigure();
+ execute();
+ project.fireTaskFinished(this, null);
+ }
+ catch(RuntimeException exc) {
+ if (exc instanceof BuildException) {
+ BuildException be = (BuildException) exc;
+ if (be.getLocation() == Location.UNKNOWN_LOCATION) {
+ be.setLocation(getLocation());
+ }
}
+ project.fireTaskFinished(this, exc);
+ throw exc;
}
- project.fireTaskFinished(this, exc);
- throw exc;
+ } else {
+ UnknownElement ue = getReplacement();
+ Task task = ue.getTask();
+ task.perform();
+ }
+ }
+
+ /**
+ * Mark this task as invalid.
+ */
+ final void markInvalid() {
+ invalid = true;
+ }
+
+ private UnknownElement replacement;
+
+ /**
+ * Create an UnknownElement that can be used to replace this task.
+ */
+ private UnknownElement getReplacement() {
+ if (replacement == null) {
+ replacement = new UnknownElement(taskType);
+ replacement.setProject(project);
+ replacement.setTaskType(taskType);
+ replacement.setTaskName(taskName);
+ replacement.setLocation(location);
+ replacement.setOwningTarget(target);
+ replacement.setRuntimeConfigurableWrapper(wrapper);
+ wrapper.setProxy(replacement);
+ target.replaceChild(this, replacement);
+ replacement.maybeConfigure();
}
+ return replacement;
}
}
1.16 +10 -0 jakarta-ant/src/main/org/apache/tools/ant/UnknownElement.java
Index: UnknownElement.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/UnknownElement.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- UnknownElement.java 2001/12/05 21:10:41 1.15
+++ UnknownElement.java 2001/12/14 11:15:42 1.16
@@ -238,4 +238,14 @@
super.getTaskName() : ((Task) realThing).getTaskName();
}
+ /**
+ * Return the task instance after it has been created (and if it is a task.
+ */
+ public Task getTask() {
+ if (realThing != null && realThing instanceof Task) {
+ return (Task) realThing;
+ }
+ return null;
+ }
+
}// UnknownElement
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant Project.java RuntimeConfigurable.java Target.java Task.java UnknownElement.java
Posted by Jose Alberto Fernandez <j_...@yahoo.com>.
Don't forget <typedef>s. You have to do the same thing
there.
Jose Alberto
--- bodewig@apache.org wrote: > bodewig 01/12/14
03:15:42
>
> Modified: src/main/org/apache/tools/ant
> Project.java
> RuntimeConfigurable.java
> Target.java Task.java
> UnknownElement.java
> Log:
> Fix taskdef testcase in a rather hacky way. This
> one doesn't address
> child elements of user defined tasks that override
> built-in tasks.
>
> Revision Changes Path
> 1.89 +48 -3
>
jakarta-ant/src/main/org/apache/tools/ant/Project.java
>
> Index: Project.java
>
>
===================================================================
> RCS file:
>
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
> retrieving revision 1.88
> retrieving revision 1.89
> diff -u -r1.88 -r1.89
> --- Project.java 2001/12/13 11:53:43 1.88
> +++ Project.java 2001/12/14 11:15:42 1.89
> @@ -114,6 +114,7 @@
> private String defaultTarget;
> private Hashtable dataClassDefinitions = new
> Hashtable();
> private Hashtable taskClassDefinitions = new
> Hashtable();
> + private Hashtable createdTasks = new
> Hashtable();
> private Hashtable targets = new Hashtable();
> private FilterSet globalFilterSet = new
> FilterSet();
> private FilterSetCollection globalFilters =
> new FilterSetCollection(globalFilterSet);
> @@ -589,9 +590,18 @@
> * conditions, that will cause the task
> execution to fail.
> */
> public void addTaskDefinition(String
> taskName, Class taskClass) throws BuildException {
> - if (null !=
> taskClassDefinitions.get(taskName)) {
> - log("Trying to override old
> definition of task "+taskName,
> - MSG_WARN);
> + Class old =
> (Class)taskClassDefinitions.get(taskName);
> + if (null != old) {
> + if (old.equals(taskClass)) {
> + log("Ignoring override for task "
> + taskName
> + + ", it is already defined by
> the same class.",
> + MSG_VERBOSE);
> + return;
> + } else {
> + log("Trying to override old
> definition of task "+taskName,
> + MSG_WARN);
> + invalidateCreatedTasks(taskName);
> + }
> }
>
> String msg = " +User task: " + taskName +
> " " + taskClass.getName();
> @@ -751,11 +761,46 @@
>
> String msg = " +Task: " + taskType;
> log (msg, MSG_DEBUG);
> + addCreatedTask(taskType, task);
> return task;
> } catch (Throwable t) {
> String msg = "Could not create task
> of type: "
> + taskType + " due to " + t;
> throw new BuildException(msg, t);
> + }
> + }
> +
> + /**
> + * Keep a record of all tasks that have been
> created so that they
> + * can be invalidated if a taskdef overrides
> the definition.
> + */
> + private void addCreatedTask(String type, Task
> task) {
> + synchronized (createdTasks) {
> + Vector v = (Vector)
> createdTasks.get(type);
> + if (v == null) {
> + v = new Vector();
> + createdTasks.put(type, v);
> + }
> + v.addElement(task);
> + }
> + }
> +
> + /**
> + * Mark tasks as invalid which no longer are
> of the correct type
> + * for a given taskname.
> + */
> + private void invalidateCreatedTasks(String
> type) {
> + synchronized (createdTasks) {
> + Vector v = (Vector)
> createdTasks.get(type);
> + if (v != null) {
> + Enumeration enum = v.elements();
> + while (enum.hasMoreElements()) {
> + Task t = (Task)
> enum.nextElement();
> + t.markInvalid();
> + }
> + v.removeAllElements();
> + createdTasks.remove(type);
> + }
> }
> }
>
>
>
>
> 1.11 +8 -2
>
jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
>
> Index: RuntimeConfigurable.java
>
>
===================================================================
> RCS file:
>
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
> retrieving revision 1.10
> retrieving revision 1.11
> diff -u -r1.10 -r1.11
> --- RuntimeConfigurable.java 2001/11/27 18:04:51
> 1.10
> +++ RuntimeConfigurable.java 2001/12/14 11:15:42
> 1.11
> @@ -138,7 +138,7 @@
> * Configure the wrapped element and all
> children.
> */
> public void maybeConfigure(Project p) throws
> BuildException {
> - String id = null;
> + String id = null;
>
> if (attributes != null) {
>
> ProjectHelper.configure(wrappedObject, attributes,
> p);
> @@ -152,7 +152,13 @@
> Enumeration enum = children.elements();
> while (enum.hasMoreElements()) {
> RuntimeConfigurable child =
> (RuntimeConfigurable) enum.nextElement();
> - child.maybeConfigure(p);
> + if (child.wrappedObject instanceof
> Task) {
> + Task childTask = (Task)
> child.wrappedObject;
> +
> childTask.setRuntimeConfigurableWrapper(child);
> + childTask.maybeConfigure();
> + } else {
> + child.maybeConfigure(p);
> + }
> ProjectHelper.storeChild(p,
> wrappedObject, child.wrappedObject,
> child.getElementTag().toLowerCase(Locale.US));
> }
>
>
>
>
> 1.30 +1 -1
>
jakarta-ant/src/main/org/apache/tools/ant/Target.java
>
> Index: Target.java
>
>
===================================================================
> RCS file:
>
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
> retrieving revision 1.29
> retrieving revision 1.30
> diff -u -r1.29 -r1.30
> --- Target.java 2001/12/12 09:17:36 1.29
> +++ Target.java 2001/12/14 11:15:42 1.30
> @@ -210,7 +210,7 @@
> }
> }
>
> - void replaceChild(UnknownElement el, Object
> o) {
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>