In the last blog post I introduced what is the OWNER API and how to use it.
Basically it is tiny library that helps reducing the Java code to read the configuration for your application from Java Properties files. You can find full documentation here. Version 1.0.0 was having the very basic features, and now I’m adding new things that may return useful without compromising its simplicity and compactness.

Yesterday I have released version 1.0.3 which includes some new features that I want to introduce in some short blog posts.
On this weekend I set up the continuous integration on CloudBees and I noticed that compiling with JDK 6 there was a compilation error, since I was using JDK 7, so I decided that the fix was worthing another release, so that if somebody is using JDK 6 won’t have any problem.

So, what’s new then?

First of all, the OWNER library is now available on Maven Central Repository, and this will ease the job of people willing to try it, since now it only requires few lines to configure your project to use it, and I tried to improve the documentation. Unfortunately, publishing the library on Maven Central Repository required me to buy an internet domain name and use it for the groupId of the library. This may have broken the backward compatibility if someone started to use this library. I apologize for that.

The first thing I want to point out, is something I always missed in Java Properties files. A “variable expansion” mechanism.
For example, imagine your application having a configuration file like this:

server.host=myhost.com
service.url=http://${server.host}/some/endpoint
application.path=${HOME}/myapp
application.data=${application.path}/data
application.logs=${application.path}/logs

With plain Java properties file, the job to replace the variables is left to you. With Owner API, you can create a Java interface to map the above configuration and have all the variables resolved:

public interface MyAppConfig extends Config {
    @Key("server.host")
    String host();

    @Key("service.url")
    URL serviceURL();

    @Key("application.data")
    File appData();

    @Key("application.logs")
    File appLogs();
}

// then use it with:
MyAppConfig cfg = ConfigFactory.create(MyAppConfig.class, System.getenv());

The System.getenv() is used to resolve the ${HOME} system environment variable. In the same way you can pass other properties files too, like System properties or any other class implementing java.util.Map, see ConfigFactory.create(). I called this technique “importing properties”, since you specify some Properties or Maps during the creation of the Config object.

More details can be found on the README file on github: variables expansion and importing properties.

I’ll write more about what’s new in the next blog post.


No Responses to “Owner 1.0.3 what’s new? Part 1: variable expansion”  

  1. No Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Calendar

February 2013
M T W T F S S
« Dec   May »
 123
45678910
11121314151617
18192021222324
25262728  

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening