开发者

Ant mapper and retaining folder structure

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:

<mapper type="regexp" from="(.*)/([^/]+)" to="\1/mobile.\2" />

The from says: grab the directory path to \1, grab the filename to \2. Then in the to the prefix is inserted.


Maybe I'm reading this wrong, but are you also trying to move/copy the images from one directory to another as a part of this?

If not, and you just need to map all *.jpg files in any subdirectory of ${from.dir}/${dir.publish}/${dir.images} to mobile.*.jpg, then try this:

<fileset includes="${from.dir}/${dir.publish}/${dir.images}/**/*" />
...
<mapper type="glob" from="*" to="mobile.*" />

The <fileset> element should include all files in all subdirectories of that path, and the mapper should prepend "mobile." to it's filename.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜