You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dmitry Trunikov <td...@quasarlabs.com> on 2002/06/24 10:50:56 UTC

strange behaviour

    Hi ALL!
I revealed strange ant's behaviour (it is only my opinion :). Suppose
there is following build.xml:

<project default="all">
    <target name="all" depends="task1" if="not_defined_property">
        <echo message="In task - all."/>
    </target>
    <target name="task1">
        <echo message="In task - task1."/>
    </target>
</project>

I ascertained that task "task1" will be done in any way, just if
paroperty "not_defined_property" didn't defined (i.e. attribute "if" is
resolving  _after_  resolving "depends"). I think that this behaviour is
not right and depended task have to be done only when attribute "if" is
true. What do people think about this situation?

Thanks.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: strange behaviour

Posted by Dmitry Trunikov <td...@quasarlabs.com>.
> It is a rather common pattern to set properties in the targets of the
> depends list, something like
>
> <target name="check">
>   <availible property="library.available" ... />
> </target>
>
> <target name="do-it-with-lib" depends="check" if="library.available">
>   <task that requires library />
> </target>
>
> <target name="do-it-without-lib" depends="check" unless="library.available">
>   <task that does the same without library" />
> </target>
>
> <target name="do-it"
>         depends="do-it-with-library,do-it-without-library" />
>
> See also:
>
> <http://jakarta.apache.org/ant/faq.html#stop-dependency>
>

^^^^^^^^^^^^^
Thank you.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: strange behaviour

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 24 Jun 2002, Dmitry Trunikov <td...@quasarlabs.com> wrote:

> (i.e. attribute "if" is resolving _after_ resolving "depends")

This is correct, and it is so with a reason.

It is a rather common pattern to set properties in the targets of the
depends list, something like

<target name="check">
  <availible property="library.available" ... />
</target>

<target name="do-it-with-lib" depends="check" if="library.available">
  <task that requires library />
</target>

<target name="do-it-without-lib" depends="check" unless="library.available">
  <task that does the same without library" />
</target>

<target name="do-it"
        depends="do-it-with-library,do-it-without-library" />

See also:

<http://jakarta.apache.org/ant/faq.html#stop-dependency>

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: strange behaviour

Posted by Diane Holt <ho...@yahoo.com>.
--- Dmitry Trunikov <td...@quasarlabs.com> wrote:
> I revealed strange ant's behaviour (it is only my opinion :). Suppose
> there is following build.xml:
> 
> <project default="all">
>     <target name="all" depends="task1" if="not_defined_property">
>         <echo message="In task - all."/>
>     </target>
>     <target name="task1">
>         <echo message="In task - task1."/>
>     </target>
> </project>
> 
> I ascertained that task "task1" will be done in any way, just if
> paroperty "not_defined_property" didn't defined (i.e. attribute "if" is
> resolving  _after_  resolving "depends"). I think that this behaviour is
> not right and depended task have to be done only when attribute "if" is
> true. What do people think about this situation?

The if/unless are attributes of <target>, just like 'depends' is -- they
affect whether the <target> they're specified for will be run, not whether
the target(s) specified in the 'depends' attribute will be run. In this
way, the dependent target can (and more often than not does) determine
whether the property being checked for gets set or not. Maybe if you wrote
it:
  <target name="all" if="not_defined_property" depends="task1">
it'd be more clear?

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>