如果macrodef属性设置为prod,我试图删除以log开头的所有行(例如下面的例子).我打算使用replaceregexp删除以log开头的所有行.但是,除了使用if任务之外,我不确定如何测试属性是否设置为特定值.我想不介绍任何非核心Ant任务来执行此操作,但我无法提出任何其他解决方案.除了使用if-task之外,我还有其他选择吗?
谢谢
<macrodef name="setBuildstamp">
<attribute name="platform" />
<sequential>
<if>
<equals arg1="platform" arg2="prod" />
<then>
<replaceregexp match="^log\(.*" value="" />
</then>
</if>
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)
您应该使用对参数的引用,如下所示@{platform}.
此外,您的replaceregexp任务缺少一些参数.
我认为在您的特定情况下,最好使用linecontainsregexp过滤器阅读器.这是修改后的代码(注意对linecontainsregexp的否定参数).
<macrodef name="setBuildstamp">
<attribute name="platform" />
<sequential>
<if>
<equals arg1="@{platform}" arg2="prod" />
<then>
<copy todir="dest-dir">
<fileset dir="src-dir"/>
<filterchain>
<linecontainsregexp
regexp="^log\(.*"
negate="true"
/>
</filterchain>
</copy>
</then>
</if>
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)