Defining Properties in an Antlib

View: New views
3 Messages — Rating Filter:   Alert me  

Defining Properties in an Antlib

by Dan Turkenkopf :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

by Jan.Materne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...]
>Gesendet: Donnerstag, 5. November 2009 19:28
>An: user@...
>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@...
For additional commands, e-mail: user-help@...


Parent Message unknown Re: Defining Properties in an Antlib

by Dan Turkenkopf :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> 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
>