Skip to content

Commit

Permalink
server: added support of property settings (can use launcher to setup…
Browse files Browse the repository at this point in the history
… params like -Dxmage.testMode=true)
  • Loading branch information
JayDi85 committed Sep 17, 2023
1 parent bcea598 commit c515ff3
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions Mage.Server/src/main/java/mage/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public final class Main {
private static final Logger logger = Logger.getLogger(Main.class);
private static final MageVersion version = new MageVersion(Main.class);

// arg settings can be setup by run script or IDE's program arguments like -xxx=yyy
// prop settings can be setup by -Dxxx=yyy in the launcher
// priority: default setting -> prop setting -> arg setting
private static final String testModeArg = "-testMode=";
private static final String fastDBModeArg = "-fastDbMode=";
private static final String testModeProp = "xmage.testMode";

This comment has been minimized.

Copy link
@Susucre

Susucre Sep 17, 2023

Contributor

@JayDi85 I did test locally just now with the launcher at 0.4.0 from the git repo. It is working that way. Should we just update the launcher delivered with the .zip?

This comment has been minimized.

Copy link
@JayDi85

JayDi85 Sep 17, 2023

Author Member

Yes, I'll update launcher with some of the release.

private static final String fastDBModeArg = "-fastDbMode="; // TODO: outdated, must be deleted
private static final String adminPasswordArg = "-adminPassword=";
/**
* The property that holds the path to the configuration file. Defaults to "config/config.xml".
* <p>
* To set up a different one, start the application with the java option "-Dxmage.config.path=&lt;path&gt;"
*/
private static final String adminPasswordProp = "xmage.adminPassword";
private static final String configPathProp = "xmage.config.path";

private static final File pluginFolder = new File("plugins");
Expand Down Expand Up @@ -91,6 +91,21 @@ public static void main(String[] args) {
// enable test mode by default for developer build (if you run it from source code)
testMode |= version.isDeveloperBuild();

// settings by properties (-Dxxx=yyy from a launcher)
if (System.getProperty(testModeProp) != null) {
testMode = Boolean.parseBoolean(System.getProperty(testModeProp));
}
if (System.getProperty(adminPasswordProp) != null) {
adminPassword = SystemUtil.sanitize(System.getProperty(adminPasswordProp));
}
final String configPath;
if (System.getProperty(configPathProp) != null) {
configPath = System.getProperty(configPathProp);
} else {
configPath = defaultConfigPath;
}

// settings by program arguments (-xxx=yyy from a command line)
for (String arg : args) {
if (arg.startsWith(testModeArg)) {
testMode = Boolean.parseBoolean(arg.replace(testModeArg, ""));
Expand All @@ -102,9 +117,6 @@ public static void main(String[] args) {
}
}

final String configPath = Optional.ofNullable(System.getProperty(configPathProp))
.orElse(defaultConfigPath);

logger.info(String.format("Reading configuration from path=%s", configPath));
final ConfigWrapper config = new ConfigWrapper(ConfigFactory.loadFromFile(configPath));

Expand Down

0 comments on commit c515ff3

Please sign in to comment.