ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: ANT task to process properties-files into static class
Date Wed, 03 Jan 2007 13:49:41 GMT
Keith Hatton wrote:
> Two more robust solutions spring to mind:
> 
> 1. You can use Properties.getProperty(String,String) to prevent your
> NPE. The first string is the property name, the second is a default
> value to be used when the property is not present.
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#getPro
> perty(java.lang.String,%20java.lang.String)
> 
> 2. Check for null values in your code - and if the property is mandatory
> but missing, then throw an appropriate exception to the user.
> 
> 
3. override the method in a subclass of Property


String getProperty(String name) {
  String value=super.getProperty(name);
  if(value==null) throw new IllegalArgumentException("No property 
"+name+" in +this);
  return value;
}


What you may want to do is have a constant defined for every property 
name. So you cannot misspell the property string. I'd use <xslt> to 
create the java source from an XML template; its how I generate 
constants. There is an example for this in the forthcoming Ant in Action 
book...


-steve


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message