You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dan Turkenkopf <dt...@gmail.com> on 2009/11/05 19:28:07 UTC
Defining Properties in an Antlib
Is there anyway to define a single set of properties that can be shared
across all macrodefs in a given antlib?
I have a series of macros that all refer to the same jar files. I'd like
to be able to define the locations in a single property within the antlib
(because the callers don't need to know the details).
Right now, because Property doesn't extend AntlibDefinition, I can't declare
a property outside of a macrodef. So I'm stuck declaring the same property
within each of the macrodefs.
Is there a better way to accomplish the goal of DRY?
Thanks,
Dan Turkenkopf
AW: Defining Properties in an Antlib
Posted by Ja...@rzf.fin-nrw.de.
I only see an init macro which sets the values.
Jan
<project xmlns:my="antlib:my">
<taskdef uri="antlib:my" resource="antlib.xml" classpath="."/>
<my:init/>
<my:hello/>
<echoproperties prefix="my."/>
</project>
<antlib xmlns:current="ant:current">
<macrodef name="init">
<sequential>
<property name="my.--flag--" value="set"/>
<property name="my.text" value="Hello World"/>
</sequential>
</macrodef>
<presetdef name="checkinit">
<fail unless="my.--flag--" message="You have to call the 'init' task before using any other."/>
</presetdef>
<macrodef name="hello">
<sequential>
<current:checkinit/>
<echo message="Hello" taskname="hello"/>
</sequential>
</macrodef>
</antlib>
>-----Ursprüngliche Nachricht-----
>Von: Dan Turkenkopf [mailto:dturkenk@gmail.com]
>Gesendet: Donnerstag, 5. November 2009 19:28
>An: user@ant.apache.org
>Betreff: Defining Properties in an Antlib
>
>Is there anyway to define a single set of properties that can be shared
>across all macrodefs in a given antlib?
>
>I have a series of macros that all refer to the same jar
>files. I'd like
>to be able to define the locations in a single property within
>the antlib
>(because the callers don't need to know the details).
>
>Right now, because Property doesn't extend AntlibDefinition, I
>can't declare
>a property outside of a macrodef. So I'm stuck declaring the
>same property
>within each of the macrodefs.
>
>Is there a better way to accomplish the goal of DRY?
>
>Thanks,
>
>Dan Turkenkopf
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Defining Properties in an Antlib
Posted by Dan Turkenkopf <dt...@gmail.com>.
Thanks for the help,
I decided to use the init macro rather than bringing in another dependency
and it seems to work well.
-- Dan
On Fri, Nov 6, 2009 at 7:26 AM, Wascally Wabbit <
wascallywabbit@earthling.net> wrote:
> Dan Turkenkopf wrote:
>
>> Is there anyway to define a single set of properties that can be shared
>> across all macrodefs in a given antlib?
>>
>> I have a series of macros that all refer to the same jar files. I'd like
>> to be able to define the locations in a single property within the antlib
>> (because the callers don't need to know the details).
>>
>> Right now, because Property doesn't extend AntlibDefinition, I can't
>> declare
>> a property outside of a macrodef. So I'm stuck declaring the same
>> property
>> within each of the macrodefs.
>>
>> Is there a better way to accomplish the goal of DRY?
>>
>> Thanks,
>>
>> Dan Turkenkopf
>>
>>
> The init macro another user recommended is one way to do this; an
> alternative is to use AntXtras (3rd party extension) and use the <doinline>
> component like:
>
> <antlib....>
> <doinline>
> <property name="1st" value="v1"/>
> <property name="2nd" value="v2"/>
> ...
> </doinline>
> </antlib>
>
> The difference? You won't need to do the explicit "init" call. Note that if
> you've installed AntXtras in its own namespace you'd need to account for
> that in the example shown above.
>
> -The Wabbit
>