Thank you Stefan ! I was a bit afraid of duplicating the logic for String
to File mapping, but if it's just about using Project#resolveFile then I'll
do it.
Gilles
On Wed, Apr 4, 2018 at 1:40 PM, Stefan Bodewig <bode...@apache.org> wrote:
> 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.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
> For additional commands, e-mail: dev-h...@ant.apache.org
>
>
--
Gilles QUERRET
Riverside Software
15d route de Bellevue • 69440 Mornant • France
Mob : +33 662.525.532