:
Antは、特別な名前空間を使用して、すべての タスクとネストされた要素の上にある場合とない限り、属性を追加することが可能である1.9.1ので。
今までmacrodefの新場合としない限り、属性を使用しますが、次のスニペットが動作しませんでした:使用している場合
<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="foo" value="true"/>
<macrodef name="foobar">
<attribute name="bla"/>
<attribute name="whentrue"/>
<sequential>
<echo if:true="${@{whentrue}}">@{bla}</echo>
</sequential>
</macrodef>
<echo>${ant.version}</echo>
<foobar whentrue="foo" bla="yada,yada"/>
</project>
お知らせ=>プロパティ構文<echo if:true="${@{whentrue}}">
、それは動作しません。 @ {whentrue}のみ。
出力:
[echo] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
[echo] yada,yada
私の他の試み:
<macrodef name="foobar" if:true="foo">
<attribute name="bla"/>
<sequential>
<echo>@{bla}</echo>
</sequential>
</macrodef>
<echo>${ant.version}</echo>
<foobar bla="yada,yada"/>
は動作しませんでした:
... Problem: failed to create task or type foobar
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
はまた<foobar bla="yada,yada" if:true="foo"/>
のようなものが動作すると仮定:
<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="foo" value="true"/>
<macrodef name="foobar">
<attribute name="bla"/>
<sequential>
<echo>@{bla}</echo>
</sequential>
</macrodef>
<echo>${ant.version}</echo>
<foobar bla="yada,yada" if:true="foo"/>
</project>
出力、エラーなししかしmacrodef実行されません。この機能は、新しいスパンキングされるいくつかの矛盾が、その領域に残っているよう
[echo] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
BUILD SUCCESSFUL
は思えます。
おそらく、バグを報告する必要があります。
- EDIT(1) -
ant bugデータベースにcomment from 2007 by Peter Reilly(彼はif/unless機能を実装しています)が見つかりました。
- EDIT(2) -
2013年12月29日から新Antのリリース1.9.3(see releasenotes here)があれば、新規に関連するバグを修正しますが:としない限り:私たちの問題は依然として残っている属性(https://issues.apache.org/bugzilla/show_bug.cgi?id=55885) 。したがって、私はバグレポートを開きました。バグデータベースbugid 55971を参照してください。
- EDIT(3)-
最後に、この溶液が見出される。 Bugid 55885のバグ修正のほか、Antリリース1.93はまた、if:true="propertyname"
の代わりにif:true="${propertyname}"
が使用されなければならないことを示す新しいif:およびunless:attributes =>Bugid 55359のドキュメントのバグ修正を提供します。
は、だからあなたのマクロは、そのようにAntを1.9.3にアップグレードした後に動作するはずです:
<property name="test.templates" value="true"/>
....
<target name="test.templates"
description="Test the autoconfiguration templates and answers">
<test.templates
if:true="${test.templates}"
template.root.dir="${main.dir}"
answers.dir="${main.config.dir}"/>
</target>
が、私はまだ問題が残った後、あなたがターゲット、プロパティおよびマクロバグレポートを満たされたすべてのいわゆる「test.templates」 –
を持って気づきました2013年12月29日からの新しいantのリリース - 詳細は私の更新された回答EDIT(2)を参照してください。 – Rebse
解決策が見つかりました - 私の更新された回答を参照EDIT(3)! – Rebse