mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Merge branch 'cbeams'
* cbeams: Reorder methods in BitsquareEnvironment for clarity Introduce 'app.version' property and remove hardcoded version Use Preconditions#checkNotNull vs. #checkArgument Rename name, port properties to node.name, node.port Remove unused ApplicationPreferences variable Rename config file from bitsquare.{conf=>properties}
This commit is contained in:
commit
69ed19d3dc
@ -1,3 +1,4 @@
|
|||||||
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
import org.apache.tools.ant.taskdefs.condition.Os
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
@ -25,6 +26,13 @@ run {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
|
include '**/*.properties'
|
||||||
|
filter(ReplaceTokens, tokens: [ 'app.version': project.version ])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
maven { url 'http://partnerdemo.artifactoryonline.com/partnerdemo/libs-snapshots-local' }
|
maven { url 'http://partnerdemo.artifactoryonline.com/partnerdemo/libs-snapshots-local' }
|
||||||
|
@ -42,6 +42,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
public class BitsquareEnvironment extends StandardEnvironment {
|
public class BitsquareEnvironment extends StandardEnvironment {
|
||||||
|
|
||||||
|
public static final String APP_VERSION_KEY = "app.version";
|
||||||
|
|
||||||
public static final String USER_DATA_DIR_KEY = "user.data.dir";
|
public static final String USER_DATA_DIR_KEY = "user.data.dir";
|
||||||
public static final String DEFAULT_USER_DATA_DIR = defaultUserDataDir();
|
public static final String DEFAULT_USER_DATA_DIR = defaultUserDataDir();
|
||||||
|
|
||||||
@ -90,13 +92,28 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PropertySource<?> filesystemProperties() 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 ResourcePropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME, resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertySource<?> classpathProperties() throws Exception {
|
||||||
|
Resource resource = resourceLoader.getResource("classpath:bitsquare.properties");
|
||||||
|
return new ResourcePropertySource(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME, resource);
|
||||||
|
}
|
||||||
|
|
||||||
PropertySource<?> defaultProperties() throws Exception {
|
PropertySource<?> defaultProperties() throws Exception {
|
||||||
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{
|
return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{
|
||||||
setProperty(APP_DATA_DIR_KEY, appDataDir);
|
setProperty(APP_DATA_DIR_KEY, appDataDir);
|
||||||
setProperty(APP_NAME_KEY, appName);
|
setProperty(APP_NAME_KEY, appName);
|
||||||
|
|
||||||
setProperty(UserAgent.NAME_KEY, appName);
|
setProperty(UserAgent.NAME_KEY, appName);
|
||||||
setProperty(UserAgent.VERSION_KEY, "0.1");
|
setProperty(UserAgent.VERSION_KEY, BitsquareEnvironment.this.getRequiredProperty(APP_VERSION_KEY));
|
||||||
|
|
||||||
setProperty(WalletFacade.DIR_KEY, appDataDir);
|
setProperty(WalletFacade.DIR_KEY, appDataDir);
|
||||||
setProperty(WalletFacade.PREFIX_KEY, appName);
|
setProperty(WalletFacade.PREFIX_KEY, appName);
|
||||||
@ -108,21 +125,6 @@ public class BitsquareEnvironment extends StandardEnvironment {
|
|||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertySource<?> classpathProperties() throws Exception {
|
|
||||||
Resource resource = resourceLoader.getResource("classpath:bitsquare.properties");
|
|
||||||
return new ResourcePropertySource(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME, resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertySource<?> filesystemProperties() throws Exception {
|
|
||||||
String location = String.format("file:%s/bitsquare.conf", appDataDir);
|
|
||||||
Resource resource = resourceLoader.getResource(location);
|
|
||||||
|
|
||||||
if (!resource.exists())
|
|
||||||
return new PropertySource.StubPropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME);
|
|
||||||
|
|
||||||
return new ResourcePropertySource(BITSQUARE_FILESYSTEM_PROPERTY_SOURCE_NAME, resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static String defaultUserDataDir() {
|
private static String defaultUserDataDir() {
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
String os = System.getProperty("os.name").toLowerCase();
|
||||||
|
@ -25,10 +25,8 @@ import io.bitsquare.gui.ViewLoader;
|
|||||||
import io.bitsquare.gui.components.Popups;
|
import io.bitsquare.gui.components.Popups;
|
||||||
import io.bitsquare.gui.util.ImageUtil;
|
import io.bitsquare.gui.util.ImageUtil;
|
||||||
import io.bitsquare.persistence.Persistence;
|
import io.bitsquare.persistence.Persistence;
|
||||||
import io.bitsquare.preferences.ApplicationPreferences;
|
|
||||||
import io.bitsquare.user.User;
|
import io.bitsquare.user.User;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
@ -48,6 +46,7 @@ import javafx.stage.Stage;
|
|||||||
|
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static io.bitsquare.app.BitsquareEnvironment.*;
|
import static io.bitsquare.app.BitsquareEnvironment.*;
|
||||||
|
|
||||||
public class BitsquareApp extends Application {
|
public class BitsquareApp extends Application {
|
||||||
@ -62,8 +61,7 @@ public class BitsquareApp extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws IOException {
|
public void start(Stage primaryStage) throws IOException {
|
||||||
Preconditions.checkArgument(env != null, "Environment must not be null");
|
checkNotNull(env, "Environment must not be null");
|
||||||
|
|
||||||
bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
|
bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
|
||||||
injector = Guice.createInjector(bitsquareAppModule);
|
injector = Guice.createInjector(bitsquareAppModule);
|
||||||
|
|
||||||
@ -82,7 +80,6 @@ public class BitsquareApp extends Application {
|
|||||||
// load and apply any stored settings
|
// load and apply any stored settings
|
||||||
|
|
||||||
User user = injector.getInstance(User.class);
|
User user = injector.getInstance(User.class);
|
||||||
ApplicationPreferences applicationPreferences = injector.getInstance(ApplicationPreferences.class);
|
|
||||||
AccountSettings accountSettings = injector.getInstance(AccountSettings.class);
|
AccountSettings accountSettings = injector.getInstance(AccountSettings.class);
|
||||||
Persistence persistence = injector.getInstance(Persistence.class);
|
Persistence persistence = injector.getInstance(Persistence.class);
|
||||||
persistence.init();
|
persistence.init();
|
||||||
|
@ -42,7 +42,7 @@ public class BitsquareAppMain extends BitsquareExecutable {
|
|||||||
parser.accepts(USER_DATA_DIR_KEY, "User data directory").withRequiredArg().defaultsTo(DEFAULT_USER_DATA_DIR);
|
parser.accepts(USER_DATA_DIR_KEY, "User data directory").withRequiredArg().defaultsTo(DEFAULT_USER_DATA_DIR);
|
||||||
parser.accepts(APP_NAME_KEY, "Application name").withRequiredArg().defaultsTo(DEFAULT_APP_NAME);
|
parser.accepts(APP_NAME_KEY, "Application name").withRequiredArg().defaultsTo(DEFAULT_APP_NAME);
|
||||||
parser.accepts(APP_DATA_DIR_KEY, "Application data directory").withRequiredArg().defaultsTo(DEFAULT_APP_DATA_DIR);
|
parser.accepts(APP_DATA_DIR_KEY, "Application data directory").withRequiredArg().defaultsTo(DEFAULT_APP_DATA_DIR);
|
||||||
parser.accepts(NAME_KEY, "Network name").withRequiredArg();
|
parser.accepts(NAME_KEY, "Name of this node").withRequiredArg();
|
||||||
parser.accepts(PORT_KEY, "Port to listen on").withRequiredArg().defaultsTo(String.valueOf(Node.DEFAULT_PORT));
|
parser.accepts(PORT_KEY, "Port to listen on").withRequiredArg().defaultsTo(String.valueOf(Node.DEFAULT_PORT));
|
||||||
parser.accepts(BITCOIN_NETWORK_KEY).withRequiredArg().defaultsTo(BitcoinModule.DEFAULT_BITCOIN_NETWORK);
|
parser.accepts(BITCOIN_NETWORK_KEY).withRequiredArg().defaultsTo(BitcoinModule.DEFAULT_BITCOIN_NETWORK);
|
||||||
parser.accepts(BOOTSTRAP_NODE_NAME_KEY).withRequiredArg().defaultsTo(BootstrapNodes.DEFAULT.getName());
|
parser.accepts(BOOTSTRAP_NODE_NAME_KEY).withRequiredArg().defaultsTo(BootstrapNodes.DEFAULT.getName());
|
||||||
|
@ -20,8 +20,8 @@ package io.bitsquare.network;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
public final class Node {
|
public final class Node {
|
||||||
public static final String NAME_KEY = "name";
|
public static final String NAME_KEY = "node.name";
|
||||||
public static final String PORT_KEY = "port";
|
public static final String PORT_KEY = "node.port";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default port is one <a
|
* Default port is one <a
|
||||||
|
@ -1 +1 @@
|
|||||||
# Empty for now; see ConfigLoader
|
app.version=@app.version@
|
@ -17,15 +17,18 @@
|
|||||||
|
|
||||||
package io.bitsquare.app;
|
package io.bitsquare.app;
|
||||||
|
|
||||||
|
import io.bitsquare.btc.UserAgent;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.MutablePropertySources;
|
import org.springframework.core.env.MutablePropertySources;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.mock.env.MockPropertySource;
|
import org.springframework.mock.env.MockPropertySource;
|
||||||
|
|
||||||
import static io.bitsquare.app.BitsquareEnvironment.*;
|
import static io.bitsquare.app.BitsquareEnvironment.*;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.core.env.PropertySource.named;
|
import static org.springframework.core.env.PropertySource.named;
|
||||||
import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
|
import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
|
||||||
@ -58,4 +61,15 @@ public class BitsquareEnvironmentTests {
|
|||||||
assertThat(env.getProperty("key.x"), equalTo("x.commandline")); // commandline value wins due to precedence
|
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
|
assertThat(env.getProperty("key.y"), equalTo("y.env")); // env value wins because it's the only one available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bitsquareVersionShouldBeAvailable() {
|
||||||
|
// we cannot actually test for the value because (a) it requires Gradle's
|
||||||
|
// processResources task filtering (which does not happen within IDEA) and
|
||||||
|
// (b) because we do not know the specific version to test for. Instead just
|
||||||
|
// test that the property has been made available.
|
||||||
|
Environment env = new BitsquareEnvironment(new MockPropertySource());
|
||||||
|
assertThat(env.containsProperty(APP_VERSION_KEY), is(true));
|
||||||
|
assertThat(env.getProperty(UserAgent.VERSION_KEY), equalTo(env.getProperty(APP_VERSION_KEY)));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user