Rename NAME_FLAG => APP_NAME_KEY and move to AppModule

This commit is contained in:
Chris Beams 2014-11-10 00:50:59 +01:00
parent 935785e611
commit e8986aa7a2
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
4 changed files with 11 additions and 10 deletions

View File

@ -42,6 +42,7 @@ import net.tomp2p.connection.Ports;
* Configures all non-UI modules necessary to run a Bitsquare application.
*/
public class AppModule extends BitsquareModule {
public static final String APP_NAME_KEY = "name";
public AppModule(Properties properties) {
super(properties);
@ -59,7 +60,7 @@ public class AppModule extends BitsquareModule {
install(tradeModule());
install(offerModule());
String appName = properties.getProperty(ArgumentParser.NAME_FLAG);
String appName = properties.getProperty(APP_NAME_KEY);
Preconditions.checkArgument(appName != null, "App name must be non-null");
bindConstant().annotatedWith(Names.named("appName")).to(appName);

View File

@ -21,12 +21,11 @@ import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
import static io.bitsquare.msg.MessageModule.*;
public class ArgumentParser {
public static final String NAME_FLAG = "name";
private final net.sourceforge.argparse4j.inf.ArgumentParser parser;
public ArgumentParser() {
@ -43,7 +42,7 @@ public class ArgumentParser {
.help("Seed node port");
// Args for app config
parser.addArgument("-n", "--" + NAME_FLAG)
parser.addArgument("-n", "--" + APP_NAME_KEY)
.help("Name to append to default application name");
}

View File

@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory;
import lighthouse.files.AppDirectory;
import net.sourceforge.argparse4j.inf.Namespace;
import static io.bitsquare.app.ArgumentParser.NAME_FLAG;
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
import static io.bitsquare.msg.MessageModule.*;
public class Main extends Application {
@ -63,12 +63,12 @@ public class Main extends Application {
public static void main(String[] args) {
Namespace argumentsNamespace = new ArgumentParser().parseArgs(args);
if (argumentsNamespace.getString(NAME_FLAG) != null)
appName = appName + "-" + argumentsNamespace.getString(NAME_FLAG);
if (argumentsNamespace.getString(APP_NAME_KEY) != null)
appName = appName + "-" + argumentsNamespace.getString(APP_NAME_KEY);
properties = ConfigLoader.loadConfig(appName);
properties.setProperty(NAME_FLAG, appName);
properties.setProperty(APP_NAME_KEY, appName);
if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null)
properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY));

View File

@ -17,7 +17,6 @@
package io.bitsquare.app.gui;
import io.bitsquare.app.ArgumentParser;
import io.bitsquare.gui.FatalException;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.ViewLoader;
@ -35,6 +34,8 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
public class ViewLoaderTests {
public static class TestApp extends Application {
@ -63,7 +64,7 @@ public class ViewLoaderTests {
@Before
public void setUp() {
Properties properties = new Properties();
properties.setProperty(ArgumentParser.NAME_FLAG, "testApp");
properties.setProperty(APP_NAME_KEY, "testApp");
Injector injector = Guice.createInjector(new MainModule(properties, TestApp.primaryStage));
ViewLoader.setInjector(injector);
}