Ant: How to echo the name of targetfile within apply
I'm not really familiar with Ant and i wonder how to print the name of the current processed file to the commandline.
This is what i have so far... It's a part of a macro which minifys files with the yui-compressor.
<apply executable="java" parallel="false" verbose="true" dest="@{target}">
<fileset dir="@{src}">
<include name="**/*.@{filetype}"/>
</fileset>
<arg l开发者_StackOverflow中文版ine="-jar" />
<arg path="${yui.jar}" />
<arg value="--charset" />
<arg value="ANSI" />
<arg value="-o" />
<targetfile />
<mapper type="glob" from="*.@{filetype}" to="*.min.@{filetype}" />
</apply>
What i'm trying to get:
[echo] Start!
[apply] Processed: filename-1.min.js
[apply] Processed: filename-2.min.js
[apply] Processed: filename-3.min.js
[echo] Success!
I don't have a lot of experience with apply but you could try defining your fileset out of the apply element , getting your printed results and then referring to it into your apply element.
<fileset dir="@{src}" id="my.files">
<include name="**/*.@{filetype}"/>
</fileset>
<pathconvert pathsep="${line.separator}" property="processed.files" refid="my.files"/>
<echo>Start!</echo>
<echo message="${processed.files}"/>
<apply executable="java" parallel="false" verbose="true" dest="@{target}">
<fileset refid="my.files"/>
<arg line="-jar" />
<arg path="${yui.jar}" />
<arg value="--charset" />
<arg value="ANSI" />
<arg value="-o" />
<targetfile />
<mapper type="glob" from="*.@{filetype}" to="*.min.@{filetype}" />
</apply>
<echo>Success!</echo>
Of course this will only work if the apply executable doesn't print anything to clutter the output.
The best way I've found to do this is to add the debug or verbose flag to ant:
ant target-name -debug
or ant target-name -verbose
This will then print the executing command-line. For example:
[apply] Executing 'lib\NUnit\bin\nunit-console-x86.exe' with arguments:
[apply] '/noshadow'
[apply] '/domain:multiple'
[apply] '/labels'
[apply] '/framework:net-4.5'
[apply] '/nologo'
[apply] 'C:\blah\foo.Tests.dll
Unfortunately, this will verbosely log everything, and not just the specific apply
.
精彩评论