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 17:56:55 GMT
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


Mime
View raw message