How to use property Array in ant Task?
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 开发者_如何学Cfile?
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>
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.
精彩评论