-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: Smart properties save() method #16
Comments
The intent, in your case, is that you want to keep the original file structure (comments and the order of the file properties), correct? The library, can load properties from a single property file (the first available from a list of I find the RFE interesting; I need to think a little bit on how to implement this in the correct way. |
Exactly. Preserve original file structure but update the specified (or all) property values. Your override capability is of interest to me too. That would allow PHP-like behavior where there is a base config file and then personal setting overrides. Perhaps it would make sense to have an annotation attribute to specify preferred write destination in the event of multiple sources? I'm not in a hurry. Thanks for your consideration. |
I do agree that this would be a nice addition. I will focus on automatic properties reload first (I'll try to take example from commons-config), and a The The new annotation attribute to specify preferred write destination doesn't convince me.
But once determined the path to be updated, this can be delegated to a specific method like
That can be made public (and available earlier). This will read the file then do the smart update as you described. So, at the end the methods that could be added to the Config interface can be something like:
The Implementing UpdatableConfig will add the support for updating the properties in memory or on the specified This is what it comes to my mind at the moment, but I'll think more about it. I think the above methods could satisfy your RFE. You can do:
And this should make the changes on the file and reload the properties immediately. It's not a single API call, but this allows people to change properties in memory without saving them to a file, that can also be desirable in some circumstances. Since the Comments and suggestions, are welcome. |
At first I didn't think that save(destination) would work for me, but that actually would be fine. I currently only call that in one place for the server. You see that I too use the ${} notation in my properties. However, I don't resolve that against the properties file. I resolve those properties based on runtime parameters (e.g. baseFolder is a command-line parameter or it is set by the web.xml). Is there a way to disable OWNER's resolution of ${} properties? |
It's not possible to disable properties resolution, if a variable ${} is not set, an empty string is replaced. There is no way to avoid this. But, you can pass an external context for your variables resolution (I called this "importing properties") Example:
The second parameter in ConfigFactory.create() is a vararg, so you can specify more than one map to resolve the properties. So, for example you can do Hope this helps. |
Do you you resolve these properties at property retrieval or at source load? |
When So this won't work:
The variables are substituted when the method |
Actually, I wanted to know when a value of "${baseFolder}/data" is resolved? At getting that property or at loading/copying the map into OWNER? |
The value is substituted when you call the method to retrieve the property (when you do See When you call MyConfig.foo() (that is actually a dynamic proxy), the |
James, I've not forgot these things. I've been busy these days with other issues but I count to get back on this asap. Thanks for the patience. |
No problem, it will be a while before I would be ready to integrate OWNER. No hurry, really. |
Hi James. About this question:
I just committed a new annotation that allows to disable the ${} and the parameter formatters, as described in the issue #20 . Documentation is updated and - as example - the junit test can be seen. This annotation, when specified on class level is not inherited by subclasses by design. This annotation will be available in version 1.0.4, and at the moment is available on the latest snapshot. If you need this to be released into 1.0.4 final, I'll release it. |
I've implemented a Now I want to make some progress in the automatic reload (changing the file on the disk, the configuration is reloaded automatically in the Config object) The smart update of files as you indicated here is not available yet. And I feel I need to think more on how this should be designed in the API interfaces. |
Hi James. I will release 1.0.4 soon, and it will include the hot reload feature, as well the Regarding the smart properties save, I thought long time how this should be implemented, and - they way I feel it should be - is very complicated, as I described above. I think it may be just simpler to include your method in a utility method that is implemeted as you already did, but I quite don't feel it fitting in the rest of the API. Any suggestion? |
I am also interested in a smart save() method as described. You can see an implementation of such in Apache Commons Configuration using the PropertiesConfigurationLayout helper class: Have you had additional thoughts since the original posts a year ago? Thank you for your excellent work on OWNER. |
I didn't do any work on this, but after initial (complicated) idea I had, I thought I would do something like the implementation you pointed out from commons-configuration. Actually I was thinking to use some layout engine like velocity or freemarker (in a separate maven module). I also think this would be a nice feature, and it's something that I would like to add. Thanks. L. |
Hi Luigi, Thanks for the information and for your work on this project. The design of All the best, Gary On Tue, Mar 18, 2014 at 8:00 AM, Luigi R. Viggiano <[email protected]
|
I use properties files as config files in Gitblit so your project is very interesting to me. Issue 15 (hot reload) is definitely a requirement for me to adopt your library, but another thing I would be missing is an enhanced write feature that replaces a property value in the file without destroying the file. I currently document config settings within the properties file (example https://github.com/gitblit/gitblit/blob/master/distrib/gitblit.properties). Unfortunately, the stock Properties class destroys the source file when you save. It is not very smart. :(
To work around this I implemented a smarter save. You can see my implementation of this here: https://github.com/gitblit/gitblit/blob/master/src/com/gitblit/FileSettings.java#L86
That capability is actually pretty small and I think would make a nice addition to your library.
The text was updated successfully, but these errors were encountered: