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

Creating for loops in ANT

 
Cindy Martin
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

can we write a build file with a for loop that runs n times ?

For eg., i want to run a for loop for n no of time depends on the value of n. But i dont want to write in java and call in build file...i am just trying with ANT tasks itself todo this... if anyone gives me a hint, or know abt how to write, kindly help me...

Cindy
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ant doesn't directly support this. It very deliberately doesn't have scripting-like constructs becasue it is not a scripting language. However, you can get the ant-contrib extensions which include this sort of stuff.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could write your own AntTask that reads a property from the build file, and iterates accordingly. It's not that hard.
 
Cindy Martin
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul and Ulf !! you have given me a hint...

Using ANT Contrib tasks , i just wrote the simple loop


This code results in, printing the values one by one. But the size is fized and i need to give all the inputs in the list attribute...Is there any way that i can specify the list = No of values (n) and iterate it by the loop ( i= i+1). I tried several possibilities, but i cud not get it. Can anyone help me ?

Cindy
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:



then run ant as:

ant -Dmy.list=1,2,3,4,5

Or you can set the my.list property in a properties file or in another location within the script.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic