ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Tasks and TaskContainer
Date Fri, 23 Jan 2004 12:33:19 GMT
The unknownelement needs to be configured - see ant.taskdefs.Antlib for 
an example
or the attached example container.

Peter
Kichline, Don (EM, PTL) wrote:

>I am attempting to write a set of tasks for ant.  I am using ant 1.6 against
>either the sun jdk 1.4.2 or the ibm jdk 1.3.1.  In either case the results
>are the same.
>
>In my TaskContainer, I have a public void addTask (Task task ) method.  The
>task that is passed in is of type UnknownElement.  Looking at
>UnknownElement, there is a method called getTask to retrieve the real
>wrappered task.
>
>When ever I call this method, the real task is null.
>
>Any ideas of what I may be doing incorrectly?
>
>I have been looking at example code of other projects, ant-contrib, etc... 
>
>Thanks,
>
>Don Kichline
>
>
>Here is a sample of my code:
>
>public class ParentTask extends Task implements TaskContainer {
>	private List childList = new ArrayList();
>
>	public void addTask(Task task) {
>		childList.add(task);
>	}
>
>	public void execute() throws BuildException {
>		try {
>			UnknownElement task = null;
>			ChildTask child = null;
>			for (Iterator i = .iterator(); i.hasNext();) {
>				task = (UnknownElement)i.next();
>				child = (ChildTask)task.getTask();
>**********			child.someMethod(...);    <===  NullPointer
>Exception Here
>			}
>		}
>		catch ( Throwable th ) {
>			th.printStackTrace();
>		}
>		super.execute();
>	}
>}
>
>
>public class ChildTask extends Task {
>	private String command = null;
>
>	public void addText(String command) {
>		this.command = command;
>	}
>
>	public void execute() throws BuildException {
>		try {
>			//	Do Something
>		} catch (Throwable th) {
>			throw new BuildException(th);
>		}
>
>		super.execute();
>	}
>
>	public void someMethod(...) {
>		//	Set something
>	}
>}
>
><project name="test" default="about" basedir=".">
>	<taskdef name="parent" 
>			 classname="some.package.ParentTask"
>			 classpath="bin"/>
>			 
>	<taskdef name="child" 
>			 classname="some.package.ChildTask"
>			 classpath="bin"/>
>			 
>	<target name="about">
>		<parent>
>			<child>TEST</child>
>		</parent>
>	</target>			 
></project>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>  
>


Mime
View raw message