Setting a call to pull a 4-digit number from the properties file
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   AJ_Spruit
Posted On:   Thursday, September 7, 2006 11:26 AM

I am relativly new to ANT and am trying to change my build to do one task if the 4 digit number is in the properties file and to to give an on screen error if the number is not detected. I have set a field in my properties file to be called 'deploy.clientno=XXXX' which need to be a 4 digit number to allow it to carry on the build other wise it needs to give an error msg instructing to enter a number.


I really need help in writing the script to do this.


Any ideas


Thanks
AJ

Re: Setting a call to pull a 4-digit number from the properties file

Posted By:   Robert_Lybarger  
Posted On:   Thursday, September 7, 2006 10:56 PM

If you take the 'custom ant task' suggestion -- and why not -- I'd actually recommend a custom "condition" just based on the wording of your question. That's also covered in the ant manual to a degree, but I'll try to save some effort, since the manual's tutorial pages just are not well written. Of course, this is going to be *highly* compressed and might not be much better. ;-)


Your java class for the custom condition will implement the org.apache.tools.ant.condition.Condition class and will implement the eval() method:


public boolean eval() {
Project p = this.getProject();
String numStr = p.getProperty("deploy.clientno");
Integer I=null;
try {
I = new Integer(numStr);
} catch (NumberFormatExcepton nfe) {
return false;
}
int i = I.intValue();
return (i>=1000 && i<=9999);
}

At that point, register your custom condition using the "typedef" task. (see ant manual.) Then load the properties file using the "property" task using the "file" attribute option. (again, see ant manual.) Finally, look the "fail" and "condition" ant tasks and note you'll need to use a "not" condition to invert the result of your custom condition:




...







...

Hope that helps??


You could make it fancier by having attributes in the "is_four_digits" element which are set in the build.xml file instead of being hard-coded in the java source code. See the custom task tutorials if that sounds like a good idea.

Re: Setting a call to pull a 4-digit number from the properties file

Posted By:   Daniel_Baylon  
Posted On:   Thursday, September 7, 2006 06:06 PM


I think you can create a custom task which reads a properties file and performs desired events.




This is a reference how to create custom tasks: http://ant.apache.org/manual/developlist.html




I hope this can help you.




Regards.

About | Sitemap | Contact