Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@jakarta.apache.org Received: (qmail 4297 invoked by uid 500); 3 Jul 2001 22:05:08 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: ant-user@jakarta.apache.org Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 4283 invoked from network); 3 Jul 2001 22:05:07 -0000 Message-ID: <4E7888D4F219E145B6F81E5D3049E3BF1B10F8@scmail01.arsin.com> From: Peter Vogel To: "'ant-user@jakarta.apache.org'" Subject: RE: Approach to Conditionals: SOMETHING USEFUL ON THIS TOPIC Date: Tue, 3 Jul 2001 15:05:07 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Quite elegant! I like it, which probably means Peter D will -1 it :-) -Peter > -----Original Message----- > From: matt.inger@sedonacorp.com [mailto:matt.inger@sedonacorp.com] > Sent: Tuesday, July 03, 2001 12:38 PM > To: ant-user@jakarta.apache.org > Subject: Approach to Conditionals: SOMETHING USEFUL ON THIS TOPIC > > > ok, well i've been peeking at the "for-each" thread for a > while, and can see > where it's going. The bottom line is that many users see the need > for some form of simple control flow structures. Shouldn't tools > be driven by the basic user requirements? That's my $.02 on that > topic. And i won't get into the debate on inclusion into the core, > but rather support for users to create their own conditionals. > > Onto something more useful. It would be nice to modify > the ant core to be able to have one task execute a series of other > tasks. This would allow people to create their own types of custom > conditionals which would work from one version of ant to another. > Currently, you could in create a Task subsclass like: > ( I already have done this, so it works ) > > // ***************** BEGIN CODE > > public class TaskContainer extends Task > { > public Task createAnt() { ... }; > public Task createAntCall() { ... }; > > public void execute() throws BuildException > { /* execute all the created tasks underneath this one */ }; > } > > public class MyConditional extends TaskContainer > { > public void execute() throws BuildException > { > if (condition.evaluate()) super.execute(); > else { /* do some elseif style stuff here in the same manner */ } > } > > .... > } > > // ************************** END CODE > > but that creates trouble from one version of ant to another, > as you have > to make create methods in the TaskContainer for every builtin > and optional > task that ant defines. Plus the above way has the drawback > of not being able > to put custom tasks inside these task containers. What would > be an elegant > way to do this is to create the following class: > > // ********************* BEGIN CODE > > package org.apache.tools.ant; > > import java.util.ArrayList; > import java.util.Collections; > import java.util.Iterator; > import java.util.List; > > public class TaskContainer extends Task > { > protected List subtasks = new ArrayList(); > > void addSubtask(Task t) > { > subtasks.add(t); > } > > List getSubtasks() > { > return Collections.unmodifiableList(subtasks); > } > > protected void executeSubtasks() > throws BuildException > { > Iterator it = subtasks.iterator(); > while (it.hasNext()) > { > Task t = (Task)(it.next()); > t.execute(); > } > } > > public void execute() > throws BuildException > { > executeSubtasks(); > } > } > // ********************* END CODE ************* > > and then in IntrospectorHelper.java: > > // ********************** BEGIN CODE > public Object createElement(Object element, String elementName) > throws BuildException { > NestedCreator nc = (NestedCreator) > nestedCreators.get(elementName); > > if (nc == null && element instanceof TaskContainer) > { > TaskContainer task = (TaskContainer)element; > Project p = task.getProject(); > Map tasks = p.getTaskDefinitions(); > if (tasks.containsKey(elementName)) > { > Task t = p.createTask(elementName); > task.addSubtask(t); > return t; > } > } > else if (nc == null) { > String msg = "Class " + element.getClass().getName() + > " doesn't support the nested \"" + > elementName + "\" element"; > throw new BuildException(msg); > } > .... > } > > // ********************* END CODE ******************** > > and then you could extend TaskContainer as in the first example, > and simply call super.execute() whenever you wanted to execute > all the tasks that were added to the container. It doesn't throw off > the basic design of ant, and is a relatively simple and innocuous way > to allow users to add their own conditionals (or support future > conditionals in the core, if it's decided that they are to be added at > a later date). > > Thoughts anyone? > > Peter Donald wrote: > > > On Wed, 4 Jul 2001 01:06, Chris Greenlee wrote: > > > Peter (Donald), > > > > > > > > > Apologies, but your tone is quite often abusive. People who post > > > thoughtful comments ought not to be insulted just because > you disagree > > > with them. > > > > > > > If I post the same thing 15 times does it become thoughtful > the 15th time? I > > am not sure how long you have been on this list but he has > been repeating > > like a drone the same things over and over and over again > for a few months > > now. We listened the first time but now it is just noise. I > thought I was > > relatively polite given the history. > > > > > Now, to continue this thread with some responses to your > objections, as > > > I have seen them: > > > > > > Objection #1: Adding flow-of-control tasks makes Ant more > complex for > > > the user. > > > > > > Response #1: Adding more tasks -- any tasks -- increases > the complexity > > > of the tool, in a trivial sense: there are more tasks to > choose from, > > > and so choosing the appropriate task to use requires reading more > > > documentation. Adding if/then, switch, foreach, etc. tasks or > > > constructs will, in this trivial sense, increase the > complexity of the > > > tool. However, people are not required to use each and every task > > > provided with Ant. I myself use only about 14 Ant tasks > -- , > > > , , , , , > , , > > > , , , , , and > > >