ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Advice on how to achieve setting properties on an arbitrary class
Date Wed, 13 Jul 2016 15:54:24 GMT
On 2016-07-12, Austin Brooks wrote:

> What is the best way to achieve something that can resemble the following?

> <healthCheck class="....urlCheck" serverPort="8080" path="/ping" />
> <healthCheck class="....portCheck" serverPort="8080" />

> Basically, I am trying to make an extendable health check task that takes a
> class and is then configured using additional attributes or elements. I am
> not overly restricted to a certain syntax.  The only real requirements I
> have are:
> 1. Is extendable by passing any class to the class attribute
> 2. Custom class is not tied to ant, will pass configuration via hash map or
> reflection property setting

> So is there a way to configure this by sub-elements or defining a method
> that is a collect all bucket for unknown attributes?

There are two approaches, which one is better in your case is not
completely clear to me.

The first approach is to take advantage of as much of Ant as
possible. If the classes you want to use provide setters you can use
Ant's attribute setting logic[1].

(1) You typedef the classes

<typedef name="urlCheck" classname="....urlCheck"/>

(2) create an instance of it and let Ant set the properties

<urlCheck serverPort="8080" path="/ping" id="pingCheck"/>

(3) Use references to use them inside your task

<healthCheck refid="pingCheck"/>

or alternatively if there is a commin interface of your check classes
you could use an "void add(TheCommonInterface)" method in healthCheck
and nest them directly like in

  <urlCheck serverPort="8080" path="/ping"/>

The alternative approach is to implement or its extension
DynamicConfigurator (or the NS aware variants) in your task, collect the
attributes and configure your checks programmatically.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message