41
41
import java .lang .reflect .Method ;
42
42
import java .util .HashMap ;
43
43
import java .util .Map ;
44
- import java .util .function .Supplier ;
44
+ import java .util .function .Function ;
45
45
import java .util .logging .ConsoleHandler ;
46
46
import java .util .logging .FileHandler ;
47
47
import java .util .logging .Handler ;
@@ -58,13 +58,12 @@ public class GridLauncherV3 {
58
58
private static final BuildInfo buildInfo = new BuildInfo ();
59
59
60
60
private interface GridItemLauncher {
61
- void setConfiguration (String [] args );
62
61
StandaloneConfiguration getConfiguration ();
63
62
void launch () throws Exception ;
64
63
default void printUsage () { new JCommander (getConfiguration ()).usage (); }
65
64
}
66
65
67
- private static ImmutableMap <String , Supplier < GridItemLauncher >> LAUNCHERS = buildLaunchers ();
66
+ private static Map <String , Function < String [], GridItemLauncher >> LAUNCHERS = buildLaunchers ();
68
67
69
68
public static void main (String [] args ) throws Exception {
70
69
GridItemLauncher launcher = buildLauncher (args );
@@ -96,7 +95,7 @@ private static GridItemLauncher buildLauncher(String[] args) {
96
95
97
96
for (int i = 0 ; i < args .length ; i ++) {
98
97
if (args [i ].equals ("-htmlSuite" )) {
99
- Supplier < GridItemLauncher > launcherSupplier = LAUNCHERS .get ("corerunner" );
98
+ Function < String [], GridItemLauncher > launcherSupplier = LAUNCHERS .get ("corerunner" );
100
99
if (launcherSupplier == null ) {
101
100
System .err .println (Joiner .on ("\n " ).join (
102
101
"Unable to find the HTML runner. This is normally because you have not downloaded" ,
@@ -107,9 +106,7 @@ private static GridItemLauncher buildLauncher(String[] args) {
107
106
"running your HTML suite." ));
108
107
return null ;
109
108
}
110
- GridItemLauncher launcher = launcherSupplier .get ();
111
- launcher .setConfiguration (args );
112
- return launcher ;
109
+ return launcherSupplier .apply (args );
113
110
}
114
111
if (args [i ].startsWith ("-role=" )) {
115
112
role = args [i ].substring ("-role=" .length ());
@@ -129,13 +126,12 @@ private static GridItemLauncher buildLauncher(String[] args) {
129
126
return null ;
130
127
}
131
128
132
- Supplier < GridItemLauncher > supplier = LAUNCHERS .get (gridRole .toString ());
129
+ Function < String [], GridItemLauncher > supplier = LAUNCHERS .get (gridRole .toString ());
133
130
if (supplier == null ) {
134
131
System .err .println ("Unknown role: " + gridRole );
135
132
return null ;
136
133
}
137
- GridItemLauncher toReturn = supplier .get ();
138
- toReturn .setConfiguration (args );
134
+ GridItemLauncher toReturn = supplier .apply (args );
139
135
140
136
if (toReturn .getConfiguration ().help ) {
141
137
toReturn .printUsage ();
@@ -239,18 +235,17 @@ private static void configureLogging(StandaloneConfiguration configuration) {
239
235
}
240
236
}
241
237
242
- private static ImmutableMap <String , Supplier < GridItemLauncher >> buildLaunchers () {
243
- ImmutableMap .Builder <String , Supplier < GridItemLauncher >> launchers =
244
- ImmutableMap .<String , Supplier < GridItemLauncher >>builder ()
245
- .put (GridRole .NOT_GRID .toString (), () -> new GridItemLauncher () {
246
- StandaloneConfiguration configuration ;
247
- public StandaloneConfiguration getConfiguration () {
248
- return configuration ;
238
+ private static Map <String , Function < String [], GridItemLauncher >> buildLaunchers () {
239
+ ImmutableMap .Builder <String , Function < String [], GridItemLauncher >> launchers =
240
+ ImmutableMap .<String , Function < String [], GridItemLauncher >>builder ()
241
+ .put (GridRole .NOT_GRID .toString (), (args ) -> new GridItemLauncher () {
242
+ StandaloneConfiguration configuration = new StandaloneConfiguration () ;
243
+ {
244
+ JCommander . newBuilder (). addObject ( configuration ). build (). parse ( args ) ;
249
245
}
250
246
251
- public void setConfiguration (String [] args ) {
252
- configuration = new StandaloneConfiguration ();
253
- JCommander .newBuilder ().addObject (configuration ).build ().parse (args );
247
+ public StandaloneConfiguration getConfiguration () {
248
+ return configuration ;
254
249
}
255
250
256
251
public void launch () throws Exception {
@@ -263,13 +258,9 @@ public void launch() throws Exception {
263
258
server .boot ();
264
259
}
265
260
})
266
- .put (GridRole .HUB .toString (), () -> new GridItemLauncher () {
261
+ .put (GridRole .HUB .toString (), (args ) -> new GridItemLauncher () {
267
262
GridHubConfiguration configuration ;
268
- public StandaloneConfiguration getConfiguration () {
269
- return configuration ;
270
- }
271
-
272
- public void setConfiguration (String [] args ) {
263
+ {
273
264
GridHubConfiguration pending = new GridHubConfiguration ();
274
265
JCommander .newBuilder ().addObject (pending ).build ().parse (args );
275
266
configuration = pending ;
@@ -281,20 +272,20 @@ public void setConfiguration(String[] args) {
281
272
}
282
273
}
283
274
275
+ public StandaloneConfiguration getConfiguration () {
276
+ return configuration ;
277
+ }
278
+
284
279
public void launch () throws Exception {
285
280
log .info (String .format (
286
281
"Launching Selenium Grid hub on port %s" , configuration .port ));
287
282
Hub h = new Hub (configuration );
288
283
h .start ();
289
284
}
290
285
})
291
- .put (GridRole .NODE .toString (), () -> new GridItemLauncher () {
286
+ .put (GridRole .NODE .toString (), (args ) -> new GridItemLauncher () {
292
287
GridNodeConfiguration configuration ;
293
- public StandaloneConfiguration getConfiguration () {
294
- return configuration ;
295
- }
296
-
297
- public void setConfiguration (String [] args ) {
288
+ {
298
289
GridNodeConfiguration pending = new GridNodeConfiguration ();
299
290
JCommander .newBuilder ().addObject (pending ).build ().parse (args );
300
291
configuration = pending ;
@@ -309,6 +300,10 @@ public void setConfiguration(String[] args) {
309
300
}
310
301
}
311
302
303
+ public StandaloneConfiguration getConfiguration () {
304
+ return configuration ;
305
+ }
306
+
312
307
public void launch () throws Exception {
313
308
log .info (String .format (
314
309
"Launching a Selenium Grid node on port %s" , configuration .port ));
@@ -324,18 +319,15 @@ public void launch() throws Exception {
324
319
try {
325
320
Class .forName (CORE_RUNNER_CLASS , false , GridLauncherV3 .class .getClassLoader ());
326
321
327
- launchers .put ("corerunner" , () -> new GridItemLauncher () {
328
- CoreRunnerConfiguration configuration ;
322
+ launchers .put ("corerunner" , (args ) -> new GridItemLauncher () {
323
+ CoreRunnerConfiguration configuration = new CoreRunnerConfiguration ();
324
+ {
325
+ JCommander .newBuilder ().addObject (configuration ).build ().parse (args );
326
+ }
329
327
public StandaloneConfiguration getConfiguration () {
330
328
return configuration ;
331
329
}
332
330
333
- @ Override
334
- public void setConfiguration (String [] args ) {
335
- configuration = new CoreRunnerConfiguration ();
336
- JCommander .newBuilder ().addObject (configuration ).build ().parse (args );
337
- }
338
-
339
331
@ Override
340
332
public void launch () throws Exception {
341
333
Class <?> coreRunnerClass = Class .forName (CORE_RUNNER_CLASS );
0 commit comments