|
[
Permlink
| « Hide
]
Joerg Schaible added a comment - 06/Jul/07 07:07 AM - edited
Interpolation for system properties is already available, simply set up your configuration properly:
Joerg, I think this is a misunderstanding: This feature request is about environment variables, while Configuration so far only supports Java's system properties.
I had a vague memory that the topic "access to environment variables" was discussed before on the commons mailing list, and found this reference: http://thread.gmane.org/gmane.comp.jakarta.commons.devel/33239/focus=33325 Obviously this thread did not come to a final solution, AFAIK this feature was not added to one of the commons libraries. If it was (for instance in commons-lang), it would be really easy to incorporate it into commons-configuration. But having to implement it ourselves, situation looks different. The problem I see here is that it will really be difficult to implement a robust and portable solution, and besides this feature is probably out of scope for commons-configuration. From Java 1.5 on, access to environment properties will be possible using methods of the System class. So when we switch to this version (no idea when this will happen though) it will be no problem to satisfy this request. But for the moment I am reluctant. I have create simple Configuration to read environment variables. Please see file attached.
Also, I have tried to use PropertiesConfiguration.PropertiesReader#parseProperty(String line) magic, but it returns corrupted Windows paths by unescapeing variables values when it is not necessary. I didn't find a way to prevent it doing that. However, here is the code for you convenience if you want to play around: private static Properties readEnvVariables(final InputStream in) throws IOException return props; Note: I haven't tested it in UNIX, but it should work just fine. Vasily, many thanks for your contribution.
For the reasons outlined above I am still reluctant to add this feature to the code base. If you don't mind I would bring this topic again to the commons developer list and ask whether the opinion to support environment variables in one of the core libraries has changed in the mean time. What we could do in any case is adding your code to the WIKI in our examples section: Thanks Oliver, feel free to add that code anywhere you want.
As discussed on mailing list
(http://mail-archives.apache.org/mod_mbox/commons-dev/200709.mbox/%3c46F17EC2.2080600@oliver-heger.de%3e This patch introduces a new EnvironmentConfiguration implementation of Configuration that uses apache Ant on java < 5 to read the platform environment. On java5 runtime it uses System.getEnv() to avoid unecessary dependency on ant. the ant dependency has been set optionnal in the POM, as it is required only for this feature and only on java < 5 Many thanks for this contribution. Some questions:
Thanks again. The patch was applied with some modifications:
I did some testing on Java 1.5 and on earlier versions as well. Everything seems to work. Hello there,
The "env" interpolator prefix still does not seem to work. On investigation, I noticed that we have a new java class to support reading environment variables from different OSes, but there is no interpolator class (extending StrLookup) that supports the "env" prefix. Could someone look into this? For the moment, I have put in a class myself locally. Will add to the repository once I find some time.. Regards. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||