mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 15:26:03 -04:00
Supply appName via properties as well
Like all other command-line options and/or configuration file properties, appName is now parsed for early in #main and its value (default or custom) is then used to populate the Properties object made available to all Guice modules. See the previous commit for additional details.
This commit is contained in:
parent
162fc3da0e
commit
b5f95e00a3
@ -29,6 +29,8 @@ import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.TradeModule;
|
||||
import io.bitsquare.user.User;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
@ -48,11 +50,8 @@ import scala.concurrent.duration.Duration;
|
||||
public class AppModule extends BitsquareModule {
|
||||
private static final Logger log = LoggerFactory.getLogger(AppModule.class);
|
||||
|
||||
private final String appName;
|
||||
|
||||
public AppModule(Properties properties, String appName) {
|
||||
public AppModule(Properties properties) {
|
||||
super(properties);
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,6 +66,9 @@ public class AppModule extends BitsquareModule {
|
||||
install(tradeModule());
|
||||
install(offerModule());
|
||||
|
||||
String appName = properties.getProperty(ArgumentParser.NAME_FLAG);
|
||||
Preconditions.checkArgument(appName != null, "App name must be non-null");
|
||||
|
||||
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
||||
bind(ActorSystem.class).toInstance(ActorSystem.create(appName));
|
||||
|
||||
|
@ -60,13 +60,15 @@ public class Main extends Application {
|
||||
private Injector injector;
|
||||
|
||||
public static void main(String[] args) {
|
||||
properties = ConfigLoader.loadConfig(appName);
|
||||
|
||||
Namespace argumentsNamespace = new ArgumentParser().parseArgs(args);
|
||||
|
||||
if (argumentsNamespace.getString(NAME_FLAG) != null)
|
||||
appName = appName + "-" + argumentsNamespace.getString(NAME_FLAG);
|
||||
|
||||
properties = ConfigLoader.loadConfig(appName);
|
||||
|
||||
properties.setProperty(NAME_FLAG, appName);
|
||||
|
||||
if (argumentsNamespace.getString(SEED_ID_FLAG) != null)
|
||||
properties.setProperty(SEED_ID_FLAG, argumentsNamespace.getString(SEED_ID_FLAG));
|
||||
|
||||
@ -81,7 +83,7 @@ public class Main extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
mainModule = new MainModule(properties, appName, primaryStage);
|
||||
mainModule = new MainModule(properties, primaryStage);
|
||||
injector = Guice.createInjector(mainModule);
|
||||
|
||||
|
||||
|
@ -26,19 +26,16 @@ import java.util.Properties;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
class MainModule extends BitsquareModule {
|
||||
|
||||
private final String appName;
|
||||
private final Stage primaryStage;
|
||||
|
||||
public MainModule(Properties properties, String appName, Stage primaryStage) {
|
||||
public MainModule(Properties properties, Stage primaryStage) {
|
||||
super(properties);
|
||||
this.appName = appName;
|
||||
this.primaryStage = primaryStage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new AppModule(properties, appName));
|
||||
install(new AppModule(properties));
|
||||
install(new GuiModule(properties, primaryStage));
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
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;
|
||||
@ -64,7 +65,9 @@ public class ViewLoaderTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Injector injector = Guice.createInjector(new MainModule(new Properties(), "testApp", TestApp.primaryStage));
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(ArgumentParser.NAME_FLAG, "testApp");
|
||||
Injector injector = Guice.createInjector(new MainModule(properties, TestApp.primaryStage));
|
||||
ViewLoader.setInjector(injector);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user