From 1fcd0343d5e3202003b5f63ecc1909f0ac06840d Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 11 Nov 2014 21:36:48 +0100 Subject: [PATCH 1/6] Rename config file from bitsquare.{conf=>properties} --- src/main/java/io/bitsquare/app/BitsquareEnvironment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/bitsquare/app/BitsquareEnvironment.java b/src/main/java/io/bitsquare/app/BitsquareEnvironment.java index daa5f15680..029279e674 100644 --- a/src/main/java/io/bitsquare/app/BitsquareEnvironment.java +++ b/src/main/java/io/bitsquare/app/BitsquareEnvironment.java @@ -114,7 +114,7 @@ public class BitsquareEnvironment extends StandardEnvironment { } PropertySource filesystemProperties() throws Exception { - String location = String.format("file:%s/bitsquare.conf", appDataDir); + String location = String.format("file:%s/bitsquare.properties", appDataDir); Resource resource = resourceLoader.getResource(location); if (!resource.exists()) From d55a03f2d8286f212b15c4c837f94b1891188b42 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 11 Nov 2014 21:51:57 +0100 Subject: [PATCH 2/6] Remove unused ApplicationPreferences variable --- src/main/java/io/bitsquare/app/gui/BitsquareApp.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/io/bitsquare/app/gui/BitsquareApp.java b/src/main/java/io/bitsquare/app/gui/BitsquareApp.java index 188c30ada9..c03fe0cb42 100644 --- a/src/main/java/io/bitsquare/app/gui/BitsquareApp.java +++ b/src/main/java/io/bitsquare/app/gui/BitsquareApp.java @@ -25,7 +25,6 @@ import io.bitsquare.gui.ViewLoader; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.persistence.Persistence; -import io.bitsquare.preferences.ApplicationPreferences; import io.bitsquare.user.User; import com.google.common.base.Preconditions; @@ -82,7 +81,6 @@ public class BitsquareApp extends Application { // load and apply any stored settings User user = injector.getInstance(User.class); - ApplicationPreferences applicationPreferences = injector.getInstance(ApplicationPreferences.class); AccountSettings accountSettings = injector.getInstance(AccountSettings.class); Persistence persistence = injector.getInstance(Persistence.class); persistence.init(); From ccd5f815f894ae689690a1391757263695f7df49 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 11 Nov 2014 21:52:43 +0100 Subject: [PATCH 3/6] Rename name, port properties to node.name, node.port --- src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java | 2 +- src/main/java/io/bitsquare/network/Node.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java b/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java index da72226152..18da83cfd6 100644 --- a/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java +++ b/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java @@ -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(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(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(BITCOIN_NETWORK_KEY).withRequiredArg().defaultsTo(BitcoinModule.DEFAULT_BITCOIN_NETWORK); parser.accepts(BOOTSTRAP_NODE_NAME_KEY).withRequiredArg().defaultsTo(BootstrapNodes.DEFAULT.getName()); diff --git a/src/main/java/io/bitsquare/network/Node.java b/src/main/java/io/bitsquare/network/Node.java index 349f9dcfce..08252e8e0a 100644 --- a/src/main/java/io/bitsquare/network/Node.java +++ b/src/main/java/io/bitsquare/network/Node.java @@ -20,8 +20,8 @@ package io.bitsquare.network; import com.google.common.base.Objects; public final class Node { - public static final String NAME_KEY = "name"; - public static final String PORT_KEY = "port"; + public static final String NAME_KEY = "node.name"; + public static final String PORT_KEY = "node.port"; /** * Default port is one Date: Tue, 11 Nov 2014 21:56:44 +0100 Subject: [PATCH 4/6] Use Preconditions#checkNotNull vs. #checkArgument --- src/main/java/io/bitsquare/app/gui/BitsquareApp.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/bitsquare/app/gui/BitsquareApp.java b/src/main/java/io/bitsquare/app/gui/BitsquareApp.java index c03fe0cb42..1160edffce 100644 --- a/src/main/java/io/bitsquare/app/gui/BitsquareApp.java +++ b/src/main/java/io/bitsquare/app/gui/BitsquareApp.java @@ -27,7 +27,6 @@ import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.persistence.Persistence; import io.bitsquare.user.User; -import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.inject.Guice; @@ -47,6 +46,7 @@ import javafx.stage.Stage; import org.springframework.core.env.Environment; +import static com.google.common.base.Preconditions.checkNotNull; import static io.bitsquare.app.BitsquareEnvironment.*; public class BitsquareApp extends Application { @@ -61,8 +61,7 @@ public class BitsquareApp extends Application { @Override 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); injector = Guice.createInjector(bitsquareAppModule); From 9adc41e23f2b98130c9c737225c3beddb8181364 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 11 Nov 2014 22:33:32 +0100 Subject: [PATCH 5/6] Introduce 'app.version' property and remove hardcoded version --- build.gradle | 8 ++++++++ .../io/bitsquare/app/BitsquareEnvironment.java | 4 +++- src/main/resources/bitsquare.properties | 2 +- .../bitsquare/app/BitsquareEnvironmentTests.java | 16 +++++++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index afe21cc5e8..8ba5d6e4ff 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import org.apache.tools.ant.filters.ReplaceTokens import org.apache.tools.ant.taskdefs.condition.Os plugins { @@ -25,6 +26,13 @@ run { } } +processResources { + from(sourceSets.main.resources.srcDirs) { + include '**/*.properties' + filter(ReplaceTokens, tokens: [ 'app.version': project.version ]) + } +} + repositories { jcenter() maven { url 'http://partnerdemo.artifactoryonline.com/partnerdemo/libs-snapshots-local' } diff --git a/src/main/java/io/bitsquare/app/BitsquareEnvironment.java b/src/main/java/io/bitsquare/app/BitsquareEnvironment.java index 029279e674..a826c8c48a 100644 --- a/src/main/java/io/bitsquare/app/BitsquareEnvironment.java +++ b/src/main/java/io/bitsquare/app/BitsquareEnvironment.java @@ -42,6 +42,8 @@ import static com.google.common.base.Preconditions.checkNotNull; 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 DEFAULT_USER_DATA_DIR = defaultUserDataDir(); @@ -96,7 +98,7 @@ public class BitsquareEnvironment extends StandardEnvironment { setProperty(APP_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.PREFIX_KEY, appName); diff --git a/src/main/resources/bitsquare.properties b/src/main/resources/bitsquare.properties index 93b4dec9d3..50d6961e71 100644 --- a/src/main/resources/bitsquare.properties +++ b/src/main/resources/bitsquare.properties @@ -1 +1 @@ -# Empty for now; see ConfigLoader \ No newline at end of file +app.version=@app.version@ \ No newline at end of file diff --git a/src/test/java/io/bitsquare/app/BitsquareEnvironmentTests.java b/src/test/java/io/bitsquare/app/BitsquareEnvironmentTests.java index e9c94fbf4c..f427554783 100644 --- a/src/test/java/io/bitsquare/app/BitsquareEnvironmentTests.java +++ b/src/test/java/io/bitsquare/app/BitsquareEnvironmentTests.java @@ -17,15 +17,18 @@ package io.bitsquare.app; +import io.bitsquare.btc.UserAgent; + import org.junit.Test; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.mock.env.MockPropertySource; 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.springframework.core.env.PropertySource.named; 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.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))); + } } \ No newline at end of file From 14dde61832797110bc2d5a8d7af4fa9d9a3390df Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 11 Nov 2014 22:42:01 +0100 Subject: [PATCH 6/6] Reorder methods in BitsquareEnvironment for clarity --- .../bitsquare/app/BitsquareEnvironment.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/bitsquare/app/BitsquareEnvironment.java b/src/main/java/io/bitsquare/app/BitsquareEnvironment.java index a826c8c48a..57a5ade700 100644 --- a/src/main/java/io/bitsquare/app/BitsquareEnvironment.java +++ b/src/main/java/io/bitsquare/app/BitsquareEnvironment.java @@ -92,6 +92,21 @@ 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 { return new PropertiesPropertySource(BITSQUARE_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {{ setProperty(APP_DATA_DIR_KEY, appDataDir); @@ -110,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.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); - } - private static String defaultUserDataDir() { String os = System.getProperty("os.name").toLowerCase();