Есть ли способ проверить условие Ant Target перед выполнением целевых зависимостей - PullRequest
1 голос
/ 21 февраля 2012

Я пытаюсь избежать 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".
Есть ли лучшее решение, когда цель и ее зависимости не будут выполняться в зависимости от условия.

Я всегда могу пойти на антракт с условиями.Но я ищу другую альтернативу.
Я не могу проверить условия "skip.c" в целях c1, c2, c3, так как у меня есть больше условий для проверки в этих целях.

Ответы [ 2 ]

2 голосов
/ 21 февраля 2012

Все зависимости цели обрабатываются перед проверкой "если / если". В 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>
0 голосов
/ 18 марта 2015

Чтобы избежать использования antcall, вам нужно поставить условие в каждую из подзадач.Глядя на имя «skip.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="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>
...