Skip to content

Commit 01399ff

Browse files
committed
server: Loading option descriptions from JSON file instead of Properties, this allows to manage order of options in the help message
1 parent ea6e0da commit 01399ff

File tree

5 files changed

+82
-69
lines changed

5 files changed

+82
-69
lines changed

Diff for: java/server/src/org/openqa/grid/common/GridDocHelper.java

+53-38
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,66 @@
1717

1818
package org.openqa.grid.common;
1919

20+
import com.google.gson.JsonArray;
21+
import com.google.gson.JsonElement;
22+
import com.google.gson.JsonIOException;
23+
import com.google.gson.JsonParser;
24+
2025
import org.openqa.selenium.server.cli.RemoteControlLauncher;
2126

22-
import java.io.IOException;
2327
import java.io.InputStream;
24-
import java.util.Properties;
28+
import java.io.InputStreamReader;
29+
import java.util.ArrayList;
30+
import java.util.HashMap;
31+
import java.util.List;
32+
import java.util.Map;
2533

2634

2735
public class GridDocHelper {
28-
private static Properties hubProperties = load(
29-
"org/openqa/grid/common/defaults/HubParameters.properties");
30-
private static Properties nodeProperties = load(
31-
"org/openqa/grid/common/defaults/NodeParameters.properties");
36+
private static List<Option> hubOptions = load(
37+
"org/openqa/grid/common/defaults/HubOptions.json");
38+
private static List<Option> nodeOptions = load(
39+
"org/openqa/grid/common/defaults/NodeOptions.json");
3240

3341
public static void printHubHelp(String msg) {
3442
printHubHelp(msg, true);
3543
}
3644

3745
public static void printHubHelp(String msg, boolean error) {
38-
printHelpInConsole(msg, "hub", hubProperties, error);
46+
printHelpInConsole(msg, "hub", hubOptions, error);
3947
RemoteControlLauncher.printWrappedLine(
4048
"",
41-
"This synopsis lists options available in hub role only. To get help on the command line options available for other roles run the server with -help option and the corresponding -role option value.");
49+
"This synopsis lists options available in hub role only. To get help on the command line options available for other roles run the server with -help name and the corresponding -role name value.");
4250
}
4351

4452
public static void printNodeHelp(String msg) {
4553
printNodeHelp(msg, true);
4654
}
4755

4856
public static void printNodeHelp(String msg, boolean error) {
49-
printHelpInConsole(msg, "node", nodeProperties, error);
57+
printHelpInConsole(msg, "node", nodeOptions, error);
5058
RemoteControlLauncher.printWrappedLine(
5159
"",
52-
"This synopsis lists options available in node role only. To get help on the command line options available for other roles run the server with -help option and the corresponding -role option value.");
60+
"This synopsis lists options available in node role only. To get help on the command line options available for other roles run the server with -help name and the corresponding -role name value.");
5361
}
5462

55-
private static String getParam(Properties properties, String param) {
56-
if (param == null) {
57-
return "";
63+
private static Map<String, String> hubOptionsMap;
64+
65+
public static String getHubParam(String param) {
66+
if (hubOptionsMap == null) {
67+
hubOptionsMap = new HashMap<String, String>();
68+
for (Option option : hubOptions) {
69+
hubOptionsMap.put(option.name, option.description);
70+
}
5871
}
59-
String s = (String) properties.get(param);
60-
if (s == null) {
61-
return "No help specified for " + param;
72+
if (hubOptionsMap.containsKey(param)) {
73+
return hubOptionsMap.get(param);
6274
} else {
63-
return s;
75+
return "No help specified for " + param;
6476
}
6577
}
6678

67-
public static String getHubParam(String param) {
68-
return getParam(hubProperties, param);
69-
}
70-
71-
public static String getNodeParam(String param) {
72-
return getParam(nodeProperties, param);
73-
}
74-
75-
private static void printHelpInConsole(String msg, String role, Properties properties, boolean error) {
79+
private static void printHelpInConsole(String msg, String role, List<Option> options, boolean error) {
7680
String indent = " ";
7781
String indent2x = indent + indent;
7882
if (msg != null) {
@@ -84,25 +88,36 @@ private static void printHelpInConsole(String msg, String role, Properties prope
8488
}
8589

8690
System.out.println("Usage: java -jar selenium-server.jar -role " + role + " [options]\n");
87-
for (Object key : properties.keySet()) {
88-
System.out.println(indent + "-" + key + ":");
89-
RemoteControlLauncher.printWrappedLine(System.out, indent2x, getParam(properties, key.toString()), true);
91+
for (Option option : options) {
92+
System.out.println(indent + "-" + option.name + ":");
93+
RemoteControlLauncher.printWrappedLine(System.out, indent2x, option.description, true);
9094
System.out.println("");
9195
}
9296
}
9397

94-
private static Properties load(String resource) {
98+
private static List<Option> load(String resource) {
9599
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
96-
Properties p = new Properties();
97-
if (in != null) {
98-
try {
99-
p.load(in);
100-
return p;
101-
} catch (IOException e) {
102-
throw new RuntimeException(resource + " cannot be loaded.");
100+
List<Option> result = new ArrayList<Option>();
101+
try {
102+
JsonElement json = new JsonParser().parse(new InputStreamReader(in));
103+
for (JsonElement element : json.getAsJsonArray()) {
104+
JsonArray arr = element.getAsJsonArray();
105+
result.add(new Option(arr.get(0).getAsString(), arr.get(1).getAsString()));
103106
}
104-
} else {
107+
108+
} catch (JsonIOException e) {
105109
throw new RuntimeException(resource + " cannot be loaded.");
106110
}
111+
return result;
112+
}
113+
114+
private static class Option {
115+
private final String name;
116+
private final String description;
117+
118+
public Option(String option, String description) {
119+
this.name = option;
120+
this.description = description;
121+
}
107122
}
108123
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
["host", "<IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary."],
3+
["port", "<xxxx> : the port the remote/hub will listen on. Default to 4444."],
4+
["throwOnCapabilityNotPresent", "<true | false> default to true. If true, the hub will reject test requests right away if no proxy is currently registered that can host that capability.Set it to false to have the request queued until a node supporting the capability is added to the grid."],
5+
["newSessionWaitTimeout", "<XXXX>. Default to no timeout ( -1 ) the time in ms after which a new test waiting for a node to become available will time out.When that happens, the test will throw an exception before starting a browser."],
6+
["capabilityMatcher", "a class implementing the CapabilityMatcher interface. Defaults to org.openqa.grid.internal.utils.DefaultCapabilityMatcher. Specify the logic the hub will follow to define if a request can be assigned to a node.Change this class if you want to have the matching process use regular expression instead of exact match for the version of the browser for instance. All the nodes of a grid instance will use the same matcher, defined by the registry."],
7+
["prioritizer", "a class implementing the Prioritizer interface. Default to null ( no priority = FIFO ).Specify a custom prioritizer if you need the grid to process the tests from the CI, or the IE tests first for instance."],
8+
["servlets", "<com.mycompany.MyServlet,com.mycompany.MyServlet2> to register a new servlet on the hub/node. The servlet will accessible under the path /grid/admin/MyServlet /grid/admin/MyServlet2"],
9+
["grid1Yml", "a YML file following grid1 format."],
10+
["hubConfig", "a JSON file following grid2 format that defines the hub properties."],
11+
["browserTimeout", "The timeout in seconds a browser can hang"]
12+
]

Diff for: java/server/src/org/openqa/grid/common/defaults/HubParameters.properties

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
["host", "<IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary."],
3+
["port", "<xxxx> : the port the remote/hub will listen on. Default to 4444."],
4+
["cleanupCycle", "<XXXX> in ms. How often a proxy will check for timed out thread."],
5+
["timeout", "<XXXX> the timeout in seconds before the hub automatically ends a test that hasn't had any activity in the last X seconds. The browser will be released for another test to use. This typically takes care of the client crashes."],
6+
["browserTimeout", "The timeout in seconds a browser can hang"],
7+
["hub", "<http://localhost:4444/grid/register> : the url that will be used to post the registration request. This option takes precedence over -hubHost and -hubPort options."],
8+
["hubHost", "<IP | hostname> : the host address of a hub the registration request should be sent to. Default to localhost. Option -hub takes precedence over this option."],
9+
["hubPort", "<xxxx> : the port listened by a hub the registration request should be sent to. Default to 4444. Option -hub takes precedence over this option."],
10+
["proxy", "the class that will be used to represent the node. By default org.openqa.grid.selenium.proxy.DefaultRemoteProxy."],
11+
["maxSession", "max number of tests that can run at the same time on the node, independently of the browser used."],
12+
["registerCycle", "how often in ms the node will try to register itself again.Allow to restart the hub without having to restart the nodes."],
13+
["nodePolling", "in ms. Interval between alive checks of node how often the hub checks if the node is still alive."],
14+
["unregisterIfStillDownAfter", "in ms. If the node remains down for more than unregisterIfStillDownAfter millisec, it will disappear from the hub.Default is 1min."],
15+
["downPollingLimit", "node is marked as down after downPollingLimit alive checks."],
16+
["nodeStatusCheckTimeout", "in ms. Connection and socket timeout which is used for node alive check."]
17+
]

Diff for: java/server/src/org/openqa/grid/common/defaults/NodeParameters.properties

-18
This file was deleted.

0 commit comments

Comments
 (0)