Echo file name in ant process

I am currently using a YUI compressor during the ant build process to minimize CSS and JavaScript files. While it minimizes each file, I would like it to give the name of the file that the executable is currently trying to apply, so that if an error occurs, I know which file is causing the error. For instance:

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

Each solution I saw seems to simply reflect the entire file name in the fileset after the application instruction has been applied to all files.

Currently, my ant build is as follows:

 <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> 

Maybe there is another way to do this, instead of using a set of files, use an instruction that cycles through each file one at a time and performs an action on the file?

+4
source share
1 answer

To do this, you will need to enable ant-contrib . Then you can do this:

 <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> 
+1
source

Source: https://habr.com/ru/post/1445977/


All Articles