Add support for $HOME/.bitsquare/bitsquare.properties

This change allows users to place a bitsquare.properties file within
a `.bitsquare` directory under their home directory. This makes it
possible to specify property values (such as
node.useManualPortForwarding=true) that will survive cleaning the
application data dir (e.g. with `--clean=true` flag as introduced
in #291).

The precedence of this new "homeDirProperties" property source is lower
than the "appDirProperties" property source.

This means that if a user has a `bitsquare.properties` file both in his
home directory and in his application data directory, both files will be
processed, but for any properties that exist in both files, the property
specified in the application data directory file will take precedence.
This arrangement allows users to customize settings on an app-by-app
basis, which is especially useful in local testing scenarios where more
than one Bitsquare instance is running.
This commit is contained in:
Chris Beams 2014-11-27 10:19:21 +01:00
parent aa3fc929cb
commit 3c50a3c4f2
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
2 changed files with 26 additions and 13 deletions

View file

@ -41,13 +41,13 @@ public class BitsquareEnvironmentTests {
PropertySource commandlineProps = new MockPropertySource(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME)
.withProperty("key.x", "x.commandline");
PropertySource filesystemProps = new MockPropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME)
PropertySource filesystemProps = new MockPropertySource(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME)
.withProperty("key.x", "x.env")
.withProperty("key.y", "y.env");
ConfigurableEnvironment env = new BitsquareEnvironment(commandlineProps) {
@Override
PropertySource<?> filesystemProperties() {
PropertySource<?> appDirProperties() {
return filesystemProps;
}
};
@ -56,10 +56,11 @@ public class BitsquareEnvironmentTests {
assertThat(propertySources.precedenceOf(named(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(propertySources.precedenceOf(named(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(propertySources.precedenceOf(named(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(propertySources.precedenceOf(named(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(propertySources.precedenceOf(named(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(propertySources.precedenceOf(named(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME)), equalTo(5));
assertThat(propertySources.size(), equalTo(6));
assertThat(propertySources.precedenceOf(named(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(propertySources.precedenceOf(named(BITSQUARE_HOME_DIR_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(propertySources.precedenceOf(named(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME)), equalTo(5));
assertThat(propertySources.precedenceOf(named(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME)), equalTo(6));
assertThat(propertySources.size(), equalTo(7));
assertThat(env.getProperty("key.x"), equalTo("x.commandline")); // commandline value wins due to precedence
assertThat(env.getProperty("key.y"), equalTo("y.env")); // env value wins because it's the only one available