ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raphael PIERQUIN <>
Subject copy/map bug when no match
Date Thu, 07 Dec 2000 12:19:14 GMT
[I am an ant newbie, so I apologize if this message is off-topic
or just makes no sense.]

Here we go :

If I need to rename every file *.toto into *.tata,
I would intuitivly use a move task a follow :
    <move todir="mydir">
           <fileset dir="mydir"/>
           <mapper type="regexp" from="(.*)\.toto" to="\1\.tata" />

ant will throw a NullPointerException if the move task meets a file
that does not end in '.toto'

[my example might be easier to understand if you s/toto/foo/ and

A simple user fix is to add a 'includes="*.toto"' parameter in the
fileset element, but it did'nt came intuitivly to me.

The NullPointerException is thrown from taskdefs.Copy.buildMap(),
   File dest = new File(toDir, mapper.mapFileName(toCopy[i])[0]);
because FileNameMapper.mapFileName() has to return null if the rule
does not match.

I'm too ant newbie to fix it by myself, and I'm not familiar enough
with ant design to find out the best way to deal with this bug.
But here's my patch anyway :
I replaced the preceding quoted line with thoose ones :
   String[] targets = mapper.mapFileName(toCopy[i]);
   String destFileName = null;
   if ( targets != null )
	destFileName = targets[0];
	destFileName = toCopy[i];
   File dest = new File(toDir, destFileName);

This fix implies that mapper will use source file name as target file
name if the mapper rule does not match.  It might introduce ambigous
behaviour, or be incompatible with future developpement (multiple
mapper for example) so I don't know if it's the right way to do.

One might even say that this is not a bug, and that every renaming task
should come with a 'includes' parmater in the 'move' element. I would
just answer that it looks like unintuitive redundancy to me.

Anyway, I guess everyone agrees that unfriendly exception message
should be caught.

Btw, ant rocks, go on !
AGISphere S.A.

View raw message