• 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

scope of property in Ant 1.5

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Ant 1.5 and using the input task. I'm having some problems getting a property set. Here're the relevant snippets:

I have vssCheckLabel, because I want to allow developers to hard code a label in their own build.xml. At the same time, I want to prompt for it if it doesn't exist. The problem I'm having is that if it's not set, then checkout.has.vss.proj.label stays unset as expected and promptForVssLabel properly runs. After entering the input, the echo with message of "Label2:${checkout.vss.proj.label}" displays, with my new input in checkout.vss.proj.label, but when control returns to vssGetLabel, ${checkout.vss.proj.label} is now unset and the echo with "Label2:${checkout.vss.proj.label}" prints out literally "Label2:${checkout.vss.proj.label}", without property value replacement.
Any ideas?
Thanks,
Jacob
[ July 16, 2002: Message edited by: Jacob Schuetze ]
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It appears that the adding a property through input -> add property does not add the property to the project, but just to the target. It seems to be a context issue, but it is strange, as setting properties either with <property> or <condition> applies to the project.
Perhaps an ant guru could shed more light, but I didn't see anything in the docs regarding this.
 
Jacob Schuetze
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for looking into it. From what I've found on the web about similar problems, there's some speculation that it may be tied to version of Xerces in the classpath.
I was seeing this problem primarily on eclipse, but then also on my development workstation at work. I tried similar code here at home wit Ant 1.5 and then in eclipse and had success, but only when I do the input in the depends. The scope of the property seems to only be the target. If I set the property via antcall, as in my example above, it doesn't get set. If I set it in a depends target, it gets included in the calling target. Here's a thought I haven't tried yet...

even if this works, it feels hacky because our "switch" is a property set elsewhere, then we try to run all targets (which would do the same thing, ultimately) and rely on the 'if' and 'unless' in the targets to ensure only one runs.
 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your other option here is to just fail the build if the property hasn't been set. Then you develpers will be forced to go in and set the property. It's not a great solution if you really want to change that parameter on the fly, but it would work.
I'm not sure what this parameter will be used for, so I don't know what other solutions to offer.
 
Jacob Schuetze
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Reeves:
Your other option here is to just fail the build if the property hasn't been set. Then you develpers will be forced to go in and set the property. It's not a great solution if you really want to change that parameter on the fly, but it would work.
I'm not sure what this parameter will be used for, so I don't know what other solutions to offer.


The original goal was to be able to have a build.xml file that would do a checkout from VisualSourceSafe (new optional tags in 1.5) and then build the code. The idea was that a developer needing to work on a certain tag branch would maybe want to set a property. If, for example, a developer is setting up a new environment just from the build.xml, they would want to enter a specific tag once via <input .../> (or just get latest, which I handle separately. At any rate, I continued along the line of my last post with the depends and multiple matching targets with if= and unless=, and it now works. I have also created a custom input using Swing so that the input tag works in my IDE also (eclipse). Now if the property is set in the build.xml, I run the checkout target and it gets what I specified. If it's NOT set, I run the checkout target and I get a Swing prompt for a label to get, and it properly sets the target property and checks out the labeled code. Pretty cool, now that it works
 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that is nice.
When you run it, just think of me, down here at the command line...
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the ant and antcall tasks don't only execute a single target but a whole ant run. That is, if the executed target would depend on others, they would be executed even if they already were executed in the calling ant run.
To get back to your specific problem: properties simply can't be returned to the calling run.
What you can do instead of using the input task is let the developers specify properties via the command line:
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ija is right, <antcall> targets run in a kind of subenvironment where things dont propagate back. There is an ugly hack workaround.
1. think of a name of a temporary file, maybe using <tempfile> in ant1.5
2. pass that file name to the antcalled target
3. have that target save the property to that file
4. have the parent read it back in, then delete the file.
reply
    Bookmark Topic Watch Topic
  • New Topic