• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

alternative to "available file" option

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to provide some info before I go into my question. I am using a single ANT build.xml for several projects, the goal is to keep the build.xml generic and use properties files for each of the projects. Due to this I've built it to accomodate all projects.
Using a web module (WSAD terminology) for an example I will have one OR more replace strings for files within that module for the different projects. The information regarding the replacement strings resides in each Projects property file, and looks something like this:
** PROPERTIES SET IN THE PROJECTS PROPERTY FILE ******
WEB.Modify1.file=C:\\ccView\\${VOB.project.name}\\${VOB.project.name}_vob\\code\\${WEB1.project.name}\\${WEB.content}\\WEB-INF\\ibm-web-bnd.xmi
WEB.Token1.string=virtualHostName="default_host"
WEB.Value1.string=virtualHostName="VHMyTime"
** END **
I currently using the following code to look for the presence of a file (stringreplacement1.txt) to determine if I should call the target "replaceString1". This is a real pain, because I have to remember to create the stringreplacement1.txt file, and it is an even bigger pain when there are lots of replacements (i.e. have to create stringreplacement2.txt, etc..).
** CODE USED TO CHECK FOR EXISTENCE OF STRINGREPLACEMENT1.TXT **
<available file="${global.vobAppBuildCode.dir}/${module.project.name}/stringreplacement1.txt" type="file" property="stringreplacement1.exists"/>
<antcall target="replaceString1">
<param name="Modify1.file" value="${WEB.Modify1.file}"/>
<param name="Replace1.string" value="${WEB.Token1.string}"/>
<param name="Replacement1.string" value="${WEB.Value1.string}"/>
</antcall>
** END **
Can anyone suggest a better way to do this? Is there a way to check if there is a value associated with "WEB.Modify1.file", and if so then do the antcall?
Thanks,
Lisa
 
lisa phillips
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not getting any hits here so I'll try and explain this better by taking another approach.
I have multiple projects which may have a file(s) that need string replacements. For example, ApplicationCAT has the file abc.xml that has two lines that require string replacements. ApplicationDOG has file abc.xml that only needs one string replacement.
I'm using one build.xml for all my projects (applications). In the properties file of each of the projects I specify the file(s)/existingString/replacementString that needs to take place during the build.
** EXAMPLE from the projects properties file **
WEB.Modify1.file=C:\\ccView\\${VOB.project.name}\\${VOB.project.name}_vob\\code\\${WEB1.project.name}\\${WEB.content}\\WEB-INF\\abc.xml
WEB.Token1.string=virtualHostName="default_host"
WEB.Value1.string=virtualHostName="VHMyTime"
** END EXAMPLE **
There will be as many of these entries in the properties files as there are string replacements. If there was a second string replacement I would have something like the above with the parameters: WEB.Modify2.file, WEB.Token2.string,WEB.Value2.string.
So at this point I have all the file and string replacement info in all of my projects properties files.
In my build.xml I must accomodate for the project that has the most string replacements. Here is an example of what is in the build.xml:
** CODE USED TO CHECK FOR EXISTENCE OF STRINGREPLACEMENT1.TXT **
<antcall target="replaceString1">
<param name="Modify1.file" value="${WEB.Modify1.file}"/>
<param name="Replace1.string" value="${WEB.Token1.string}"/>
<param name="Replacement1.string" value="${WEB.Value1.string}"/>
</antcall>
<antcall target="replaceString1">
<param name="Modify2.file" value="${WEB.Modify2.file}"/>
<param name="Replace2.string" value="${WEB.Token2.string}"/>
<param name="Replacement2.string" value="${WEB.Value2.string}"/>
</antcall>
** END **
So the above code will execute the string replacement command in targets "replaceString1" and "replaceString2". The problem is that project ApplicationDOG (going back to the example) only has ONE string replacement that needs to take place, so the build fails with it tries to do the second string replacement because there are no values.
The way I worked around this was to put a "dummy" file on the file system (stringreplacement"x".txt). For each project I have an area that I place these. ApplicationDOG would just have "stringreplacement1", while ApplicationCAT would have "stringreplacement1.txt" and "stringreplacment2.txt".
I then use an "available file" statement before the <antcall target="replaceStringx"> statement, which will check for the existence of the stringreplacementx.txt file. If it exist it executes the ant call, if not it skips it.
** EXAMPLE **
<available file="${global.vobAppBuildCode.dir}/${module.project.name}/stringreplacement1.txt" type="file" property="stringreplacement1.exists"/>
<antcall target="replaceString1">
<param name="Modify1.file" value="${WEB.Modify1.file}"/>
<param name="Replace1.string" value="${WEB.Token1.string}"/>
<param name="Replacement1.string" value="${WEB.Value1.string}"/>
</antcall>
** END OF EXAMPLE **
THE GOAL - FINALLY!!
I don't want to have to put the stringreplacmentx.txt file(s) on the file system as a means to check if it should execute the ant call. I would prefer it if there was a way to check if there was a value for WEB.modify1.file, WEB.modify2.file, etc. If a value has been set in the projects properties file there should be a value in there.
Is this possible? I initially though I could use something like the "available" task to check for a "JVM system resource" (I'm not sure if this would qualifies as as a JVM System Resource though).
I don't know if this makes any more sense than it did before, I hope so. If you want to take a look at the projects properties file and the build.xml I will gladly send it to you.
Thanks for your help,
Lisa
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lisa,
OK, I'm not going to lie to you. I read through your very long question fairly quickly. It sounds like what you need is a loop, which ant really doesn't provide. There are some ant add-ons that purport to make loops possible, but I've never used them, and they look kludgey to me.
Some things that you might look at are:
- "if" attribute of a target.
<target "mytarget" if="property"> means the target won't be executed if the property isn't set.
- "conditional" task. I'm not sure this is in basic ant, but it's at least one of the standard optional tasks. It might be a little more flexible than "available" for what you're trying to do.
- "param" subtag of antcall task. It still doesn't let you do loops, but it does let you pass different values into the same target. That could save you some coding.
Good luck with it! Hope to see you back in this forum soon, well, you know ... preferably with some shorter questions, but anytime you run into trouble.
[ February 20, 2003: Message edited by: Greg Charles ]
 
lisa phillips
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg,
Sorry for the LONG message, but I was just trying to provide the necessary information!
The good news is that one of the items you mentioned (<target "mytarget" if="property"> means the target won't be executed if the property isn't set) was the ticket and lets me accomplish the goal of getting rid of the file on the file system.
I was actually already using the "if", but was making it too difficult by having it check for the existence of a file vs a property that was set. Live and learn. Ant/programming is fairly new to me, so you may see me visiting the saloon once in awhile - if not for help maybe a drink!
Thanks again for your help,
Lisa
 
This one time, at bandcamp, I had relations with a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic