• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loops in Ant

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to perform a looping action of any type in Ant? If so, can someone provide an examples? Thanks
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I don't believe you can with the core ant tasks, I did have rather an extensive look at this. One thing you have to remember is that.


ant is not a scripting language.


You can of course write you own task and execute some another task multiple times within it...
L
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I am now looking at performing looping tasks using JavaScript. It was relatively easy to get JavaScript enabled and I now have some working JavaScript in my Ant script file. However, I am still trying to work out how Ant targets can call JavaScript and vice versa.
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jay,
What do you actually want to do?
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on some Ant scripts designed to be run inside the WebSphere Studio Application Developer (v4.0.3) IDE. Because there are a number of tasks, e.g. refresh, rebuild, etc., that are applicable to all projects, what I want to do is 1) declare all my project names in one place (so I do not have to create task-specific code for each of the refresh, rebuild, etc. tasks), and 2) use a looping mechanism to execute each of these tasks for each project.
I have managed to get JavaScript working inside my Ant scripts and it appears this may solve my problems by 1) declaring the project types and names within JavaScript arrays, and 2) using a for loop within JavaScript to execute Ant targets repeatedly.
However, I am still working on some issues related to the execution of JavaScript from Ant targets and vice versa. But I am fairly confident that I will be able to get the Ant scripts to do what I want now although I still have to work out the details.
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the club. I too have multiple similar subprojects that I'd like to be able to iterate Ant sub-builds over without having to change the master build.xml every time I add one. Even just running over a list from a property would suffice.
Not now, and, as far as I can tell, so time soon. I don't know if if's something the Ant people don't feel a need for or if it's just something they object to
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out Using JavaScript with Ant at:
http://www.sitepen.com/ant/javascript.html
As I indicated, I am currently looking at JavaScript as a solution to this problem. I'm still working out the details but the following Ant script, as an example, works once you add the bsf.jar (Bean Scripting Framework) and js.jar (JavaScript) files to your classpath.
Unfortunately, I am currently locked into Ant v1.3 because I am using IBM WebSphere Studio Application Developer v4.0.3. I think some of my problems would be solved if I could move to Ant v1.4 or v1.5.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a recent project I used a different method. In a master buildfile I included an Xslt/Style task which generated another buildfile on the fly and then executed it. This generated buildfile would include a series of tasks derived from a list in an XML config file I had in my source project. This may seem convoluted and obviously depends on having an XML metadata file to drive it in the first place. However, in my case, once set up, it worked really easily - the XML file was actually a J2EE deployment descriptor in my situation.
[ January 07, 2003: Message edited by: Paul Done ]
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, can you provide examples of your solution?
 
Paul Done
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately I don't have the orginal buildscripts at hand - this was done for a customer last year - however I have found the XSL which I called from the XLS/Style ant task in the master buildfile - not sure if this is any help?....

...which generated the buildfile....

Not sure if this helps because its very specific to the problem at the time. Basically I was creating a large WAR web component from lots of smaller ones developed by different developers in source control. Each sub project had its own buildfile, but there was not way to automate the build of the master web component from these smaller web components until I used this method (a single web component was required for production, rather than an EAR containing multiple WARs, because the servlet context needed to be shared). In fact, this example didn't use a deployment descriptor as input to the XSL, it used a custom XML config file that was also source controlled - but the principle is the same.
Paul
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Paul.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I tried to implement Paul's solution, unfortunately I get some problems when using the $ { } characters ...
Here is a code snippet of my stylesheet :

As Paul did I tried to use internal entities replacing the $ { } characters ... the result I get is quite dispointing :

I only get a single dollar sign. I saw Paul was nopt always using the entities in his stylesheet ... is there any rule I am not respecting ?
Thanks in advance
Nicolas
PS : I know my question is more about XSLT than ant but it directly concerns people who are trying to build Ant xml files using XSLT to solve some problems (cfr. my yesterday post)
 
Nicolas Brasseur
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually entities work well when unsed in elements ... and don't when used in attributes ...
will I be forced to use <xsl:element> <xsl:attribute> everywhere or is it a solution to use entities as attributes values ?
Thanks in advance ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic