ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: File type mapping in external task
Date Wed, 04 Apr 2018 11:40:02 GMT
On 2018-04-03, Gilles Querret wrote:

> If I have an attribute mapped to a File type (such as setSrcDir(File file)
> { this.srcDir = file; } ), then passing an empty string (as in <MyTask
> srcDir="" ) leads to srcDir set to baseDir (or current directory, not sure).

baseDir :-)

> Is there a way to trap the empty string in the setter ? Or is it required
> to change the setter to accept a String parameter, and create the File
> object from the string ?

You will need the String-arg setter for that. The File (or Path) -arg
versions simply go through Project#resolveFile.

If you are using typed attribute setters you are all in on Ant's
behavior without any chance to tweak it.

An alternative may be a type of your own with a Project and String-arg
constructor, something like

public class MyFileWrapper {
    private final File file;

    public MyFileWrapper(Project p, String fileName) {
        if ("".equals(fileName)) {
            throw new BuildException("file name must not be empty");
        this.file = p.resolveFile(fileName);

    public File getFile() {
        return file;

public void setSrcDir(MyFileWrapper w) {
    this.srcDir = w.getFile();

which may be slightly better.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message