Remove now unused BisqEnvironment class

In previous commits, BisqEnvironment functionality has been fully ported
to the new, simpler and more type-safe Config class. This change removes
BisqEnvironment and all dependencies on the Spring Framework Environment
interface that it implements.

The one exception is the pricenode module, which is separate and apart
from the rest of the codebase in that it is a standalone, Spring-based
HTTP service.
This commit is contained in:
Chris Beams 2019-12-17 19:57:36 +01:00
parent 1216ba2e2c
commit f5a1854762
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
30 changed files with 53 additions and 259 deletions

View File

@ -19,26 +19,19 @@ package bisq.common.app;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
public abstract class AppModule extends AbstractModule {
protected final Environment environment;
protected final Config config;
private final List<AppModule> modules = new ArrayList<>();
protected AppModule(Environment environment, Config config) {
Preconditions.checkNotNull(environment, "Environment must not be null");
this.environment = environment;
protected AppModule(Config config) {
this.config = config;
}

View File

@ -20,8 +20,6 @@ package bisq.core.alert;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import static bisq.common.config.Config.IGNORE_DEV_MSG;
@ -29,8 +27,8 @@ import static com.google.inject.name.Names.named;
public class AlertModule extends AppModule {
public AlertModule(Environment environment, Config config) {
super(environment, config);
public AlertModule(Config config) {
super(config);
}
@Override

View File

@ -1,83 +0,0 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.app;
import bisq.common.BisqException;
import org.springframework.core.env.JOptCommandLinePropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import joptsimple.OptionSet;
import java.util.Properties;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
public class BisqEnvironment extends StandardEnvironment {
///////////////////////////////////////////////////////////////////////////////////////////
// Static
///////////////////////////////////////////////////////////////////////////////////////////
public static final String BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME = "bisqCommandLineProperties";
public static final String BISQ_DEFAULT_PROPERTY_SOURCE_NAME = "bisqDefaultProperties";
///////////////////////////////////////////////////////////////////////////////////////////
// Instance fields
///////////////////////////////////////////////////////////////////////////////////////////
@Getter
@Setter
protected boolean isBitcoinLocalhostNodeRunning;
public BisqEnvironment(OptionSet options) {
this(new JOptCommandLinePropertySource(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME, checkNotNull(
options)));
}
@SuppressWarnings("ConstantConditions")
public BisqEnvironment(PropertySource commandLineProperties) {
MutablePropertySources propertySources = getPropertySources();
propertySources.addFirst(commandLineProperties);
try {
propertySources.addLast(defaultProperties());
} catch (Exception ex) {
throw new BisqException(ex);
}
}
private String getProperty(PropertySource properties, String propertyKey, String defaultValue) {
return properties.containsProperty(propertyKey) ? (String) properties.getProperty(propertyKey) : defaultValue;
}
private PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{
}
});
}
}

View File

@ -41,8 +41,6 @@ import bisq.common.handlers.ResultHandler;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.setup.GracefulShutDownHandler;
import org.springframework.core.env.JOptCommandLinePropertySource;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
@ -58,10 +56,6 @@ import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import static bisq.core.app.BisqEnvironment.BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
@Slf4j
public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener {
@ -76,7 +70,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
protected Injector injector;
protected AppModule module;
protected BisqEnvironment bisqEnvironment;
protected Config config;
public BisqExecutable(String fullName, String scriptName, String appName, String version) {
@ -129,8 +122,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
///////////////////////////////////////////////////////////////////////////////////////////
protected void doExecute(OptionSet options) {
bisqEnvironment = new BisqEnvironment(
new JOptCommandLinePropertySource(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME, checkNotNull(options)));
configUserThread();
CoreSetup.setup(config);
addCapabilities();

View File

@ -95,7 +95,7 @@ public class BisqHeadlessAppMain extends BisqExecutable {
@Override
protected AppModule getModule() {
return new CoreModule(bisqEnvironment, config);
return new CoreModule(config);
}
@Override

View File

@ -45,8 +45,6 @@ import bisq.common.crypto.PubKeyRingProvider;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import org.springframework.core.env.Environment;
import java.io.File;
import static bisq.common.config.Config.*;
@ -54,13 +52,12 @@ import static com.google.inject.name.Names.named;
public class CoreModule extends AppModule {
public CoreModule(Environment environment, Config config) {
super(environment, config);
public CoreModule(Config config) {
super(config);
}
@Override
protected void configure() {
bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment);
bind(Config.class).toInstance(config);
bind(BridgeAddressProvider.class).to(Preferences.class);
@ -83,15 +80,15 @@ public class CoreModule extends AppModule {
// ordering is used for shut down sequence
install(new TradeModule(environment, config));
install(new EncryptionServiceModule(environment, config));
install(new OfferModule(environment, config));
install(new P2PModule(environment, config));
install(new BitcoinModule(environment, config));
install(new DaoModule(environment, config));
install(new AlertModule(environment, config));
install(new FilterModule(environment, config));
install(new CorePresentationModule(environment, config));
install(new TradeModule(config));
install(new EncryptionServiceModule(config));
install(new OfferModule(config));
install(new P2PModule(config));
install(new BitcoinModule(config));
install(new DaoModule(config));
install(new AlertModule(config));
install(new FilterModule(config));
install(new CorePresentationModule(config));
bind(PubKeyRing.class).toProvider(PubKeyRingProvider.class);
}
}

View File

@ -18,7 +18,6 @@
package bisq.core.app.misc;
import bisq.core.alert.AlertModule;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.TorSetup;
import bisq.core.btc.BitcoinModule;
import bisq.core.dao.DaoModule;
@ -46,8 +45,6 @@ import bisq.common.crypto.PubKeyRingProvider;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import java.io.File;
@ -57,13 +54,12 @@ import static com.google.inject.name.Names.named;
public class ModuleForAppWithP2p extends AppModule {
public ModuleForAppWithP2p(Environment environment, Config config) {
super(environment, config);
public ModuleForAppWithP2p(Config config) {
super(config);
}
@Override
protected void configure() {
bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment);
bind(Config.class).toInstance(config);
bind(KeyStorage.class).in(Singleton.class);
@ -86,14 +82,14 @@ public class ModuleForAppWithP2p extends AppModule {
bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.getReferralId());
// ordering is used for shut down sequence
install(new TradeModule(environment, config));
install(new EncryptionServiceModule(environment, config));
install(new OfferModule(environment, config));
install(new P2PModule(environment, config));
install(new BitcoinModule(environment, config));
install(new DaoModule(environment, config));
install(new AlertModule(environment, config));
install(new FilterModule(environment, config));
install(new TradeModule(config));
install(new EncryptionServiceModule(config));
install(new OfferModule(config));
install(new P2PModule(config));
install(new BitcoinModule(config));
install(new DaoModule(config));
install(new AlertModule(config));
install(new FilterModule(config));
bind(PubKeyRing.class).toProvider(PubKeyRingProvider.class);
}
}

View File

@ -35,8 +35,6 @@ import bisq.core.provider.price.PriceFeedService;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
@ -52,8 +50,8 @@ import static com.google.inject.name.Names.named;
public class BitcoinModule extends AppModule {
public BitcoinModule(Environment environment, Config config) {
super(environment, config);
public BitcoinModule(Config config) {
super(config);
}
@Override

View File

@ -88,16 +88,14 @@ import bisq.core.dao.state.unconfirmed.UnconfirmedBsqChangeOutputListService;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import static com.google.inject.name.Names.named;
public class DaoModule extends AppModule {
public DaoModule(Environment environment, Config config) {
super(environment, config);
public DaoModule(Config config) {
super(config);
}
@Override

View File

@ -17,7 +17,6 @@
package bisq.core.dao.state.model.governance;
import bisq.core.app.BisqEnvironment;
import bisq.core.dao.governance.param.Param;
import bisq.core.dao.governance.proposal.IssuanceProposal;
import bisq.core.dao.governance.proposal.ProposalType;

View File

@ -20,8 +20,6 @@ package bisq.core.filter;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import static bisq.common.config.Config.IGNORE_DEV_MSG;
@ -29,8 +27,8 @@ import static com.google.inject.name.Names.named;
public class FilterModule extends AppModule {
public FilterModule(Environment environment, Config config) {
super(environment, config);
public FilterModule(Config config) {
super(config);
}
@Override

View File

@ -20,8 +20,6 @@ package bisq.core.offer;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
@ -29,8 +27,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class OfferModule extends AppModule {
public OfferModule(Environment environment, Config config) {
super(environment, config);
public OfferModule(Config config) {
super(config);
}
@Override

View File

@ -20,14 +20,12 @@ package bisq.core.presentation;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
public class CorePresentationModule extends AppModule {
public CorePresentationModule(Environment environment, Config config) {
super(environment, config);
public CorePresentationModule(Config config) {
super(config);
}
@Override

View File

@ -31,8 +31,6 @@ import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import static bisq.common.config.Config.DUMP_STATISTICS;
@ -40,8 +38,8 @@ import static com.google.inject.name.Names.named;
public class TradeModule extends AppModule {
public TradeModule(Environment environment, Config config) {
super(environment, config);
public TradeModule(Config config) {
super(config);
}
@Override

View File

@ -17,15 +17,12 @@
package bisq.core.util.coin;
import bisq.core.app.BisqEnvironment;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.MonetaryFormat;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,58 +0,0 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.app;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockPropertySource;
import org.junit.Test;
import static bisq.core.app.BisqEnvironment.*;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.springframework.core.env.PropertySource.named;
public class BisqEnvironmentTests {
@Test
public void testPropertySourcePrecedence() {
PropertySource commandlineProps = new MockPropertySource(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME)
.withProperty("key.x", "x.commandline");
ConfigurableEnvironment bisqEnvironment = new BisqEnvironment(commandlineProps);
MutablePropertySources propertySources = bisqEnvironment.getPropertySources();
assertThat(propertySources.precedenceOf(named(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(propertySources.precedenceOf(named(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(propertySources.precedenceOf(named(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(propertySources.precedenceOf(named(BISQ_DEFAULT_PROPERTY_SOURCE_NAME)), equalTo(3));
// we removed support for the rest
/* assertThat(propertySources.precedenceOf(named(BISQ_APP_DIR_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(propertySources.precedenceOf(named(BISQ_HOME_DIR_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(propertySources.precedenceOf(named(BISQ_CLASSPATH_PROPERTY_SOURCE_NAME)), equalTo(5));*/
assertThat(propertySources.size(), equalTo(4));
assertThat(bisqEnvironment.getProperty("key.x"), equalTo("x.commandline")); // commandline value wins due to precedence
//TODO check why it fails
//assertThat(bisqEnvironment.getProperty("key.y"), equalTo("y.bisqEnvironment")); // bisqEnvironment value wins because it's the only one available
}
}

View File

@ -75,7 +75,7 @@ public class BisqDaemonMain extends BisqHeadlessAppMain implements BisqSetup.Bis
@Override
protected AppModule getModule() {
return new CoreModule(bisqEnvironment, config);
return new CoreModule(config);
}
@Override

View File

@ -27,8 +27,6 @@ import bisq.core.locale.Res;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import com.google.inject.name.Names;
@ -38,9 +36,8 @@ import static bisq.common.config.Config.APP_NAME;
public class DesktopModule extends AppModule {
public DesktopModule(Environment environment, Config config) {
super(environment, config);
public DesktopModule(Config config) {
super(config);
}
@Override

View File

@ -104,7 +104,7 @@ public class BisqAppMain extends BisqExecutable {
@Override
protected AppModule getModule() {
return new BisqAppModule(bisqEnvironment, config);
return new BisqAppModule(config);
}
@Override

View File

@ -24,17 +24,15 @@ import bisq.core.app.CoreModule;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
public class BisqAppModule extends AppModule {
public BisqAppModule(Environment environment, Config config) {
super(environment, config);
public BisqAppModule(Config config) {
super(config);
}
@Override
protected void configure() {
install(new CoreModule(environment, config));
install(new DesktopModule(environment, config));
install(new CoreModule(config));
install(new DesktopModule(config));
}
}

View File

@ -21,7 +21,6 @@ import bisq.desktop.app.BisqAppMain;
import bisq.desktop.components.AutoTooltipToggleButton;
import bisq.desktop.main.overlays.Overlay;
import bisq.core.app.BisqEnvironment;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;

View File

@ -25,7 +25,6 @@ import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.GUIUtil;
import bisq.core.app.BisqEnvironment;
import bisq.core.locale.Res;
import bisq.core.user.DontShowAgainLookup;

View File

@ -24,7 +24,6 @@ import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.core.alert.Alert;
import bisq.core.app.BisqEnvironment;
import bisq.core.locale.Res;
import bisq.common.config.Config;

View File

@ -17,7 +17,6 @@ import bisq.desktop.main.presentation.MarketPricePresentation;
import bisq.desktop.util.Transitions;
import bisq.core.app.AvoidStandbyModeService;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.P2PNetworkSetup;
import bisq.core.app.TorSetup;
import bisq.core.app.WalletAppSetup;
@ -62,8 +61,6 @@ import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.CorruptedDatabaseFilesHandler;
import bisq.common.storage.Storage;
import org.springframework.mock.env.MockPropertySource;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -83,7 +80,7 @@ public class GuiceSetupTest {
Res.setup();
CurrencyUtil.setup();
injector = Guice.createInjector(new BisqAppModule(new BisqEnvironment(new MockPropertySource()), new TestConfig()));
injector = Guice.createInjector(new BisqAppModule(new TestConfig()));
}
@Test

View File

@ -4,7 +4,6 @@ import bisq.desktop.main.offer.MakerFeeProvider;
import bisq.desktop.util.validation.SecurityDepositValidator;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
@ -22,9 +21,7 @@ import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.coin.ImmutableCoinFormatter;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.InputValidator;
import org.bitcoinj.core.Coin;

View File

@ -20,14 +20,12 @@ package bisq.network.crypto;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
public class EncryptionServiceModule extends AppModule {
public EncryptionServiceModule(Environment environment, Config config) {
super(environment, config);
public EncryptionServiceModule(Config config) {
super(config);
}
@Override

View File

@ -35,8 +35,6 @@ import bisq.network.p2p.storage.persistence.ResourceDataStoreService;
import bisq.common.app.AppModule;
import bisq.common.config.Config;
import org.springframework.core.env.Environment;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
@ -53,8 +51,8 @@ import static com.google.inject.util.Providers.of;
public class P2PModule extends AppModule {
public P2PModule(Environment environment, Config config) {
super(environment, config);
public P2PModule(Config config) {
super(config);
}
@Override

View File

@ -17,8 +17,6 @@
package bisq.seednode;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.BisqExecutable;
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.app.misc.ModuleForAppWithP2p;
@ -86,7 +84,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
@Override
protected AppModule getModule() {
return new ModuleForAppWithP2p(bisqEnvironment, config);
return new ModuleForAppWithP2p(config);
}
@Override

View File

@ -1,6 +1,5 @@
package bisq.seednode;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.misc.AppSetupWithP2PAndDAO;
import bisq.core.app.misc.ModuleForAppWithP2p;
import bisq.core.locale.CurrencyUtil;
@ -8,8 +7,6 @@ import bisq.core.locale.Res;
import bisq.common.config.TestConfig;
import org.springframework.mock.env.MockPropertySource;
import com.google.inject.Guice;
import org.junit.Test;
@ -20,7 +17,7 @@ public class GuiceSetupTest {
Res.setup();
CurrencyUtil.setup();
ModuleForAppWithP2p module = new ModuleForAppWithP2p(new BisqEnvironment(new MockPropertySource()), new TestConfig());
ModuleForAppWithP2p module = new ModuleForAppWithP2p(new TestConfig());
Guice.createInjector(module).getInstance(AppSetupWithP2PAndDAO.class);
}
}

View File

@ -17,7 +17,6 @@
package bisq.statistics;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.app.misc.ModuleForAppWithP2p;
@ -81,7 +80,7 @@ public class StatisticsMain extends ExecutableForAppWithP2p {
@Override
protected AppModule getModule() {
return new ModuleForAppWithP2p(bisqEnvironment, config);
return new ModuleForAppWithP2p(config);
}
@Override