ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@yahoo.com>
Subject Re: NestedElement weirdness
Date Wed, 09 May 2007 16:52:32 GMT
This probably isn't your whole problem, but right off
the bat you generally need to make your inner types
static.

HTH,
Matt

--- Kevin Jackson <foamdino@gmail.com> wrote:

> Hi all,
> 
> I've just spent a hugely frustrating 2 hours or so
> trying to get a
> simple nested element to work within a task.
> 
> -addElementName(ObjectType t) fails (task doesn't
> support nested element)
> -addConfiguredElementName(ObjectType t) fails
> -createElementName works
> 
> Here's pretty much the exact code from the ant
> manual
> 
> import org.apache.tools.ant.Task;
> import org.apache.tools.ant.BuildException;
> 
> import java.util.Vector;
> import java.util.Enumeration;
> /* from
>
http://ant.apache.org/manual/develop.html#nested-elements
>  * &
>
http://ant.apache.org/manual/tutorial-writing-tasks.html
>  */
> public class EchoTest extends Task {
>     private Vector messages = new Vector();
> 
> 
>     public void execute() throws BuildException {
>         for(Enumeration e = messages.elements();
> e.hasMoreElements();) {
>             getProject().log("MSG:
> "+((Message)e.nextElement()).getMessage());
>         }
>     }
> 
> // works
> //    public Message createMessage() {
> //        Message m = new Message();
> //        messages.add(m);
> //        return m;
> //    }
> 
> //doesn't
>     public void addMessage(Message m) {
>         messages.add(m);
>     }
> 
>     public class Message {
>         private String message;
>         public Message() {}
> 
>         public String getMessage() {
>             return message;
>         }
> 
>         public void setMessage(String message) {
>             this.message = message;
>         }
>     }
> }
> 
> and my build.xml:
> 
> <?xml version="1.0"?>
> <project name="test-dpkg" basedir=".">
>     <target name="init">
>         <taskdef name="my-echo"
>          
>
classname="org.apache.tools.ant.taskdefs.optional.dpkg.EchoTest"
>         />
>     </target>
> 
>     <target name="test" depends="init">
>       <my-echo>
>         <message message="1"/>
>         <message message="2"/>
>       </my-echo>
>     </target>
> </project>
> 
> output:
> kev@ubuntu-dev:~/IdeaProjects/ant-core-trunk$ ant
> -debug -f
> test-control-file.xml test
> Apache Ant version 1.7.1alpha compiled on May 9 2007
> Buildfile: test-control-file.xml
> Adding reference: ant.PropertyHelper
> Detected Java version: 1.6 in:
> /usr/lib/jvm/java-6-sun-1.6.0.00/jre
> Detected OS: Linux
> Adding reference: ant.ComponentHelper
> Setting ro project property: ant.file ->
>
/home/kev/IdeaProjects/ant-core-trunk/test-control-file.xml
> Adding reference: ant.projectHelper
> Adding reference: ant.parsing.context
> Adding reference: ant.targets
> parsing buildfile
>
/home/kev/IdeaProjects/ant-core-trunk/test-control-file.xml
> with URI =
>
file:/home/kev/IdeaProjects/ant-core-trunk/test-control-file.xml
> Setting ro project property: ant.project.name ->
> test-dpkg
> Adding reference: test-dpkg
> Setting ro project property: ant.file.test-dpkg ->
>
/home/kev/IdeaProjects/ant-core-trunk/test-control-file.xml
> Project base dir set to:
> /home/kev/IdeaProjects/ant-core-trunk
>  +Target:
>  +Target: init
>  +Target: test
> Attempting to create object of type
> org.apache.tools.ant.helper.DefaultExecutor
> Adding reference: ant.executor
> Build sequence for target(s) `test' is [init, test]
> Complete build sequence is [init, test, ]
> 
> init:
> [antlib:org.apache.tools.ant] Could not load
> definitions from resource
> org/apache/tools/ant/antlib.xml. It could not be
> found.
> Class
>
org.apache.tools.ant.taskdefs.optional.dpkg.ControlFileTask
> loaded from parent loader (parentFirst)
>  +Datatype control
>
org.apache.tools.ant.taskdefs.optional.dpkg.ControlFileTask
> Class
> org.apache.tools.ant.taskdefs.optional.dpkg.EchoTest
> loaded from
> parent loader (parentFirst)
>  +Datatype my-echo
> org.apache.tools.ant.taskdefs.optional.dpkg.EchoTest
> 
> test:
> 
> BUILD FAILED
>
/home/kev/IdeaProjects/ant-core-trunk/test-control-file.xml:18:
> my-echo doesn't support the nested "message"
> element.
>         at
>
org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:356)
>         at
>
org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:198)
>         at
>
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
>         at
> org.apache.tools.ant.Task.perform(Task.java:347)
>         at
> org.apache.tools.ant.Target.execute(Target.java:357)
>         at
>
org.apache.tools.ant.Target.performTasks(Target.java:385)
>         at
>
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1331)
>         at
>
org.apache.tools.ant.Project.executeTarget(Project.java:1300)
>         at
>
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>         at
>
org.apache.tools.ant.Project.executeTargets(Project.java:1183)
>         at
> org.apache.tools.ant.Main.runBuild(Main.java:758)
>         at
> org.apache.tools.ant.Main.startAnt(Main.java:217)
>         at
>
org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>         at
>
org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
> Caused by: The <my-echo> type doesn't support the
> nested "message" element.
>         at
>
org.apache.tools.ant.IntrospectionHelper.throwNotSupported(IntrospectionHelper.java:480)
>         at
>
org.apache.tools.ant.IntrospectionHelper.getNestedCreator(IntrospectionHelper.java:545)
>         at
>
org.apache.tools.ant.IntrospectionHelper.getElementCreator(IntrospectionHelper.java:608)
>         at
>
org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:543)
>         at
>
org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:343)
>         ... 13 more
> --- Nested Exception ---
> The <my-echo> type doesn't support the nested
> "message" element.
>         at
>
org.apache.tools.ant.IntrospectionHelper.throwNotSupported(IntrospectionHelper.java:480)
>         at
>
org.apache.tools.ant.IntrospectionHelper.getNestedCreator(IntrospectionHelper.java:545)
>         at
>
org.apache.tools.ant.IntrospectionHelper.getElementCreator(IntrospectionHelper.java:608)
>         at
>
org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:543)
>         at
>
org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:343)
>         at
>
org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:198)
>         at
>
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
>         at
> org.apache.tools.ant.Task.perform(Task.java:347)
>         at
> org.apache.tools.ant.Target.execute(Target.java:357)
>         at
>
org.apache.tools.ant.Target.performTasks(Target.java:385)
>         at
>
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1331)
>         at
>
org.apache.tools.ant.Project.executeTarget(Project.java:1300)
>         at
>
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>         at
>
org.apache.tools.ant.Project.executeTargets(Project.java:1183)
>         at
> org.apache.tools.ant.Main.runBuild(Main.java:758)
>         at
> org.apache.tools.ant.Main.startAnt(Main.java:217)
>         at
>
org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>         at
>
org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
> 
> I've been working on something more complex than
> this and couldn't get
> the nested elements to work, so I went back to the
> most basic task I
> could think of - the addElementName methods don't
> seem to work on svn
> trunk - which is obviously not true as this code is
> used throughout
> the codebase.
> 
> Can anyone see what I'm doing wrong here, or indeed
> reproduce what I'm
> seeing (and really not being able to believe right
> now). I know I'm
> dumb, but this shouldn't be that hard :(
> 
> Kev
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message