繁体   English   中英

在ant过程中回显文件名

[英]Echo file name during ant process

我目前在ant构建过程中使用YUI压缩器来缩小CSS和JavaScript文件。 虽然它是在缩小每个文件,但我希望它输出当前尝试应用可执行文件的文件的名称,以便在发生错误时,我知道哪个文件导致了错误。 例如:

[echo] Minifying JS files...
[echo] Trying to minify file1.js...
[echo] Trying to minify file2.js....

我看到的每个解决方案似乎只是在将apply指令应用于所有文件之后回显文件集中的所有文件名。

我的ant build目前看起来像这样:

<target name="minifyJS" depends="overwriteCSSWithMinified">
    <echo message="minifying js files and saving them to fileName-min.js" />
    <apply executable="java" parallel="false" dest="${toWebHome}">
        <fileset dir="${toWebHome}">
            <exclude name="**/*.min.js" />
            <include name="**/*.js"/>
         </fileset>
         <arg line="-jar"/>
         <arg path="yuicompressor-2.4.7.jar" />
         <arg line="-v"/>
         <srcfile/>
         <arg line="-o"/>
         <mapper type="glob" from="*.js" to="*-min.js"/>
         <targetfile/>
     </apply>
 </target>

也许还有另一种方法,这样做而不是使用文件集,使用一次循环遍历每个文件的指令并对文件执行应用程序?

为此,您需要包含ant-contrib 然后你可以这样做:

<target name="minifyJS" depends="overwriteCSSWithMinified">
    <echo message="minifying js files and saving them to fileName-min.js" />
    <foreach target="yui" param="jsFile">
        <fileset dir="${toWebHome}">
            <exclude name="**/*.min.js" />  
                     <!-- should this be -min.js instead of .min.js ? -->
            <include name="**/*.js"/>
        </fileset>
    </foreach>
</target>

<target name="yui">
    <echo message="${jsFile}"/>
    <exec executable="java">
        <arg value="-jar"/>
        <arg value="yuicompressor-2.4.7.jar"/>
        <arg value="-v"/>
        <arg value="-o"/>
        <arg value="'.js$:-min.js'"/>
        <arg value="${jsFile}" />
    </exec>
</target>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM