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:[EMAIL PROTECTED] 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:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]