ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miles Parker <milespar...@earthlink.net>
Subject Dynamic task parsing
Date Tue, 21 Sep 2004 01:32:37 GMT

I've been trying to implement a task that would allow one to specify a class and 
then values for the properties of that class as attributes. So follows a very 
simple example -- and yes, I know that I could accomplish this example task in 
some relativly easy ways but there is more to the task. I could also do this 
employing some kind of object/xml mapping, but I want to do it from within ant..


Assume org.foo.Bar with properties val1 and val2. RunJavaTask simply extends 
Task or UnknownElement with the className property and different logic I've 
tried. (See below.)

<project name="Run Class" default="run">
     ...
     <taskdef name="runjavaclass" classpath="${dir.classpath}" 
classname="org.foo.RunJavaTask"/>

     <target name="run some class">
         <runjavaclass className="org.foo.Bar" val1="Hello" val2="World">
         </runjavaclass>
     </target>
</project>


Or, something like..

     <target name="run some class">
         <runjavaclass className="org.foo.Bar">
             <properties val1="Hello" val2="World"/>
         </runjavaclass>
     </target>

Or other variations, including using elements, would work just as well. What I 
don't want to do is something like:

     <target name="run some class">
         <runjavaclass modelName="org.foo.Bar">
             <property name="val1" value="Hello"/>
             <property name="val2" value="World"/>
         </runjavaclass>
     </target>

And ideally you would still be able to report a parse error, e.g. "Property 
'val3' doesn't exist in org.foo.Bar.

Now, I've done a fair amount of reading up on the Task life cycle, including 
this excellent piece:

http://codefeed.com/tutorial/ant_config.html

And I'm thinking that somehow I need to use UnknownElement and 
RuntimeConfiguration to get this working. However everything I've tried so far 
(overriding maybeConfigure, for example) has got me stuck in a parsing/runtime 
chicken-and-egg problem; e.g. I can't find out what the class to instantiate is 
until it is too late to properly parse the remaining attributes.

thanks for any ideas or esp. usage examples..don't know if I've missed something 
obvious.

Miles


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


Mime
View raw message