tags:

views:

68

answers:

2

I have created an Ant task, wherein i would like to have an property array? First of all, is it possible? Does ant allows us to have a property array?

public class MyTask extends Task {
    private String tokens[] = null;
    public void setTokens(String[] _tokens) {
        //...
    }
    public void execute() {
     // iterator over the conditions
    }
}

Now how to set tokens in ant build file?

A: 

You sound like you want to set multiple inner tags.

Writing your own task gives some guidelines. The section you are after is Supporting Nested Elements. It is pretty simple. I would be inclined to use something like the following

List tokens = new ArrayList();

public void addConfiguredToken(NestedElement token) {
    tokens.add(token);
}

You could then use it using something like the following

<task>
    <token value="XXX" />
    <token value="YYY" />
</task>
Michael Rutherfurd
+1  A: 

Ant has some types like DirList and FileSet as well - it's quite common to have a task that accepts an attribute that is an implicit list, and then iterate over the contents. If you're dealing with files, what's nice is that you can tell Ant to glob over them, store them in a FileSet, and pass that to your custom type.

Julian Simpson