Skip to content

Commit 4f1eada

Browse files
authored
Merge pull request #4772 from evolvedbinary/hotfix/existdb-args
Fix some issues with CLI args
2 parents 1eaa076 + 95fc259 commit 4f1eada

File tree

11 files changed

+136
-9
lines changed

11 files changed

+136
-9
lines changed

exist-core/src/main/java/org/exist/backup/ExportGUI.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
import org.exist.util.Configuration;
3232
import org.exist.util.MimeTable;
3333
import org.exist.util.MimeType;
34+
import org.exist.util.OSUtil;
3435
import org.exist.util.SystemExitCodes;
3536
import org.exist.xquery.TerminatedException;
37+
import se.softhouse.jargo.Argument;
38+
import se.softhouse.jargo.ArgumentException;
39+
import se.softhouse.jargo.CommandLineParser;
3640

3741
import javax.swing.*;
3842
import javax.swing.filechooser.FileFilter;
@@ -48,6 +52,7 @@
4852
import static java.nio.charset.StandardCharsets.UTF_8;
4953
import static org.exist.util.ThreadUtils.newGlobalThread;
5054
import static org.exist.util.ThreadUtils.newInstanceThread;
55+
import static se.softhouse.jargo.Arguments.helpArgument;
5156

5257

5358
/**
@@ -58,6 +63,9 @@
5863
public class ExportGUI extends javax.swing.JFrame {
5964
private static final long serialVersionUID = -8104424554660744639L;
6065

66+
/* general arguments */
67+
private static final Argument<?> helpArg = helpArgument("-h", "--help");
68+
6169
private BrokerPool pool = null;
6270
private int documentCount = 0;
6371
private PrintWriter logWriter = null;
@@ -613,13 +621,27 @@ private void closeLog() {
613621
public static void main(final String[] args) {
614622
try {
615623
CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
624+
625+
// parse command-line options
626+
CommandLineParser
627+
.withArguments(helpArg)
628+
.programName("export-gui" + (OSUtil.isWindows() ? ".bat" : ".sh"))
629+
.parse(args);
630+
616631
} catch (final StartException e) {
617632
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
618633
System.err.println(e.getMessage());
619634
}
620635
System.exit(e.getErrorCode());
636+
} catch (final ArgumentException e) {
637+
consoleOut(e.getMessageAndUsage().toString());
638+
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
621639
}
622640

623641
java.awt.EventQueue.invokeLater(() -> new ExportGUI().setVisible(true));
624642
}
643+
644+
private static void consoleOut(final String msg) {
645+
System.out.println(msg); //NOSONAR this has to go to the console
646+
}
625647
}

exist-core/src/main/java/org/exist/backup/ExportMain.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.exist.storage.txn.Txn;
3131
import org.exist.util.Configuration;
3232
import org.exist.util.DatabaseConfigurationException;
33+
import org.exist.util.OSUtil;
3334
import org.exist.util.SystemExitCodes;
3435
import org.exist.xquery.TerminatedException;
3536
import se.softhouse.jargo.Argument;
@@ -130,6 +131,7 @@ public static void main(final String[] args) {
130131
.withArguments(noCheckArg, checkDocsArg, directAccessArg, exportArg, noExportArg, incrementalArg, zipArg, noZipArg)
131132
.andArguments(configArg, outputDirArg)
132133
.andArguments(helpArg, verboseArg)
134+
.programName("export" + (OSUtil.isWindows() ? ".bat" : ".sh"))
133135
.parse(args);
134136

135137
process(arguments);

exist-core/src/main/java/org/exist/backup/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.exist.start.StartException;
2727
import org.exist.util.ConfigurationHelper;
2828
import org.exist.util.NamedThreadFactory;
29+
import org.exist.util.OSUtil;
2930
import org.exist.util.SystemExitCodes;
3031
import org.exist.xmldb.*;
3132
import org.xmldb.api.DatabaseManager;
@@ -461,6 +462,7 @@ public static void main(final String[] args) {
461462
.andArguments(backupCollectionArg, backupOutputDirArg, backupDeduplicateBlobs)
462463
.andArguments(restoreArg, rebuildExpathRepoArg, overwriteAppsArg)
463464
.andArguments(helpArg, guiArg, quietArg, optionArg)
465+
.programName("backup" + (OSUtil.isWindows() ? ".bat" : ".sh"))
464466
.parse(args);
465467

466468
process(arguments);

exist-core/src/main/java/org/exist/client/CommandlineOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.nio.file.Path;
2727
import java.util.*;
2828

29+
import org.exist.util.OSUtil;
2930
import org.exist.xmldb.XmldbURI;
3031
import org.exist.xquery.util.URIUtils;
3132
import se.softhouse.jargo.*;
@@ -176,6 +177,7 @@ public static CommandlineOptions parse(final String[] args) throws ArgumentExcep
176177
.andArguments(setDocArg, xupdateArg)
177178
.andArguments(reindexArg, reindexRecurseDirsArg)
178179
.andArguments(helpArg, quietArg, verboseArg, outputFileArg, optionArg)
180+
.programName("client" + (OSUtil.isWindows() ? ".bat" : ".sh"))
179181
.parse(args);
180182

181183
final boolean quiet = getBool(arguments, quietArg);

exist-core/src/main/java/org/exist/jetty/JettyStart.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
import org.exist.start.Main;
4242
import org.exist.start.StartException;
4343
import org.exist.storage.BrokerPool;
44-
import org.exist.util.ConfigurationHelper;
45-
import org.exist.util.FileUtils;
46-
import org.exist.util.SingleInstanceConfiguration;
44+
import org.exist.util.*;
4745
import org.exist.validation.XmlLibraryChecker;
4846
import org.exist.xmldb.DatabaseImpl;
4947
import org.exist.xmldb.ShutdownListener;
5048
import org.xmldb.api.DatabaseManager;
5149
import org.xmldb.api.base.Database;
50+
import se.softhouse.jargo.Argument;
51+
import se.softhouse.jargo.ArgumentException;
52+
import se.softhouse.jargo.CommandLineParser;
5253

5354
import java.io.IOException;
5455
import java.io.LineNumberReader;
@@ -61,6 +62,8 @@
6162
import java.util.stream.Collectors;
6263

6364
import static org.exist.util.ThreadUtils.newGlobalThread;
65+
import static se.softhouse.jargo.Arguments.helpArgument;
66+
import static se.softhouse.jargo.Arguments.stringArgument;
6467

6568
/**
6669
* This class provides a main method to start Jetty with eXist. It registers shutdown
@@ -85,6 +88,15 @@ public class JettyStart extends Observable implements LifeCycle.Listener {
8588
private final static int STATUS_STOPPING = 2;
8689
private final static int STATUS_STOPPED = 3;
8790

91+
/* general arguments */
92+
private static final Argument<String> jettyConfigFilePath = stringArgument()
93+
.description("Path to Jetty Config File")
94+
.build();
95+
private static final Argument<String> existConfigFilePath = stringArgument()
96+
.description("Path to eXist-db Config File")
97+
.build();
98+
private static final Argument<?> helpArg = helpArgument("-h", "--help");
99+
88100
@GuardedBy("this") private int status = STATUS_STOPPED;
89101
@GuardedBy("this") private Optional<Thread> shutdownHookThread = Optional.empty();
90102
@GuardedBy("this") private int primaryPort = 8080;
@@ -93,11 +105,21 @@ public class JettyStart extends Observable implements LifeCycle.Listener {
93105
public static void main(final String[] args) {
94106
try {
95107
CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
108+
109+
CommandLineParser
110+
.withArguments(jettyConfigFilePath, existConfigFilePath)
111+
.andArguments(helpArg)
112+
.programName("startup" + (OSUtil.isWindows() ? ".bat" : ".sh"))
113+
.parse(args);
114+
96115
} catch (final StartException e) {
97116
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
98117
System.err.println(e.getMessage());
99118
}
100119
System.exit(e.getErrorCode());
120+
} catch (final ArgumentException e) {
121+
consoleOut(e.getMessageAndUsage().toString());
122+
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
101123
}
102124

103125
final JettyStart start = new JettyStart();
@@ -109,6 +131,10 @@ public JettyStart() {
109131
XmlLibraryChecker.check();
110132
}
111133

134+
private static void consoleOut(final String msg) {
135+
System.out.println(msg); //NOSONAR this has to go to the console
136+
}
137+
112138
public synchronized void run() {
113139
run(true);
114140
}

exist-core/src/main/java/org/exist/jetty/ServerShutdown.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.exist.start.CompatibleJavaVersionCheck;
2727
import org.exist.start.StartException;
2828
import org.exist.util.ConfigurationHelper;
29+
import org.exist.util.OSUtil;
2930
import org.exist.util.SystemExitCodes;
3031
import org.exist.xmldb.DatabaseInstanceManager;
3132
import org.exist.xmldb.XmldbURI;
@@ -77,6 +78,7 @@ public static void main(final String[] args) {
7778
final ParsedArguments arguments = CommandLineParser
7879
.withArguments(userArg, passwordArg, uriArg)
7980
.andArguments(helpArg)
81+
.programName("shutdown" + (OSUtil.isWindows() ? ".bat" : ".sh"))
8082
.parse(args);
8183

8284
process(arguments);

exist-core/src/main/java/org/exist/launcher/LauncherWrapper.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import org.exist.start.CompatibleJavaVersionCheck;
2525
import org.exist.start.StartException;
2626
import org.exist.util.ConfigurationHelper;
27+
import org.exist.util.OSUtil;
28+
import org.exist.util.SystemExitCodes;
29+
import se.softhouse.jargo.Argument;
30+
import se.softhouse.jargo.ArgumentException;
31+
import se.softhouse.jargo.CommandLineParser;
2732

2833
import javax.swing.*;
2934
import java.io.File;
@@ -37,6 +42,7 @@
3742

3843
import static java.nio.charset.StandardCharsets.UTF_8;
3944
import static org.exist.launcher.ConfigurationUtility.*;
45+
import static se.softhouse.jargo.Arguments.helpArgument;
4046

4147
/**
4248
* A wrapper to start a Java process using start.jar with correct VM settings.
@@ -48,17 +54,30 @@
4854
*/
4955
public class LauncherWrapper {
5056

51-
private final static String LAUNCHER = org.exist.launcher.Launcher.class.getName();
52-
private final static String OS = System.getProperty("os.name").toLowerCase();
57+
private static final String LAUNCHER = org.exist.launcher.Launcher.class.getName();
58+
private static final String OS = OSUtil.getOS().toLowerCase();
59+
60+
/* general arguments */
61+
private static final Argument<?> helpArg = helpArgument("-h", "--help");
5362

5463
public final static void main(final String[] args) {
5564
try {
5665
CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
66+
67+
// parse command-line options
68+
CommandLineParser
69+
.withArguments(helpArg)
70+
.programName("launcher" + (OSUtil.isWindows() ? ".bat" : ".sh"))
71+
.parse(args);
72+
5773
} catch (final StartException e) {
5874
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
5975
System.err.println(e.getMessage());
6076
}
6177
System.exit(e.getErrorCode());
78+
} catch (final ArgumentException e) {
79+
consoleOut(e.getMessageAndUsage().toString());
80+
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
6281
}
6382

6483
final LauncherWrapper wrapper = new LauncherWrapper(LAUNCHER);
@@ -203,4 +222,8 @@ protected void getLauncherOpts(final List<String> args, final Properties launche
203222
}
204223
}
205224
}
225+
226+
private static void consoleOut(final String msg) {
227+
System.out.println(msg); //NOSONAR this has to go to the console
228+
}
206229
}

exist-core/src/main/java/org/exist/management/client/JMXClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.exist.start.CompatibleJavaVersionCheck;
2525
import org.exist.start.StartException;
26+
import org.exist.util.OSUtil;
2627
import org.exist.util.SystemExitCodes;
2728
import se.softhouse.jargo.Argument;
2829
import se.softhouse.jargo.ArgumentException;
@@ -256,17 +257,14 @@ private void error(Exception e) {
256257
/* connection arguments */
257258
private static final Argument<String> addressArg = stringArgument("-a", "--address")
258259
.description("RMI address of the server")
259-
.required()
260260
.defaultValue("localhost")
261261
.build();
262262
private static final Argument<Integer> portArg = integerArgument("-p", "--port")
263263
.description("RMI port of the server")
264-
.required()
265264
.defaultValue(DEFAULT_PORT)
266265
.build();
267266
private static final Argument<String> instanceArg = stringArgument("-i", "--instance")
268267
.description("The ID of the database instance to connect to")
269-
.required()
270268
.defaultValue("exist")
271269
.build();
272270
private static final Argument<Integer> waitArg = integerArgument("-w", "--wait")
@@ -317,6 +315,7 @@ public static void main(final String[] args) {
317315
.andArguments(cacheDisplayArg, locksDisplayArg)
318316
.andArguments(dbInfoArg, memoryInfoArg, sanityCheckInfoArg, jobsInfoArg)
319317
.andArguments(helpArg)
318+
.programName("jmxclient" + (OSUtil.isWindows() ? ".bat" : ".sh"))
320319
.parse(args);
321320

322321
process(arguments);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist.util;
23+
24+
public interface OSUtil {
25+
26+
/**
27+
* Return true if the Operating System is Microsoft Windows.
28+
*
29+
* @return true if the OS is Windows.
30+
*/
31+
static boolean isWindows() {
32+
return getOS().toLowerCase().contains("win");
33+
}
34+
35+
/**
36+
* Return the OS name from the `os.name` System Property.
37+
*
38+
* @return the OS name or "unknown".
39+
*/
40+
static String getOS() {
41+
return System.getProperty("os.name", "unknown");
42+
}
43+
}

exist-distribution/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,9 @@
871871
<daemon>
872872
<id>launcher</id>
873873
<mainClass>org.exist.start.Main</mainClass>
874-
<!-- No arguments needed! Default is to start the launcher -->
874+
<commandLineArguments>
875+
<commandLineArgument>launcher</commandLineArgument>
876+
</commandLineArguments>
875877
<platforms>
876878
<platform>booter-unix</platform>
877879
<platform>booter-windows</platform>

0 commit comments

Comments
 (0)