mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 00:45:23 -04:00
Rename NAME_FLAG => APP_NAME_KEY and move to AppModule
This commit is contained in:
parent
935785e611
commit
e8986aa7a2
4 changed files with 11 additions and 10 deletions
|
@ -42,6 +42,7 @@ import net.tomp2p.connection.Ports;
|
||||||
* Configures all non-UI modules necessary to run a Bitsquare application.
|
* Configures all non-UI modules necessary to run a Bitsquare application.
|
||||||
*/
|
*/
|
||||||
public class AppModule extends BitsquareModule {
|
public class AppModule extends BitsquareModule {
|
||||||
|
public static final String APP_NAME_KEY = "name";
|
||||||
|
|
||||||
public AppModule(Properties properties) {
|
public AppModule(Properties properties) {
|
||||||
super(properties);
|
super(properties);
|
||||||
|
@ -59,7 +60,7 @@ public class AppModule extends BitsquareModule {
|
||||||
install(tradeModule());
|
install(tradeModule());
|
||||||
install(offerModule());
|
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");
|
Preconditions.checkArgument(appName != null, "App name must be non-null");
|
||||||
|
|
||||||
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
||||||
|
|
|
@ -21,12 +21,11 @@ import net.sourceforge.argparse4j.ArgumentParsers;
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
|
||||||
|
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
|
||||||
import static io.bitsquare.msg.MessageModule.*;
|
import static io.bitsquare.msg.MessageModule.*;
|
||||||
|
|
||||||
public class ArgumentParser {
|
public class ArgumentParser {
|
||||||
|
|
||||||
public static final String NAME_FLAG = "name";
|
|
||||||
|
|
||||||
private final net.sourceforge.argparse4j.inf.ArgumentParser parser;
|
private final net.sourceforge.argparse4j.inf.ArgumentParser parser;
|
||||||
|
|
||||||
public ArgumentParser() {
|
public ArgumentParser() {
|
||||||
|
@ -43,7 +42,7 @@ public class ArgumentParser {
|
||||||
.help("Seed node port");
|
.help("Seed node port");
|
||||||
|
|
||||||
// Args for app config
|
// Args for app config
|
||||||
parser.addArgument("-n", "--" + NAME_FLAG)
|
parser.addArgument("-n", "--" + APP_NAME_KEY)
|
||||||
.help("Name to append to default application name");
|
.help("Name to append to default application name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import lighthouse.files.AppDirectory;
|
import lighthouse.files.AppDirectory;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
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.*;
|
import static io.bitsquare.msg.MessageModule.*;
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
@ -63,12 +63,12 @@ public class Main extends Application {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Namespace argumentsNamespace = new ArgumentParser().parseArgs(args);
|
Namespace argumentsNamespace = new ArgumentParser().parseArgs(args);
|
||||||
|
|
||||||
if (argumentsNamespace.getString(NAME_FLAG) != null)
|
if (argumentsNamespace.getString(APP_NAME_KEY) != null)
|
||||||
appName = appName + "-" + argumentsNamespace.getString(NAME_FLAG);
|
appName = appName + "-" + argumentsNamespace.getString(APP_NAME_KEY);
|
||||||
|
|
||||||
properties = ConfigLoader.loadConfig(appName);
|
properties = ConfigLoader.loadConfig(appName);
|
||||||
|
|
||||||
properties.setProperty(NAME_FLAG, appName);
|
properties.setProperty(APP_NAME_KEY, appName);
|
||||||
|
|
||||||
if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null)
|
if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null)
|
||||||
properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY));
|
properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY));
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package io.bitsquare.app.gui;
|
package io.bitsquare.app.gui;
|
||||||
|
|
||||||
import io.bitsquare.app.ArgumentParser;
|
|
||||||
import io.bitsquare.gui.FatalException;
|
import io.bitsquare.gui.FatalException;
|
||||||
import io.bitsquare.gui.Navigation;
|
import io.bitsquare.gui.Navigation;
|
||||||
import io.bitsquare.gui.ViewLoader;
|
import io.bitsquare.gui.ViewLoader;
|
||||||
|
@ -35,6 +34,8 @@ import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
|
||||||
|
|
||||||
public class ViewLoaderTests {
|
public class ViewLoaderTests {
|
||||||
|
|
||||||
public static class TestApp extends Application {
|
public static class TestApp extends Application {
|
||||||
|
@ -63,7 +64,7 @@ public class ViewLoaderTests {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Properties properties = new Properties();
|
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));
|
Injector injector = Guice.createInjector(new MainModule(properties, TestApp.primaryStage));
|
||||||
ViewLoader.setInjector(injector);
|
ViewLoader.setInjector(injector);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue