ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Cohen" <SCo...@sportvision.com>
Subject RE: <property refid=> question
Date Wed, 26 Feb 2003 18:56:59 GMT
I had been hoping to write a buildfile, not a task.  The buildfile would
contain a generic target, callable from a number of other buildfiles,
but it should not blow up
just because a refid is not defined there.  I want it to do nothing if
the reference
has not been defined.  I don't want to have to define an empty fileset
in every file that calls this target.

Since I don't want to advance my whole shop to using an intermediate
version of 1.6,
or to go through the messiness of adding custom tasks to their build
scripts, I am still looking for a way to do this on the 1.5.1 codebase.
Before I give up on this, one more question:

What happens when a fileset id is redefined?  Is it an error or does the
redefinition simply not take place as for a property?

-----Original Message-----
From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com] 
Sent: Wednesday, February 26, 2003 12:38 PM
To: Ant Users List
Subject: Re: <property refid=> question


Sorry... I guess I'm confused.  I thought originally you were writing a 
custom task and wanted it to be flexible about whether a datatype 
existed or not.  But, yes, the <isreference> is in 1.6, not 1.5.

	Erik


On Wednesday, February 26, 2003, at 12:56  PM, Steve Cohen wrote:

> Ah, so you're talking about writing a task in java.  I take it that 
> there is no way to accomplish this using the collection of tasks and 
> types that are included in the ant distribution?
>
> -----Original Message-----
> From: Dominique Devienne [mailto:DDevienne@lgc.com]
> Sent: Wednesday, February 26, 2003 11:40 AM
> To: 'Ant Users List'
> Subject: RE: <property refid=> question
>
>
> Here's the pattern I've been using myself... --DD
>
> public class MyTask extends Task {
>
>   private MyAttr _myAttr;
>
>   public void setMyAttrRef(String attrRef) {
>     _myAttr = (MyAttr)assertReferenceType(getProject(), attrRef,
>                                           MyAttr.class,
"<myAttrRef>");
>   }
>
>   private static Object assertReferenceType(Project prj, String ref,
>                                             Class cls, String name) {
>     Object o = prj.getReference(ref);
>     if (o == null) {
>       throw new BuildException("Reference " + ref + " not found!");
>     }
>     if (!cls.isAssignableFrom(o.getClass())) {
>       throw new BuildException(ref + " not a " + name + "
reference!");
>     }
>     return o;
>   }
> }
>
> PS: Usually, MyAttr would extend DataType.
>
> -----Original Message-----
> From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com]
> Sent: Wednesday, February 26, 2003 11:26 AM
> To: Ant Users List
> Subject: Re: <property refid=> question
>
> On Wednesday, February 26, 2003, at 12:16  PM, Steve Cohen wrote:
>> So is there really no way to write a generic task that does something

>> with a fileset if it is defined but nothing if it is not?  Or can I 
>> get around this by introducing a "default" empty definition of the 
>> reference?  Do references work like properties - first one to define 
>> it keeps it?  Or are they handled differently?
>
> You could always write your task to take a String argument that 
> represents the refid, and then look it up internally and deal with its

> potential non-existence yourself.
>
> I'm not sure, without digging a bit, whether using a Reference type or

> not would do the trick, but it might.
>
> 	Erik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


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


Mime
View raw message