2013-11-20 24 views
6

Ant 1.9.1では、ほとんどのタスクでif and unless attributesを使用できます。Ant if:true。プロパティをtrueに設定してもタスクは実行されません

私はこれらのタスクを実行しようとしているところ、私が定義したマクロを持っています。しかし、これは私のマクロを実行しません

<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がtrueに設定されていても。その行を削除すると、私のtest.templateマクロが機能します。

ユーザ定義マクロにif:trueを使用して問題がありますか?この問題を回避する最良の方法は何ですか? ant manualから

+0

が、私はまだ問題が残った後、あなたがターゲット、プロパティおよびマクロバグレポートを満たされたすべてのいわゆる「test.templates」 –

+0

を持って気づきました2013年12月29日からの新しいantのリリース - 詳細は私の更新された回答EDIT(2)を参照してください。 – Rebse

+0

解決策が見つかりました - 私の更新された回答を参照EDIT(3)! – Rebse

答えて

7


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

あなたが入れたすべての作品をありがとう!私たちは嫌いな人の「」を使用していましたが、これは問題をよりうまく処理する方法だと思っていましたが、うまくいきませんでした。 –

+0

@Rebse:この答えを編集して、ソリューションをボトムではなく上部に置くといいでしょう(いくつかのソリューションではありません)。あなたの "私はそれを解決した!"質問にコメントしたら、私はあなたの答えをあきらめて終わりに達するでしょう。 –

関連する問題