41
41
import org .exist .start .Main ;
42
42
import org .exist .start .StartException ;
43
43
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 .*;
47
45
import org .exist .validation .XmlLibraryChecker ;
48
46
import org .exist .xmldb .DatabaseImpl ;
49
47
import org .exist .xmldb .ShutdownListener ;
50
48
import org .xmldb .api .DatabaseManager ;
51
49
import org .xmldb .api .base .Database ;
50
+ import se .softhouse .jargo .Argument ;
51
+ import se .softhouse .jargo .ArgumentException ;
52
+ import se .softhouse .jargo .CommandLineParser ;
52
53
53
54
import java .io .IOException ;
54
55
import java .io .LineNumberReader ;
61
62
import java .util .stream .Collectors ;
62
63
63
64
import static org .exist .util .ThreadUtils .newGlobalThread ;
65
+ import static se .softhouse .jargo .Arguments .helpArgument ;
66
+ import static se .softhouse .jargo .Arguments .stringArgument ;
64
67
65
68
/**
66
69
* 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 {
85
88
private final static int STATUS_STOPPING = 2 ;
86
89
private final static int STATUS_STOPPED = 3 ;
87
90
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
+
88
100
@ GuardedBy ("this" ) private int status = STATUS_STOPPED ;
89
101
@ GuardedBy ("this" ) private Optional <Thread > shutdownHookThread = Optional .empty ();
90
102
@ GuardedBy ("this" ) private int primaryPort = 8080 ;
@@ -93,11 +105,21 @@ public class JettyStart extends Observable implements LifeCycle.Listener {
93
105
public static void main (final String [] args ) {
94
106
try {
95
107
CompatibleJavaVersionCheck .checkForCompatibleJavaVersion ();
108
+
109
+ CommandLineParser
110
+ .withArguments (jettyConfigFilePath , existConfigFilePath )
111
+ .andArguments (helpArg )
112
+ .programName ("startup" + (OSUtil .isWindows () ? ".bat" : ".sh" ))
113
+ .parse (args );
114
+
96
115
} catch (final StartException e ) {
97
116
if (e .getMessage () != null && !e .getMessage ().isEmpty ()) {
98
117
System .err .println (e .getMessage ());
99
118
}
100
119
System .exit (e .getErrorCode ());
120
+ } catch (final ArgumentException e ) {
121
+ consoleOut (e .getMessageAndUsage ().toString ());
122
+ System .exit (SystemExitCodes .INVALID_ARGUMENT_EXIT_CODE );
101
123
}
102
124
103
125
final JettyStart start = new JettyStart ();
@@ -109,6 +131,10 @@ public JettyStart() {
109
131
XmlLibraryChecker .check ();
110
132
}
111
133
134
+ private static void consoleOut (final String msg ) {
135
+ System .out .println (msg ); //NOSONAR this has to go to the console
136
+ }
137
+
112
138
public synchronized void run () {
113
139
run (true );
114
140
}
0 commit comments