Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Conditional Logic Based on the Presence of a Passed Variable

 
Ranch Hand
Posts: 377
  • 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.
 
author
Posts: 5856
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:

 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this post. It contains working example.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • 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
Posts: 5856
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: 377
  • 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
Posts: 5856
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: 377
  • 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.
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic