1

プログラムでantcallを回避しようとしているので、antcallターゲットをターゲットの依存関係に移動しようとしています。今私は状況があります:

<target name="test" depends="a,b,c" />

<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="c1,c2,c3" />

今まで、すべてがうまく機能しています。しかし、ターゲット'c'とその依存関係を実行からスキップしたいだけの場合は、

<target name="c" depends="c1,c2,c3" if="skip.c" />  (considering the property "skip.c" is already set)

これで、ターゲット'c'の依存関係が実行され、条件"skip.c"がチェックされます。
ターゲットとその依存関係の両方が条件に基づいて実行されない、より良い解決策はありますか?

私はいつでもif条件でantcallに行くことができます。しかし、他の選択肢を探しています。
c1、c2、c3ターゲットで「skip.c」条件をチェックすることができません。これらのターゲットでチェックする条件がまだあるためです。

4

2 に答える 2

2

ターゲットのすべての依存関係は、「if/unless」テストが確認される前に処理されます。これを回避するための組み込みメソッドはAntにはありません。

代わりに、依存関係をアクションから分離することをお勧めします。次のことを試してください。

<target name="test" depends="a,b,c" />

<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c">
    <condition property="skip.c.and.dependents">
        <or>
            <isset property="prop1"/>
            <isset property="prop2"/>
        </or>
    </condition>

    <antcall target="do-c-conditionally"/>
</target>

<target name="do-c-conditionally" unless="skip.c.and.dependents">
    <antcall target="do-c"/>
</target>

<target name="do-c" depends="c1,c2,c3">
    <!-- former contents of target c -->
</target>
于 2012-02-21T17:14:58.460 に答える
0

antcallの使用を回避するには、各サブタスクに条件を設定する必要があります。「skip.c」という名前を見ると、次のような「unless」状態である可能性があります。

<target name="test" depends="a,b,c" />

<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="c1,c2,c3" />

<target name="c1" unless="skip.c">
        <!-- contents of target c1 -->
</target>
<target name="c2" unless="skip.c">
        <!-- contents of target c2 -->
</target>
<target name="c3" unless="skip.c">
        <!-- contents of target c3 -->
</target>

タスク「c」を実行するときに条件の処理を実行する必要がある場合は、次のようにターゲット「check_run_c」で実行できます。

<target name="test" depends="a,b,c" />

<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="check_run_c,c1,c2,c3" />
<target name="check_run_c">
    <condition property="run.c">
        <!-- set this property "run.c" if the  "c*" targets should run... -->
        <or>
            <isset property="prop1"/>
            <isset property="prop2"/>
        </or>
    </condition>
</target>
<target name="c1" if="run.c">
        <!-- contents of target c1 -->
</target>
<target name="c2" if="run.c">
        <!-- contents of target c2 -->
</target>
<target name="c3" if="run.c">
        <!-- contents of target c3 -->
</target>

タスク「c」に条件付きでのみ実行したい指示もある場合:

<target name="test" depends="a,b,c" />

<target name="a" depends="a1,a2,a3" />
<target name="b" depends="b1,b2,b3" />
<target name="c" depends="check_run_c,c1,c2,c3" if="run.c" >
        <!-- contents of target c -->
</target>
<target name="check_run_c">
    <condition property="run.c">
        <!-- set this property "run.c" if the  "c*" targets should run... -->
        <or>
            <isset property="prop1"/>
            <isset property="prop2"/>
        </or>
    </condition>
</target>
<target name="c1" if="run.c">
        <!-- contents of target c1 -->
</target>
<target name="c2" if="run.c">
        <!-- contents of target c2 -->
</target>
<target name="c3" if="run.c">
        <!-- contents of target c3 -->
</target>
于 2015-03-18T16:23:13.943 に答える