2011-11-23 51 views
1

我想執行目標「MyTarget」,並得到一個錯誤:「不支持的元素回聲」。也許Macrodef不是做這項工作的方式。有沒有其他方式將任務傳遞給具有不同參數的另一個目標/宏定義?如何使用不同的參數幾次運行自定義任務?

<macrodef name="dotask"> 
    <attribute name="platform" description="" /> 
    <attribute name="config" description="" /> 
    <element name="task2" optional="true" /> 
    <sequential> 
     <task2 /> 
    </sequential> 
</macrodef> 

<macrodef name="buildsuite2"> 
    <element name="task" optional="true" /> 
    <sequential> 
     <dotask platform="win32" config="debug"> 
      <task /> 
     </dotask> 
     <dotask platform="win32" config="release"> 
      <task /> 
     </dotask> 
    </sequential> 
</macrodef> 

    <target name="MyTarget"> 
     <buildsuite2> 
      <task> 
       <echo>${platform} ${config}</echo> 
      </task> 
     </buildsuite2> 
    </target> 

回答

0
​​

是的,你可以用antcall任務的幫助下做到這一點。

樣本:

<target name="method_impl"> 
    <echo message="${firstParam}"/> 
    <echo message="${secondParam}"/> 
</target> 

<target name="test_calling_twice"> 
    <echo message="First time call"/> 
    <antcall target="method_impl"> 
     <param name="firstParam" value="fP1"/> 
     <param name="secondParam" value="sP1"/> 
    </antcall> 

    <echo message="Second time call"/> 
    <antcall target="method_impl"> 
     <param name="firstParam" value="fP2"/> 
     <param name="secondParam" value="sP2"/> 
    </antcall> 
</target> 

輸出將是:

First time call
fP1
sP1
Second time call
fP2
sP2

+0

我有一組PARAMS將重新使用了相當數量的自定義任務。做你的建議可能會解決這個問題,但我必須爲每個參數組寫一個antcall。如果我添加一個新的參數集,我必須爲每個自定義任務添加一個新的antcall。 –

+0

@Chau你可以使用[macrodef](http://ant.apache.org/manual/Tasks/macrodef.html)和antcall來分解公共代碼。 – sudocode

相關問題