You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Greg Akins <ga...@insomnia-consulting.org> on 2005/09/14 14:11:17 UTC

"unless" doesn't appear to work for me?

 I have two targets.  One has a "if", the other has an "unless" that both
evaluate the same property.

I conditionally set the property based on the length of a file.

when I echo the property before the target, if it's set, I get "true"  If it's
not set, I get ${file.exists} (which I assume mean the property isn't set.

However, in either case, the target with unless="file.exists" does not run and
teh target with if="file.exists" does run.

Any ideas what I'm doing wrong? (Ant 1.6.5 on Java 1.4.2 on Linux)

-greg

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: "unless" doesn't appear to work for me?

Posted by Andrew Goktepe <an...@gmail.com>.
Please send the section of the script where you set the property.

 On 9/14/05, Greg Akins <ga...@insomnia-consulting.org> wrote: 
> 
> I have two targets. One has a "if", the other has an "unless" that both
> evaluate the same property.
> 
> I conditionally set the property based on the length of a file.
> 
> when I echo the property before the target, if it's set, I get "true" If 
> it's
> not set, I get ${file.exists} (which I assume mean the property isn't set.
> 
> However, in either case, the target with unless="file.exists" does not run 
> and
> teh target with if="file.exists" does run.
> 
> Any ideas what I'm doing wrong? (Ant 1.6.5 on Java 1.4.2 on Linux)
> 
> -greg
> 
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
>

Re: "unless" doesn't appear to work for me?

Posted by Andrew Goktepe <an...@gmail.com>.
Remember that all that matters is that the property is set to something. 
When you pass <param name="file.exists" value="${file.exists}"/>, you are 
setting that parameter for the target you are calling. This means that if 
file.exists has not been defined previously, you have just set it to the 
value "${file.exists}", and from that point forward the property has a 
value. This causes the if/unless behavior you are seeing. 
 You shouldn't have to specify the file.exists property as a parameter at 
all. Once you set it during the main target, it will be available to the 
checkout and update targets as well. (the default value of antcall's 
'inheritAll' attribute is true). 
 -Andrew

 On 9/15/05, Greg Akins <ga...@insomnia-consulting.org> wrote: 
> 
> Quoting Dominique Devienne <dd...@gmail.com>:
> 
> > 1) Thinking if="foo" means "execute the target is foo's property value
> > is true (or yes, or 1)". It sounds like you're are not making that
> > mistake.
> >
> 
> Here is the target I'm running (this is the only target in this buildfile, 
> and
> fileToCheck & destination are getting passed correctly).
> 
> I didn't necessarily think that if="foo" meant that it had to be true, 
> just that
> it had to be set.
> 
> However, if file.exists isn't set <echo message="${file.exists}/> prints
> ${file.exists} then checkout does not run, and update still does
> 
> 
> 
> <target name="main" >
> <condition property="file.exists">
> <length file="${fileToCheck}" when="greater" length="0"/>
> </condition>
> 
> <echo message="File Exists ${file.exists}" />
> 
> <antcall target="checkout">
> <param name="destination" value="${destination}"/>
> <param name="file.exists" value="${file.exists}" />
> </antcall>
> <antcall target="update">
> <param name="destination" value="${destination}"/>
> <param name="file.exists" value="${file.exists}" />
> </antcall>
> 
> </target>
> <target name="checkout" unless="file.exists" >
> <echo message="svn co
> https://svn.forge.amervideo.com/svn/systems/cim/atlas/${destination}
> ${destination}" />
> <exec executable="svn" >
> <arg line="co
> https://svn.forge.amervideo.com/svn/systems/cim/atlas/${destination}
> ${destination}" />
> </exec>
> </target>
> <target name="update" if="file.exists" >
> <echo message="svn update ${destination}" />
> <exec executable="svn" >
> <arg line="co
> https://svn.forge.amervideo.com/svn/systems/cim/atlas/${destination}
> ${destination}" />
> </exec>
> </target>
> 
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
>

Re: "unless" doesn't appear to work for me?

Posted by Greg Akins <ga...@insomnia-consulting.org>.
Quoting Matt Benson <gu...@yahoo.com>:


> 
> This is "the Ant way," ordinarily.
> 

I chose "the Ant way";').  Thanks very much for everyones help!

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: "unless" doesn't appear to work for me?

Posted by Matt Benson <gu...@yahoo.com>.
--- Greg Akins <ga...@insomnia-consulting.org> wrote:
[SNIP]
>   <target name="main" >
>          <condition property="file.exists">
>             <length file="${fileToCheck}"
> when="greater" length="0"/>
>           </condition>
> 
>           <echo message="File Exists ${file.exists}"
> />
>                     
>           <antcall target="checkout">
>             <param name="destination"
> value="${destination}"/>
>             <param name="file.exists"
> value="${file.exists}" />
>           </antcall>
>           <antcall target="update">
>             <param name="destination"
> value="${destination}"/>
>             <param name="file.exists"
> value="${file.exists}" />
>           </antcall>
> 
> 	</target>
>         <target name="checkout" unless="file.exists"

This is as far as we need to go.  Here you don't want
to run "checkout" unless the property "file.exists" is
set.  So you do an antcall, but you are setting
"file.exists" in the _antcall_ project context to the
value of ${file.exists} (set or not) in the
_top-level_ project context.  So in the subcontext,
the property will _always_ be set.  The lesson here is
not to use antcalls unless there is no other option. 
You would do better to restructure such as:

<target name="init">...</target>
<target name="checkout" unless="file.exists">
  ...
</target>
<target name="update" if="file.exists">
  ...
</target>
<target name="main" depends="init,checkout,update" />

This is "the Ant way," ordinarily.

HTH,
Matt


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: "unless" doesn't appear to work for me?

Posted by Greg Akins <ga...@insomnia-consulting.org>.
Quoting Dominique Devienne <dd...@gmail.com>:

> 1) Thinking if="foo" means "execute the target is foo's property value
> is true (or yes, or 1)". It sounds like you're are not making that
> mistake.
> 

Here is the target I'm running (this is the only target in this buildfile, and
fileToCheck & destination are getting passed correctly).  

I didn't necessarily think that if="foo" meant that it had to be true, just that
it had to be set.

However, if file.exists isn't set <echo message="${file.exists}/> prints
${file.exists} then checkout does not run, and update still does



  <target name="main" >
         <condition property="file.exists">
            <length file="${fileToCheck}" when="greater" length="0"/>
          </condition>

          <echo message="File Exists ${file.exists}" />
                    
          <antcall target="checkout">
            <param name="destination" value="${destination}"/>
            <param name="file.exists" value="${file.exists}" />
          </antcall>
          <antcall target="update">
            <param name="destination" value="${destination}"/>
            <param name="file.exists" value="${file.exists}" />
          </antcall>

	</target>
        <target name="checkout" unless="file.exists" >
          <echo message="svn co 
https://svn.forge.amervideo.com/svn/systems/cim/atlas/${destination}
${destination}" />
          <exec executable="svn"  >
            <arg line="co
https://svn.forge.amervideo.com/svn/systems/cim/atlas/${destination}
${destination}" />
          </exec>
        </target>
        <target name="update" if="file.exists" >
          <echo message="svn update ${destination}" />
          <exec executable="svn"  >
            <arg line="co
https://svn.forge.amervideo.com/svn/systems/cim/atlas/${destination}
${destination}" />
          </exec>
        </target>

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: "unless" doesn't appear to work for me?

Posted by Dominique Devienne <dd...@gmail.com>.
Posting a small snippet demonstrating the problem in Ant 'code' will
often get you an answer faster ;-)

The two main misunderstood points about target's if/unless are:

1) Thinking if="foo" means "execute the target is foo's property value
is true (or yes, or 1)". It sounds like you're are not making that
mistake.

2) The if/unless is evaluated *after* the depends target are executed.

In your case, it's possible you are not 'running' the code that sets
the property prior to testing for it. But of course that's just a
guess without actual code to look at ;-) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org