开发者

Apply-Task puts targetfile in wrong directory

I am about to create an apache ant target that compresses all my .js files with gzip. For no开发者_开发技巧w I came up with the following:

<target name="compress-js" description="Compressed JS files">
    <echo>Compressing JS files...</echo>
    <apply executable="gzip" parallel="false">
        <arg value="-c" />
        <arg value="--best" />
        <srcfile />
        <arg value=">" />
        <targetfile suffix=".${extension}" />
        <fileset dir="${js.dir}" includes="**/*.js" />
        <mapper type="identity" />
    </apply>
    <echo>OK!</echo>
</target>

Reading the files works correctly but the generated targetfile has the wrong path.

Given ${js.dir} is: /var/htdocs/js and I start my ant target in some other directory the script above produces the following shell command:

gzip -c /var/htdocs/js/a/b/1.js > ./a/b/1.js

which is not correct. The targetfile should get the same absolute path as the sourcefile. I want it to produce the following line:

gzip -c /var/htdocs/js/a/b/1.js > /var/htdocs/js/a/b/1.js

Can someone tell me how to do this?


Use something like =

<tar destfile="./your.tar.gz" compression="gzip">
 <tarfileset dir="${js.dir}">
  <include name="**/*.js"/>
 </tarfileset>
 </tar>
</target>

see Ant manual for tar task

Beside that there is also a wrapper task for the YUI Compressor Task, here's some detailled description how to use it = Compress JavaScript and CSS as Part of your Build Process


You could do it with two steps: first gzip the files, then rename them to remove the suffix.

<target name="compress-js">
  <apply executable="gzip" parallel="false">
    <srcfile/>
    <fileset dir="${js.dir}" includes="**/*.js"/>
  </apply>
  <move todir="${js.dir}">
    <fileset dir="${js.dir}">
       <include name="**/*.gz"/>
    </fileset>
    <globmapper from="*.gz" to="*"/>
  </move>
</target>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜