Skip to content

Commit

Permalink
[grid] Fixing configuration information in console servlet
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Aug 15, 2018
1 parent 7530315 commit 5726224
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@

public class GridHubCliOptions extends CommonGridCliOptions {

private String[] rawArgs;

public JCommander parse(String... args) {
rawArgs = args;
JCommander commander = JCommander.newBuilder().addObject(this).build();
commander.parse(args);
return commander;
Expand Down Expand Up @@ -111,4 +114,7 @@ public String getRegistry() {
return registry;
}

public String[] getRawArgs() {
return rawArgs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class GridHubConfiguration extends GridConfiguration {

public String registry;

private GridHubCliOptions cliConfig;

/**
* Creates a new configuration using the default values.
*/
Expand All @@ -96,6 +98,7 @@ public GridHubConfiguration(HubJsonConfiguration jsonConfig) {
public GridHubConfiguration(GridHubCliOptions cliConfig) {
this(ofNullable(cliConfig.getConfigFile()).map(HubJsonConfiguration::loadFromResourceOrFile)
.orElse(DEFAULT_CONFIG_FROM_JSON));
this.cliConfig = cliConfig;
super.merge(cliConfig);
ofNullable(cliConfig.getNewSessionWaitTimeout()).ifPresent(v -> newSessionWaitTimeout = v);
ofNullable(cliConfig.getThrowOnCapabilityNotPresent()).ifPresent(v -> throwOnCapabilityNotPresent = v);
Expand Down Expand Up @@ -191,4 +194,8 @@ public String toString(String format) {

return sb.toString();
}

public GridHubCliOptions getCliConfig() {
return cliConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -215,20 +220,25 @@ private String getConfigInfo(boolean verbose) {
builder.append(prettyHtmlPrint(config));

if (verbose) {

GridHubConfiguration tmp = new GridHubConfiguration();

builder.append("<b>Config details :</b><br/>");
builder.append("<b>hub launched with :</b>");
builder.append(config.toString());

builder.append("<br/><b>the final configuration comes from :</b><br/>");
builder.append("<br/><b>The final configuration comes from:</b><br/>");
builder.append("<b>the default :</b><br/>");
builder.append(prettyHtmlPrint(tmp));

builder.append("<br/><b>updated with params :</b></br>");
tmp.merge(config);
builder.append(prettyHtmlPrint(tmp));
if (config.getCliConfig() != null) {
builder.append("<b>updated with command line options:</b><br/>");
builder.append(String.join(" ", config.getCliConfig().getRawArgs()));

if (config.getCliConfig().getConfigFile() != null) {
builder.append("<br/><b>and configuration loaded from ").append(config.getCliConfig().getConfigFile()).append(":</b><br/>");
try {
builder.append(String.join("<br/>", Files.readAllLines(new File(config.getCliConfig().getConfigFile()).toPath())));
} catch (IOException e) {
builder.append("<b>").append(e.getMessage()).append("</b>");
}
}
}
}
builder.append("</div>");
return builder.toString();
Expand Down

0 comments on commit 5726224

Please sign in to comment.