Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conditional Logic Based on the Presence of a Passed Variable

 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an ANT neophyte I have no idea even where to look for this. I have this working (I got lucky and lots of help here) Ant file:

It is the 'incserial' target that I am interested in modifying. If ${build.number} is set from the command line I want to use it and not update the resources file. If is it not set then I want to run as is. How do I modify my ant to make that work? TIA.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the docs on the 'if' and 'unless' properties for <target>: http://ant.apache.org/manual/targets.html#targets
I think you want something like this:

 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this post. It contains working example.
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies and my apologies for not being sufficiently clear. I need to execute 'incserial' regardless. The issue is to not execute the copy and buildnumber parts if ${build.number} is set.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you split the incserial target into separate targets, some of which are always performed, others of which depend on the 'if' or 'unless' properties. For example:



There are other variations possible also, such as not having incserial2 at all - instead leave those three tasks in incserial.
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion but I came up with a slightly different solution. What I did not realize until recently was that the only thing I needed to do was not execute the <buildnumber /> task. I then figured out that <if><then><else> would work there (other places I tried it resulted in an unsupported nesting error).
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with using the <if> task is that it is not part of the Ant distribution, but is instead a part of Ant-contrib (which has not been updated since 2003!). I dislike relying on such old, no longer active, projects when there are ways of accomplishing what I want using standard Ant tasks (which is why I use the mechanism I identified earlier).
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was not aware that ant-contrib was effectively deprecated. I will probably switch to your suggestion. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic