Skip to content

Commit b9dd5af

Browse files
committed
Remove duplicate syserr output from SM
1 parent 477f84a commit b9dd5af

File tree

2 files changed

+59
-49
lines changed

2 files changed

+59
-49
lines changed

java/src/org/openqa/selenium/manager/SeleniumManager.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ private static Result runCommand(Path binary, List<String> arguments) {
113113
try {
114114
CommandLine command =
115115
new CommandLine(binary.toAbsolutePath().toString(), arguments.toArray(new String[0]));
116-
command.copyOutputTo(System.err);
117116
command.executeAsync();
118117
command.waitFor(10000); // A generous timeout
119118
if (command.isRunning()) {
@@ -130,16 +129,8 @@ private static Result runCommand(Path binary, List<String> arguments) {
130129
if (!output.isEmpty()) {
131130
try {
132131
jsonOutput = new Json().toType(output, SeleniumManagerOutput.class);
133-
jsonOutput.logs.forEach(
134-
logged -> {
135-
if (logged.level.equalsIgnoreCase(WARN)) {
136-
LOG.warning(logged.message);
137-
}
138-
if (logged.level.equalsIgnoreCase(DEBUG) || logged.level.equalsIgnoreCase(INFO)) {
139-
LOG.fine(logged.message);
140-
}
141-
});
142-
dump = jsonOutput.result.message;
132+
jsonOutput.getLogs().forEach(logged -> LOG.log(logged.getLevel(), logged.getMessage()));
133+
dump = jsonOutput.getResult().getMessage();
143134
} catch (JsonException e) {
144135
failedToParse = e;
145136
}
@@ -152,7 +143,7 @@ private static Result runCommand(Path binary, List<String> arguments) {
152143
throw new WebDriverException(
153144
"Failed to parse json output, executed: " + arguments + "\n" + dump, failedToParse);
154145
}
155-
return jsonOutput.result;
146+
return jsonOutput.getResult();
156147
}
157148

158149
/**

java/src/org/openqa/selenium/manager/SeleniumManagerOutput.java

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
import java.util.List;
2020
import java.util.Objects;
21+
import java.util.logging.Level;
22+
import org.openqa.selenium.internal.Require;
2123
import org.openqa.selenium.json.JsonInput;
2224

2325
public class SeleniumManagerOutput {
2426

25-
public List<Log> logs;
26-
public Result result;
27+
private List<Log> logs;
28+
private Result result;
2729

2830
public List<Log> getLogs() {
2931
return logs;
@@ -42,43 +44,76 @@ public void setResult(Result result) {
4244
}
4345

4446
public static class Log {
45-
public String level;
46-
long timestamp;
47-
public String message;
47+
private final Level level;
48+
private final long timestamp;
49+
private final String message;
4850

49-
public String getLevel() {
50-
return level;
51+
public Log(Level level, long timestamp, String message) {
52+
this.level = Require.nonNull("level", level);
53+
this.timestamp = timestamp;
54+
this.message = Require.nonNull("message", message);
5155
}
5256

53-
public void setLevel(String level) {
54-
this.level = level;
57+
public Level getLevel() {
58+
return level;
5559
}
5660

5761
public long getTimestamp() {
5862
return timestamp;
5963
}
6064

61-
public void setTimestamp(long timestamp) {
62-
this.timestamp = timestamp;
63-
}
64-
6565
public String getMessage() {
6666
return message;
6767
}
6868

69-
public void setMessage(String message) {
70-
this.message = message;
69+
private static Log fromJson(JsonInput input) {
70+
Level level = Level.FINE;
71+
long timestamp = System.currentTimeMillis();
72+
String message = "";
73+
74+
input.beginObject();
75+
while (input.hasNext()) {
76+
switch (input.nextName()) {
77+
case "level":
78+
switch (input.nextString().toLowerCase()) {
79+
case "error":
80+
case "warn":
81+
level = Level.WARNING;
82+
break;
83+
84+
case "info":
85+
level = Level.INFO;
86+
break;
87+
88+
default:
89+
level = Level.FINE;
90+
break;
91+
}
92+
break;
93+
94+
case "timestamp":
95+
timestamp = input.nextNumber().longValue();
96+
break;
97+
98+
case "message":
99+
message = input.nextString();
100+
break;
101+
}
102+
}
103+
input.endObject();
104+
105+
return new Log(level, timestamp, message);
71106
}
72107
}
73108

74109
public static class Result {
75-
public int code;
76-
public String message;
77-
public String driverPath;
78-
public String browserPath;
110+
private final int code;
111+
private final String message;
112+
private final String driverPath;
113+
private final String browserPath;
79114

80115
public Result(String driverPath) {
81-
this.driverPath = driverPath;
116+
this(0, null, driverPath, null);
82117
}
83118

84119
public Result(int code, String message, String driverPath, String browserPath) {
@@ -92,34 +127,18 @@ public int getCode() {
92127
return code;
93128
}
94129

95-
public void setCode(int code) {
96-
this.code = code;
97-
}
98-
99130
public String getMessage() {
100131
return message;
101132
}
102133

103-
public void setMessage(String message) {
104-
this.message = message;
105-
}
106-
107134
public String getDriverPath() {
108135
return driverPath;
109136
}
110137

111-
public void setDriverPath(String driverPath) {
112-
this.driverPath = driverPath;
113-
}
114-
115138
public String getBrowserPath() {
116139
return browserPath;
117140
}
118141

119-
public void setBrowserPath(String browserPath) {
120-
this.browserPath = browserPath;
121-
}
122-
123142
@Override
124143
public String toString() {
125144
return "Result{"
@@ -154,7 +173,7 @@ public int hashCode() {
154173
return Objects.hash(code, message, driverPath, browserPath);
155174
}
156175

157-
public static Result fromJson(JsonInput input) {
176+
private static Result fromJson(JsonInput input) {
158177
int code = 0;
159178
String message = null;
160179
String driverPath = null;

0 commit comments

Comments
 (0)