ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: Dynamic task parsing
Date Tue, 21 Sep 2004 06:46:13 GMT
First I dont see any sense in such a task - but thats my opinion :)

When implementing I would be most general as I can:
- specify the classname by attribute
- specify the method to start by attribute
Because it´s common to use several properties as nested elements, why not
doing that here also? So you´ll get something like
  <runjava classname="org.foo.Bar" method="run">
      <property name="val1" value="Hello"/>
      <property name="val2" value="World"/>
  </runjava>
Simply iterating over the property-List and using reflection for setting the
values. Seems to be more easier than handling with mapping (ok, to be
honest,
I just wrote a program with reflection so I am more familiar with that :)

Jan


> -----Ursprüngliche Nachricht-----
> Von: Miles Parker [mailto:milesparker@earthlink.net]
> Gesendet am: Dienstag, 21. September 2004 03:33
> An: user@ant.apache.org
> Betreff: Dynamic task parsing
> 
> 
> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message