ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin de Dardel <benjamin.dedar...@gmail.com>
Subject Re: attribute name with dash
Date Wed, 08 Sep 2010 11:39:19 GMT
Wonderful, thank you for your responses.
They resolve my current problem
... and also an old one for ant4hg project, where the main task class
contains many many attributes !

2010/9/7 <Jan.Materne@rzf.fin-nrw.de>

> >> Is it possible to define attribute name with dash ?
> >
> >Not with Ant's built-in reflection logic.  Any attribute can only
> >consist of characters leagl inside a Java method name.
> >
> >You can define attributes with a dash when you implement
> >org.apache.tools.ant.DynamicAttribute or DynamicAttributeNS in which
> >case your setDynamicAttribute method will get invoked for any attribute
> >that does not directly map to a setter method.
>
> And a sample:
>
> <project>
>    <javac srcdir="." destdir="." includeantruntime="true"/>
>    <taskdef name="my" classname="MyTask" classpath="."/>
>    <my normal="normal" with-dash="with-dash" unknown="unknown"
> unknown2="two"/>
> </project>
>
> import org.apache.tools.ant.Task;
> import org.apache.tools.ant.DynamicAttribute;
> import java.util.*;
>
> public class MyTask extends Task implements DynamicAttribute {
>    String normal;
>    String withDash;
>    Map<String,String> otherData = new HashMap<String,String>();
>
>    public void setNormal(String s) {
>        this.normal = s;
>    }
>
>    public void setDynamicAttribute(String name, String value) {
>        if (name.equals("with-dash")) {
>            this.withDash = value;
>        } else {
>            otherData.put(name, value);
>        }
>    }
>
>    public void execute() {
>        log("normal   : " + normal);
>        log("with-dash: " + withDash);
>        if (!otherData.isEmpty()) {
>            for(String key : otherData.keySet()) {
>                log("- " + key + "=" + otherData.get(key));
>             }
>        }
>    }
> }
>
>
>
> Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message