Phing UpToDateTask with mapper?
Can someone give me an example of how to use Phin开发者_开发百科g's UpToDateTask
with a
mapper? I can't figure it out and I can't find any examples on the net.
Here's what I am trying to achieve. I have a bunch of SCSS files that I
convert to CSS using the ExecTask
and Ruby's SASS parser. But, I only
want to regenerate the CSS files if any of the source files have changed.
The source SCSS files are in app/assets/css
and the compiled files are
placed in app/webroot/css
. How can I use the UpToDateTask
to test if any
of the files in app/assets/css
are newer than any of the files in
app/webroot/css
?
Note that the SASS comilation does not have a 1-to-1 filename mapping to
CSS files. There could be a dozen SCSS files that in the end get
compiled into 3-4 CSS files. I know I could simply hard-code those CSS files into my build.xml
but I would like to create a more generic, re-usable build target.
Thanks in advance!
If you know in advance which result files will exist, you can use an identity mapper to check if each of the source files are newer than a single result file. Do that for each result file, and you'll know if there have been changes.
I figured it out for myself using trial and error. The scenario I described above (testing if any file in a source directory is newer than any file in a destination directory) cannot be achieved using a mapper in the uptodate
task. The uptodate
task simply iterates over the fileset
, converts any filename using the mapper
and then compares that file with the original file.
For the time being I am using a fileset that includes all files that do not start with an underscore (which are SASS includes) and a simple mapper that just globs *.scss
to *.css
. It works, but it's not perfect. When only one of the include files changes (those starting with an underscore) then Phing will not detect any changes and skip rebuilding the CSS assets.
精彩评论