Not sure if there’s documentation out there specifically for this, couldn’t find it after perusing the ant docs and experimenting a bit, but the main just is this:
Let’s say in my Ant build I want to collect all the images in a certain folder and all subfolders in that folder so I can run them through ImageMagick to convert and resize for mobile images. I use
<apply executable="\pathtoImageMagick\convert">
<fileset dir="${from.dir}/${dir.publish}/${dir.images}" />
<srcfile />
<arg value="-resize" />
<arg value="25%" />
<targetfile />
<mapper type="glob" from="*" to="${from.dir}/${dir.publish}/${dir.images}/mobile.*" />
</apply>
This works for first-level files, such that beside test.jpg I get mobile.test.jpg.
Unfortunately, if I have an image in a subfolder, say test.jpg in the folder ${from.dir}/${dir.publish}/${dir.images}/home and I want it to go to ${from.dir}/${dir.publish}/${dir.images}/home/mobile.test.jpg, how do I do this? It tried to create ${from.dir}/${dir.publish}/${dir.images}/mobile.home/test.jpg, which isn’t correct.
Any ideas from someone who has experience with Ant and mapper? Greatly appreciated.
Glob mapping isn’t useful here, because you want to interpose something in the middle of the matched ‘atom’. There is an example in the Ant documentation of this type of mapping that uses a
regexpmapper, something like:The
fromsays: grab the directory path to\1, grab the filename to\2. Then in thetothe prefix is inserted.