Xml 如果对ant脚本执行其他操作
嗨,我有一个ant脚本:Xml 如果对ant脚本执行其他操作,xml,ant,Xml,Ant,嗨,我有一个ant脚本: <target name="Cleanup Snapshots" description="Cleanup TrueCM snapshots"> <echo>Executing: ${TrueCM_App}\ssremove.exe -h${TrueCM_Host} "${TrueCM_New_SS}"</echo> <exec executable="${TrueCM_App}
<target name="Cleanup Snapshots" description="Cleanup TrueCM snapshots">
<echo>Executing: ${TrueCM_App}\ssremove.exe -h${TrueCM_Host} "${TrueCM_New_SS}"</echo>
<exec executable="${TrueCM_App}\ssremove.exe" failonerror="${TrueCM_Failon_Exec}">
<arg line="-h ${TrueCM_Host}"/>
<arg line='-f "${TrueSASE}/${Product_version}/${name}"'/>
</exec>
</target>
正在执行:${TrueCM\u App}\ssremove.exe-h${TrueCM\u Host}“${TrueCM\u New\u SS}”
此脚本的作用是,它将使用一些参数执行ssremove.exe,如图所示
但是,上述脚本仅在参数${Product_version}包含单词“Extensions”(例如6.00_Extensions)时有效
否则,如果它们不包含“扩展”,则脚本应如下所示:
<target name="Cleanup Snapshots" description="Cleanup TrueCM snapshots">
<echo>Executing: ${TrueCM_App}\ssremove.exe -h${TrueCM_Host} "${TrueCM_New_SS}"</echo>
<exec executable="${TrueCM_App}\ssremove.exe" failonerror="${TrueCM_Failon_Exec}">
<arg line="-h ${TrueCM_Host}"/>
<arg line='-f "${TrueSASE}/${name}"'/>
</exec>
</target>
正在执行:${TrueCM\u App}\ssremove.exe-h${TrueCM\u Host}“${TrueCM\u New\u SS}”
所以我的问题是,我应该如何添加完全包含行“Extensions”的if-else语句?或者如何检查是否存在“Extensions”单词?有一个ant库:antlib() 它支持if/else语句() 网站中的示例:
<if>
<equals arg1="${foo}" arg2="bar" />
<then>
<echo message="The value of property foo is bar" />
</then>
<else>
<echo message="The value of property foo is not bar" />
</else>
</if>
<if>
<equals arg1="${foo}" arg2="bar" />
<then>
<echo message="The value of property foo is 'bar'" />
</then>
<elseif>
<equals arg1="${foo}" arg2="foo" />
<then>
<echo message="The value of property foo is 'foo'" />
</then>
</elseif>
<else>
<echo message="The value of property foo is not 'foo' or 'bar'" />
</else>
</if>
如果无法将自定义库添加到Ant构建中,只需概述一个解决方案。请注意,您需要一个相当新的Ant版本(>=1.7,我想) 首先,需要将测试结果放入属性中(使用with;请参阅)。然后,当属性为
true
时,可以在exec
中使用该属性跳过它
<condition property="hasExtensions">
<contains string="${Product_version}" substring="Extensions">
</condition>
<exec ... unless="hasExtensions">
...
</exec>
...
有些解决方案可以与纯ANT一起工作,但很难理解;如果您可以添加自定义库,这将更加简单和直接。@aaron我如何检查Ant版本?我不确定何时添加了condition
。那可能太老了。将我的代码粘贴到build.xml
并运行它。蚂蚁如果不明白,就会抱怨。还有一个问题。。对于此除非=“hasExtensions”
这仅适用于${Product\u version}不包含“扩展”的情况?包含“扩展”的属性如何?创建第二个属性,该属性是hasExtensions
(例如,withoutExtensions
)的否定,并创建第二个exec
目标,该目标运行,除非=“withoutExtensions”
。其中只有一个将被执行。