There is an optional task called rennameext
that renames files from one extension to
another. It was available in Ant 1.2, and
works quite well:
<renameext srcDir="application/server/bin"
includes="**/*.bat.template"
fromExtension=".bat.template"
toExtension=".bat" />
Raphael PIERQUIN wrote:
> Hi,
> [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 :
> <my-example>
> <move todir="mydir">
> <fileset dir="mydir"/>
> <mapper type="regexp" from="(.*)\.toto" to="\1\.tata" />
> </move>
> </my-example>
>
> 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
> s/tata/bar/]
>
> 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(),
> line
> 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];
> else
> 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 !
> --
> Raphael PIERQUIN
> AGISphere S.A.
> [EMAIL PROTECTED]