ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles Scokart" <gscok...@gmail.com>
Subject Re: JavaFront update: TagBuilder
Date Fri, 31 Oct 2008 11:25:41 GMT
2008/10/31 Stefan Bodewig <bodewig@apache.org>:
> On Fri, 31 Oct 2008, Gilles Scokart <gscokart@gmail.com> wrote:
>
>> 2008/10/30 Stefan Bodewig <bodewig@apache.org>:
>>>    public void hello() {
>>>        TagBuilder.forProject(p)
>>>            .newTag("echo")
>>>            .withAttribute("message", "Hello, ${world}!")
>>>            .execute();
>>>    }
>>
>> Some alternatives  :
>>
>> public void hello() {
>>       EchoTask echo = TagBuilder.create(EchoTask.class , p);
>>       echo.setMessage("Hello, ${world}!");
>>       echo.execute();
>> }
>
> TagBuilder uses UnknownElement which means it can resolve task
> implementations, typedefs and so on.  Your example wouldn't resolve
> properties, BTW.

The idea was not to instanciate and execute the Task directly.
The idea was to produce a "builder" object with a more strongly typed API.

The echo object created can actually be a recorder object that fill an
UnknownElement.  The fact that this recorder can be declared as an
EchoTask is just a way to provide stronger typing.

This is the kind of technique is used by jmock or easymock.

(Note that's more complexe in my second example because there you have
to execute your project into a specific ClassLoader where all tasks
class are transformed into a recorder.)

>
> In current svn it reads
>
> EchoBuilder.echoMessage(p, "Hello, ${world}!");

This is obviously shorter :-)

-- 
Gilles Scokart

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


Mime
View raw message