mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-18 14:55:53 -04:00
Merge pull request #296 from bitsquare/cbeams
Add support for $HOME/.bitsquare/bitsquare.properties
This commit is contained in:
commit
1ce151821a
@ -57,10 +57,11 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
||||
public static final String APP_DATA_DIR_CLEAN_KEY = "app.data.dir.clean";
|
||||
public static final String DEFAULT_APP_DATA_DIR_CLEAN = "false";
|
||||
|
||||
static final String BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME = "bitsquareDefaultProperties";
|
||||
static final String BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME = "bitsquareClasspathProperties";
|
||||
static final String BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME = "bitsquareFilesystemProperties";
|
||||
static final String BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME = "bitsquareCommandLineProperties";
|
||||
static final String BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME = "bitsquareAppDirProperties";
|
||||
static final String BITSQUARE_HOME_DIR_PROPERTY_SOURCE_NAME = "bitsquareHomeDirProperties";
|
||||
static final String BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME = "bitsquareClasspathProperties";
|
||||
static final String BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME = "bitsquareDefaultProperties";
|
||||
|
||||
private final ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
|
||||
@ -87,7 +88,8 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
||||
MutablePropertySources propertySources = this.getPropertySources();
|
||||
propertySources.addFirst(commandLineProperties);
|
||||
try {
|
||||
propertySources.addLast(filesystemProperties());
|
||||
propertySources.addLast(appDirProperties());
|
||||
propertySources.addLast(homeDirProperties());
|
||||
propertySources.addLast(classpathProperties());
|
||||
propertySources.addLast(defaultProperties());
|
||||
} catch (Exception ex) {
|
||||
@ -96,14 +98,24 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
||||
}
|
||||
|
||||
|
||||
PropertySource<?> filesystemProperties() throws Exception {
|
||||
PropertySource<?> appDirProperties() throws Exception {
|
||||
String location = String.format("file:%s/bitsquare.properties", appDataDir);
|
||||
Resource resource = resourceLoader.getResource(location);
|
||||
|
||||
if (!resource.exists())
|
||||
return new PropertySource.StubPropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME);
|
||||
return new PropertySource.StubPropertySource(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME);
|
||||
|
||||
return new ResourcePropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME, resource);
|
||||
return new ResourcePropertySource(BITSQUARE_APP_DIR_PROPERTY_SOURCE_NAME, resource);
|
||||
}
|
||||
|
||||
PropertySource<?> homeDirProperties() throws Exception {
|
||||
String location = String.format("file:%s/.bitsquare/bitsquare.properties", getProperty("user.home"));
|
||||
Resource resource = resourceLoader.getResource(location);
|
||||
|
||||
if (!resource.exists())
|
||||
return new PropertySource.StubPropertySource(BITSQUARE_HOME_DIR_PROPERTY_SOURCE_NAME);
|
||||
|
||||
return new ResourcePropertySource(BITSQUARE_HOME_DIR_PROPERTY_SOURCE_NAME, resource);
|
||||
}
|
||||
|
||||
PropertySource<?> classpathProperties() throws Exception {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user