ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: expanding properties in custom task
Date Mon, 01 Sep 2003 07:39:45 GMT
I had written a tutorial on that, available on
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22570

On topic "Nested Text" that is described.

But where to put that tutorial? Manual or Wiki?
I think I try to put it on the Wiki today
http://nagoya.apache.org/wiki/apachewiki.cgi?AntTutorials



Jan



> -----Original Message-----
> From: Erik Hatcher [mailto:erik@ehatchersolutions.com]
> Sent: Monday, September 01, 2003 9:05 AM
> To: Ant Users List
> Subject: Re: expanding properties in custom task
> 
> 
> On Monday, September 1, 2003, at 02:01  AM, Jon Madison wrote:
> > Thanks greatly for the direction! Definitely my bad for the 
> laziness. 
> > I had
> > expected this to be mentioned in the doc (at least clearly?). I'll 
> > implement
> > and (if time permits) modify/submit changes to the documentation
> > accordingly.
> >
> > j.
> >
> 
> Well, just to make a shameless plug - it is "documented", in Java 
> Development with Ant:
> 
> CHAPTER 19 WRITING ANT TASKS
> 19.4.2 Handling element text
> Element text is handed to its containing object, typically the task 
> itself, or possibly a
> nested element, using the addText method. Of note is that the text is 
> provided as is,
> and no property references are expanded. Here is a simple 
> example of a 
> variant of the
> original MessageTask to take the message text as the element data 
> rather than from
> an attribute:
> 
> package org.example.antbook.tasks;
> import org.apache.tools.ant.Task;
> public class MessageTask2 extends Task {
>    private String message = "";
>    public void addText(String message) {
>      this.message = message;
>    }
> 
>    public void execute() {
>      log(message);
>    }
> }
> 
> Our build file fragment using this task is:
> 
>    <property name="another.message" value="light up ahead"/>
>    <message2>${another.message}</message2>
> 
> It generates this output:
> 
>    [message2] ${another.message}
> 
> Special method to accept element text
> Having the unaltered body text provided to the task is beneficial for 
> data that may
> contain such strings that appear like property references, but if you 
> need those references
> resolved, it's a simple matter of adding a call to a Project method. 
> Our execute
> method now becomes:
> 
> public void execute() {
>    log(getProject().replaceProperties(message));
> }
> 
> The results now have the property references resolved:
> 
>    [message2] light up ahead
> ------
> 
> Now that you know how to do it, where in the docs would be a 
> good place 
> to add this?  Care to submit a patch so that we can fold it in?
> 
> Or perhaps we could put this stuff on the Jakarta wiki pages for Ant?
> 
> 	Erik
> 
> 
> ---------------------------------------------------------------------
> 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