bisq/gui/src/main/java/io/bitsquare/app/BitsquareAppMain.java

154 lines
6.5 KiB
Java
Raw Normal View History

Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
/*
* This file is part of Bitsquare.
*
* Bitsquare 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.
*
* Bitsquare 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 Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
2015-04-06 22:46:27 +02:00
package io.bitsquare.app;
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
2015-03-06 00:39:02 +01:00
import io.bitsquare.BitsquareException;
import io.bitsquare.btc.BitcoinNetwork;
import io.bitsquare.btc.RegTestHost;
2015-03-20 00:08:43 +01:00
import io.bitsquare.p2p.BootstrapNodes;
import io.bitsquare.p2p.Node;
import io.bitsquare.util.joptsimple.EnumValueConverter;
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
import java.io.File;
2015-03-06 00:39:02 +01:00
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.vinumeris.updatefx.UpdateFX;
import joptsimple.OptionException;
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import static io.bitsquare.app.BitsquareEnvironment.*;
2015-03-20 00:08:43 +01:00
import static io.bitsquare.p2p.Node.*;
import static io.bitsquare.p2p.tomp2p.TomP2PModule.*;
import static java.util.Arrays.asList;
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
public class BitsquareAppMain extends BitsquareExecutable {
private static final Logger log = LoggerFactory.getLogger(BitsquareAppMain.class);
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
public static void main(String[] args) throws Exception {
// We don't want to do the full argument parsing here as that might easily change in update versions
// So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
OptionParser parser = new OptionParser();
2015-03-07 23:46:57 +01:00
parser.allowsUnrecognizedOptions();
parser.accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR))
.withRequiredArg();
parser.accepts(APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME))
.withRequiredArg();
OptionSet options;
try {
options = parser.parse(args);
} catch (OptionException ex) {
System.out.println("error: " + ex.getMessage());
System.out.println();
parser.printHelpOn(System.out);
System.exit(EXIT_FAILURE);
return;
}
2015-04-06 22:46:27 +02:00
BitsquareAppEnvironment bitsquareEnvironment = new BitsquareAppEnvironment(options);
String updatesDirectory = bitsquareEnvironment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY);
2015-03-14 09:43:10 +01:00
Logging.setup(Paths.get(bitsquareEnvironment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY), "bitsquare").toString());
2015-03-06 00:39:02 +01:00
// app dir need to be setup before UpdateFX bootstrap
initAppDir(updatesDirectory);
UpdateFX.bootstrap(BitsquareAppMain.class, new File(updatesDirectory).toPath(), args);
}
// That will be called from UpdateFX after updates are checked
public static void realMain(String[] args) throws Exception {
log.trace("realMain");
// For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
// In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
Thread.currentThread().setContextClassLoader(BitsquareAppMain.class.getClassLoader());
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
new BitsquareAppMain().execute(args);
}
2015-03-06 00:39:02 +01:00
private static void initAppDir(String appDir) {
Path dir = Paths.get(appDir);
if (Files.exists(dir)) {
if (!Files.isWritable(dir))
throw new BitsquareException("Application data directory '%s' is not writeable", dir);
else
return;
}
try {
Files.createDirectory(dir);
} catch (IOException ex) {
throw new BitsquareException(ex, "Application data directory '%s' could not be created", dir);
}
}
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
@Override
protected void customizeOptionParsing(OptionParser parser) {
parser.accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR))
.withRequiredArg();
parser.accepts(APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME))
.withRequiredArg();
parser.accepts(APP_DATA_DIR_KEY, description("Application data directory", DEFAULT_APP_DATA_DIR))
.withRequiredArg();
parser.acceptsAll(asList(APP_DATA_DIR_CLEAN_KEY, "clean"),
description("Clean application data directory", DEFAULT_APP_DATA_DIR_CLEAN))
.withRequiredArg()
.ofType(boolean.class);
parser.accepts(NAME_KEY, description("Name of this node", null))
.withRequiredArg();
parser.accepts(PORT_KEY, description("Port to listen on", Node.DEFAULT_PORT))
.withRequiredArg()
.ofType(int.class);
parser.accepts(USE_MANUAL_PORT_FORWARDING_KEY, description("Use manual port forwarding", false))
.withRequiredArg()
.ofType(boolean.class);
parser.accepts(BitcoinNetwork.KEY, description("", BitcoinNetwork.DEFAULT))
.withRequiredArg()
.ofType(BitcoinNetwork.class)
.withValuesConvertedBy(new EnumValueConverter(BitcoinNetwork.class));
parser.accepts(RegTestHost.KEY, description("", RegTestHost.DEFAULT))
.withRequiredArg()
.ofType(RegTestHost.class)
.withValuesConvertedBy(new EnumValueConverter(RegTestHost.class));
parser.accepts(BOOTSTRAP_NODE_NAME_KEY, description("", BootstrapNodes.DEFAULT.getName()))
.withRequiredArg();
parser.accepts(BOOTSTRAP_NODE_IP_KEY, description("", BootstrapNodes.DEFAULT.getIp()))
.withRequiredArg();
parser.accepts(BOOTSTRAP_NODE_PORT_KEY, description("", BootstrapNodes.DEFAULT.getPort()))
.withRequiredArg()
.ofType(int.class);
parser.accepts(NETWORK_INTERFACE_KEY, description("Network interface", null))
.withRequiredArg();
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
}
@Override
protected void doExecute(OptionSet options) {
2015-04-06 22:46:27 +02:00
BitsquareApp.setEnvironment(new BitsquareAppEnvironment(options));
Overhaul property management and main class infrastructure Use of the Spring Environment ----------------------------- This change replaces the use of the argparse4j library and basic Properties objects with the Spring Framework's Environment abstraction. The Environment allows for managing any number of 'property sources' in a hierarchical fashion, such that a call to `environment.getProperty("someKey")` iterates through an ordered set of property sources, returning the first value associated with the given key. BitsquareEnvironment, introduced in this commit, eliminates the functionality previously present in ConfigLoader, modeling the bitsquare.conf and bitsquare.properties files as Spring Resource objects, and in turn creating ResourcePropertySources out of them. These custom property sources are combined with standard property sources based on system environment variables and Java system properties as well as a property source based on the command-line arguments passed to a Bitsquare application to form a unified, one-stop configuration hierarchy. For example, let's say a Bitsquare user wishes to customize the port that his Bitsquare application listens on. The simplest approach (assuming the user is comfortable with the command line), would be the following: java -jar bitsquare.jar --port=1234 where '1234' is the custom port of choice. This is convenient enough for one-off experimentation, but if the user wishes to make this a permanent arrangement, he may want to add a `port=1234` entry to his {bitsquare_app_dir}/bitsquare.conf file. Alternatively, the user may wish to specify the port value as an environment variable, e.g.: PORT=1234 java -jar bitsquare.jar or with a JVM system property, e.g.: java -jar -DPORT=1234 bitsquare.jar With BitsquareEnvironment, and its customized set of PropertySources in place, the value of the port property may be specified in any of the ways described above, and it is all handled in a unified way. Restructuring of *Main classes ------------------------------ This commit also introduces significant changes to the structure of executable Bitsquare applications. For example, prior to this change, the io.bitsquare.app.gui.Main class was responsible for being both a JavaFX Application and a standard Java main class. Now, however, these concerns have been renamed and separated. BitsquareApp is the JavaFX Application, and BitsquareAppMain is the Java main class. Likewise, BootstrapNode has been broken out into BootstrapNode and BootstrapNodeMain. A common base class for the *Main classes has been extracted, named BitsquareExecutable, which creates a template for option parsing, environment creation, and ultimately application execution that applies both to the BootstrapNode and BitsquareApp cases. Improved help text ------------------ With the removal of argparse4j and the introduction of JOpt for argument parsing, the application's help text has been improved. Use --help to display this text, where you'll see information about default values, etc. To do this easily from the Gradle build, run any of the following commands: # Display help text ./gradlew run -Pargs="--help" # Qualify the application name as "Bitsquare-Alice" ./gradlew run -Pargs="--appName=Alice" # Customize the port ./gradlew run -Pargs="--port=7377" Renaming of FatalException -------------------------- Finally, the exception formerly known as io.bitsquare.gui.FatalException has been moved up a package and generalized to io.bitsquare.BitsquareException, as it is now used more widely.
2014-11-10 15:48:27 +01:00
javafx.application.Application.launch(BitsquareApp.class);
}
}