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:
Chris Beams 2014-11-09 23:42:57 +01:00
parent 162fc3da0e
commit b5f95e00a3
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
4 changed files with 17 additions and 13 deletions

View File

@ -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));

View File

@ -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);

View File

@ -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));
}
}

View File

@ -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);
}