2009-10-08 78 views
2

有沒有辦法將值放入包含macrodef參數字符串的屬性中?包含Macrodef參數的Ant屬性

例如,在下面的macrodef我想給$ {} build.dir /空間/ @ {} platform}/@{resolution}/${widget.name添加一個屬性,因爲它是在幾個宏定義中使用。

<macrodef name="setBuildstamp"> 
    <attribute name="platform" /> 
    <attribute name="resolution" /> 
    <sequential> 
     <replace file="${build.dir}/widget/@{platform}/@{resolution}/${widget.name}/Contents/Javascript/views/sidebar/DevSettingsView.js" token="%%%BUILD_TIMESTAMP%%%" value="${build.timestamp}" /> 
    </sequential> 
</macrodef> 

將成爲

<property name="widget.base" value"${build.dir}/widget/@{platform}/@{resolution}/${widget.name}" /> 

<macrodef name="setBuildstamp"> 
    <attribute name="platform" /> 
    <attribute name="resolution" /> 
    <sequential> 
     <replace file="${widget.base}/Contents/Javascript/views/sidebar/DevSettingsView.js" token="%%%BUILD_TIMESTAMP%%%" value="${build.timestamp}" /> 
    </sequential> 
</macrodef> 

回答

1

根據您的意見,這或許會有所幫助。

您可以定義設置widget.base屬性的目標,然後調用其名稱作爲參數傳遞的另一個目標。 widget.base的值將在每次對包裝器的調用中重新計算。 下面的例子設置了兩個嵌套目標,第一個調用macrodef,就像你的問題一樣。第二個直接調用目標中的任務。主要目標每次調用幾次來測試替代。

<property name="platform" value="foo" /> 
<property name="resolution" value="bar" /> 
<property name="widget.name" value="bibble" /> 
<property name="build.dir" value="boo" /> 
<property name="build.timestamp" value ="1234"/> 

<!--sets the property on each call then calls the target with the passed name --> 
<target name="wrapper"> 
    <property name="widget.base" value="${build.dir}/widget/${platform}/${resolution}/${widget.name}" /> 

    <antcall target="${nestedTarget}"/> 
</target> 

<target name="nestedTarget1"> 
    <setBuildstamp widgetBase="${widget.base}" buildTimestamp="${build.timestamp}"/> 
</target> 

<target name="nestedTarget2"> 
    <echo>"different/${widget.base}/Contents/Javascript/views/sidebar/DevSettingsView.js" 
     token="%%%BUILD_TIMESTAMP%%%" value="${build.timestamp}"</echo> 
</target> 

<macrodef name="setBuildstamp"> 
    <attribute name="widgetBase" /> 
    <attribute name="buildTimestamp" /> 
    <sequential> 
     <echo>"@{widgetBase}/Contents/Javascript/views/sidebar/DevSettingsView.js" 
     token="%%%BUILD_TIMESTAMP%%%" value="@{buildTimestamp}"</echo> 
    </sequential> 
</macrodef> 

<target name="test"> 
    <antcall target="wrapper"> 
    <param name="platform" value="${platform}"/> 
    <param name="resolution" value="${resolution}"/> 
    <param name="nestedTarget" value="nestedTarget1"/> 
    </antcall> 
    <antcall target="wrapper"> 
    <param name="platform" value="starsky"/> 
    <param name="resolution" value="hutch"/> 
    <param name="nestedTarget" value="nestedTarget1"/> 
    </antcall> 
    <antcall target="wrapper"> 
    <param name="platform" value="fizz"/> 
    <param name="resolution" value="buzz"/> 
    <param name="nestedTarget" value="nestedTarget2"/> 
    </antcall> 
    <antcall target="wrapper"> 
    <param name="platform" value="jim"/> 
    <param name="resolution" value="joe"/> 
    <param name="nestedTarget" value="nestedTarget2"/> 
    </antcall> 
</target> 

運行此腳本的輸出是:

test: 

wrapper: 

nestedTarget1: 
    [echo] "boo/widget/foo/bar/bibble/Contents/Javascript/views/sidebar/DevSettingsView.js" 
    [echo]    token="%%%BUILD_TIMESTAMP%%%" value="1234" 

wrapper: 

nestedTarget1: 
    [echo] "boo/widget/starsky/hutch/bibble/Contents/Javascript/views/sidebar/DevSettingsView.js" 
    [echo]    token="%%%BUILD_TIMESTAMP%%%" value="1234" 

wrapper: 

nestedTarget2: 
    [echo] "different/boo/widget/fizz/buzz/bibble/Contents/Javascript/views/sidebar/DevSettingsView.js" 
    [echo]    token="%%%BUILD_TIMESTAMP%%%" value="1234" 

wrapper: 

nestedTarget2: 
    [echo] "different/boo/widget/jim/joe/bibble/Contents/Javascript/views/sidebar/DevSettingsView.js" 
    [echo]    token="%%%BUILD_TIMESTAMP%%%" value="1234" 

BUILD SUCCESSFUL 
+0

我特別使用了宏定義,因爲我需要根據選擇的目標來改變路徑的能力。如果我設置了widget.base(是不可變的),一旦它被設置,我將無法改變它。我希望儘管有一種方法可以在宏定義中提取路徑,就像我將一個路徑放在一個屬性中一樣,但是當@ {}屬性選擇器出現時,這看起來不起作用。 – Steve 2009-10-09 11:34:35

3

在螞蟻1.8,你有local任務,這是本設計的。

+0

謝謝。很高興知道。 – Steve 2010-09-13 19:23:06