dcsimg
Problem while executing an ANT target repeatedly through Java
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aashay_Saralkar
Posted On:   Thursday, November 15, 2007 06:42 AM

Hi All, I am a newbie at executing ANT through Java and ran into a roadblock while tryin to do the following : i have a build.xml containing a target with mkdir task I want to execute this target repeatedly for different values to the property 'property1'.The source code looks like project = new Project(); File buildFile = new File(repeaterConfig.getBuildXMLPath()); project.setUserProperty("ant.file", buildFile.getAbsolutePath()); project.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); project.addReference("ant.projectHelper", helper); helper.parse(project, build   More>>


Hi All,
I am a newbie at executing ANT through Java and ran into a roadblock while tryin to do the following :



i have a build.xml containing a target with mkdir task

			






I want to execute this target repeatedly for different values to the property 'property1'.The source code looks like

			
project = new Project();
File buildFile = new File(repeaterConfig.getBuildXMLPath());
project.setUserProperty("ant.file", buildFile.getAbsolutePath());
project.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper);
helper.parse(project, buildFile);
for(int i=0;i <5;i++){
project.setProperty("property1","test"+i);
project.executeTarget("createDirectory");
}


The target executes successfully for the first time creating folder 'test0' but fails in rest of the iterations.
Using the verbose flag i found out that the value for property 'property1' was getting replaced properly in every iteration, but for some reason the target keeps on using the initially set value for 'property1' which is 'test0'.

Is there some basic mistake i am making here ?    <<Less

Re: Problem while executing an ANT target repeatedly through Java

Posted By:   Robert_Lybarger  
Posted On:   Thursday, November 15, 2007 08:44 AM

Ant goes through some great efforts to make sure that a property value, once set, can never be changed or removed. It's usually the first mistake someone makes in any Ant script file longer than about ten lines, and is my biggest pet peave about the tool. I'm not overly surprised that, even using the classes programmatically, your task is using the same initial value. (And no: I don't know how you'd work around this, other than possibly loading up a completely new 'Project' object in each loop, forcing the guts of the tool to totally start over each time. [shrug])
About | Sitemap | Contact