开发者

Disabling filtering including nested <filterset> elements in ANT 'copy' task

Requiremen开发者_Python百科t:

We have one ANT build file which is used to for both DEV and RELEASE mode. We would like to enable filtering in DEV mode and disable it in RELEASE mode. As we are using the same build file for both modes(DEV and RELEASE) hence we are looking for ways to switch on/off filtering based on build mode.

My analysis so far:

As per documentation, the filtering can be disabled but the nested elements will always be used, even if this attribute is false. http://ant.apache.org/manual/Tasks/copy.html

Please note that we can't move away from elements in our case.

Question:

I would like to know if there is a workaround to disable filtering including nested elements in 'copy' task .


You can achieve the effect of having no filterset by having one that does nothing. Filtersets support id/refids, so you can define two - one dev and one release - then switch between them using a condition based on the mode. Something like this:

<property name="mode" value="release" /><!--Or value="dev"-->

<filterset id="dev.filter.id">
    <filter token="MODE" value="dev" />
</filterset>

<filterset id="release.filter.id" /><!--Null filterset-->

<!--Choose filterset id depending on mode-->   
<condition property="copy.filter.id"
           value="dev.filter.id"
           else="release.filter.id">
    <equals arg1="${mode}" arg2="dev"/>
</condition>

<copy file="input.txt" tofile="output.txt">
    <filterset refid="${copy.filter.id}" />
</copy>

If you have a number of behaviours that differ between dev and release modes, it might make sense to put those in separate build configuration files and load just the one for the current mode.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜