2011-04-12 76 views
2

喜當前我有這個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}\ssremove.exe" failonerror="${TrueCM_Failon_Exec}"> 
      <arg line="-h ${TrueCM_Host}"/> 
      <arg line='-f "${TrueSASE}/${Product_version}/${name}"'/> 
     </exec> 


    </target> 

一下這個腳本做的是,如圖所示,將執行ssremove.exe一些參數。

然而,這上面的腳本是當參數$ {} PRODUCT_VERSION例如含有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> 

所以我的問題是我應該如何添加if else語句包含確切的「擴展」行?或者我如何檢查「Extensions」單詞是否存在?

回答

1

只是,如果你勾勒出一個解決方案:它支持if/else語句(http://ant-contrib.sourceforge.net/tasks/tasks/index.html

從網站實例的antlib(http://ant-contrib.sourceforge.net

無法將自定義庫添加到您的Ant構建中。請注意,您需要一個相當新的Ant版本(> = 1.7,我認爲)。

首先,您需要將測試結果放入屬性中(使用conditioncontains;請參閱Ant Manual)。然後,您可以使用exec中的該屬性在屬性爲true時跳過該屬性。

<condition property="hasExtensions"> 
    <contains string="${Product_version}" substring="Extensions"> 
</condition> 

<exec ... unless="hasExtensions"> 
    ... 
</exec> 
+0

@aaron如何檢查Ant版本? – jeremychan 2011-04-12 08:06:31

+0

運行'ant -version' – 2011-04-12 08:08:16

+0

哦好的版本是1.6.5 – jeremychan 2011-04-12 08:15:56

6

有一隻螞蟻庫:

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

有一些解決方案與純ANT一起工作,但它們很難理解;如果您可以添加自定義庫,這會更加簡單直接。 – 2011-04-12 07:42:34