git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File type mapping in external task


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 <bodewig@xxxxxxxxxx> 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-unsubscribe@xxxxxxxxxxxxxx
> For additional commands, e-mail: dev-help@xxxxxxxxxxxxxx
>
>


-- 
Gilles QUERRET

Riverside Software
15d route de Bellevue • 69440 Mornant • France
Mob : +33 662.525.532


( ! ) Warning: include(msgfooter.php): failed to open stream: No such file or directory in /var/www/git/apache-ant-development/msg01750.html on line 136
Call Stack
#TimeMemoryFunctionLocation
10.0009358376{main}( ).../msg01750.html:0

( ! ) Warning: include(): Failed opening 'msgfooter.php' for inclusion (include_path='.:/var/www/git') in /var/www/git/apache-ant-development/msg01750.html on line 136
Call Stack
#TimeMemoryFunctionLocation
10.0009358376{main}( ).../msg01750.html:0