Repository navigation
Properties Group
A Properties group provides a way to define configurations through Properties at multiple "levels".
A Properties group is defined like this:
import org.abego.commons.util.PropertiesGroup;
...
private static final PropertiesGroup propertiesGroup =
newPropertiesGroup("mytools.maven");
In this example the name of the Properties group is mytools.maven. This Properties group also uses the shared group abego (*).
Later one can access the values of the Properties group with code like this, with "mvn" being the default value for the property "mytools.maven.tool" when the property is not specified externally:
String mvnTool = propertiesGroup.getProperty("mytools.maven.tool", "mvn"));
A Properties group's content is accumulated from multiple Properties sources:
- The System Properties
- Properties files in:
- the working directory
- the home directory
- the config directory ("{homeDirectory}/.config/abego.org/") (*)
A Properties file may be:
- group- and user-specific ("{groupName}-{userName}.properties")
- group-specific ("{groupName}.properties")
- shared and user-specific ("abego-{userName}.properties") (*)
- shared ("abego.properties") (*)
The following rules hold:
- A value defined in a System property overrules any value defined in a Properties file.
- A group-specific value overrules any shared value.
- A value defined in the working directory overrules any value defined in the home directory, which overrules any value defined in the config directory.
- Within a directory a user-specific value overrules a non-user-specific value.
These rules lead to the following "lookup order":
- System Properties
- "{workingDirectory}/{groupName}-{userName}.properties"
- "{workingDirectory}/{groupName}.properties"
- "{homeDirectory}/{groupName}-{userName}.properties"
- "{homeDirectory}/{groupName}.properties"
- "{homeDirectory}/.config/abego.org/{groupName}-{userName}.properties" (*)
- "{homeDirectory}/.config/abego.org/{groupName}.properties" (*)
- "{workingDirectory}/abego-{userName}.properties" (*)
- "{workingDirectory}/abego.properties" (*)
- "{homeDirectory}/abego-{userName}.properties" (*)
- "{homeDirectory}/abego.properties" (*)
- "{homeDirectory}/.config/abego.org/abego-{userName}.properties" (*)
- "{homeDirectory}/.config/abego.org/abego.properties" (*)
_("{workingDirectory}", "{homeDirectory}" and "{userName}" correspond to the System properties "{user.dir}", "{user.home}" and "{user.name}".)
With this lookup in mind one can now defined any required configuration value in different way.
Here are some ways how we may define the mytools.maven.tool value:
- We could pass it as a System property value to the application (with a JVM parameter
-Dmytools.maven.tool=my/path/to/the/maven/tool. - We could create an
abego.maven.propertiesfile with the contentmytools.maven.tool=my/path/to/the/maven/tooland put it in the working directory or the user's home directory or the directory.config/abego.orgin the user's home directory. - We could create (or edit) the file
abego.propertiesin the user's home directory and add the linemytools.maven.tool=my/path/to/the/maven/tool - (and many more)
Where to put the information depends on your needs. Defining a value in a abego.properties typically means the value is used by more than one application, a value defined in a properties file with a username part will only be applied for that specific user, using the System property parameter are only used in the given invocations.
(*) The config directory .config/abego.org/ and the name of the shared group abego can be customized when using the factory method newPropertiesGroup(String, String, String).