Skip to content

Commit

Permalink
[java] Code cleanup, no functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Apr 5, 2019
1 parent c1371ce commit efbe341
Show file tree
Hide file tree
Showing 149 changed files with 172 additions and 239 deletions.
1 change: 0 additions & 1 deletion java/client/test/org/openqa/selenium/build/BuckBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.base.StandardSystemProperty.LINE_SEPARATOR;
import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.Platform.WINDOWS;
import static org.openqa.selenium.build.DevMode.isInDevMode;

import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class WrappedPrintWriter extends PrintWriter {
private final int lineLength;
private final int indentBy;
private int position = 0;
private boolean isIndenting;

public WrappedPrintWriter(OutputStream out, int lineLength, int indentBy) {
this(new OutputStreamWriter(out), lineLength, indentBy);
Expand All @@ -50,10 +49,8 @@ public WrappedPrintWriter(Writer out, int lineLength, int indentBy) {
public void write(int c) {
if (c == '\n') {
super.write(c);
isIndenting = false;
position = 0;
} else if (position > lineLength && Character.isWhitespace(c)) {
isIndenting = true;
super.write('\n');
for (int i = 0; i < indentBy; i++) {
super.write(' ');
Expand Down
2 changes: 1 addition & 1 deletion java/server/src/org/openqa/selenium/events/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class Type {
private final String name;

public Type(String name) {
this.name = Objects.requireNonNull(name, "Type name nust be set.");
this.name = Objects.requireNonNull(name, "Type name must be set.");
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.events.Type;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.net.PortProber;
import org.zeromq.ZContext;
import org.zeromq.ZMQ;

import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
Expand Down
10 changes: 3 additions & 7 deletions java/server/src/org/openqa/selenium/grid/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

Expand Down Expand Up @@ -161,11 +159,9 @@ public Executable configure(String... args) {
String format = " %-" + longest + "s";

PrintWriter indented = new WrappedPrintWriter(System.out, 72, indent);
commands.forEach(cmd -> {
indented.format(format, cmd.getName())
.append(cmd.getDescription())
.append("\n");
});
commands.forEach(cmd -> indented.format(format, cmd.getName())
.append(cmd.getDescription())
.append("\n"));

out.write("\nFor each command, run with `--help` for command-specific help\n");
out.write("\nUse the `--ext` flag before the command name to specify an additional " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.json.JsonInput;
import org.openqa.selenium.remote.Dialect;

import java.util.Base64;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public Map<Capabilities, Integer> getUsedStereotypes() {

public boolean hasCapacity() {
HashMap<Capabilities, Integer> all = new HashMap<>(stereotypes);
used.forEach((caps, count) -> {
all.computeIfPresent(caps, (ignored, curr) -> curr - count);
});
used.forEach((caps, count) -> all.computeIfPresent(caps, (ignored, curr) -> curr - count));

return all.values()
.stream()
Expand Down
8 changes: 3 additions & 5 deletions java/server/src/org/openqa/selenium/grid/data/NodeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ private Map<String, Object> toJson() {

private List<Map<String, Object>> asCapacity(Map<Capabilities, Integer> toConvert) {
ImmutableList.Builder<Map<String, Object>> toReturn = ImmutableList.builder();
toConvert.forEach((caps, count) -> {
toReturn.add(ImmutableMap.of(
"capabilities", caps,
"count", count));
});
toConvert.forEach((caps, count) -> toReturn.add(ImmutableMap.of(
"capabilities", caps,
"count", count)));
return toReturn.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.tracing.DistributedTracer;

import java.io.IOException;
import java.util.Objects;

public class AddNode implements CommandHandler {
Expand All @@ -49,7 +48,7 @@ public AddNode(
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
NodeStatus status = json.toType(req.getContentString(), NodeStatus.class);

Node node = new RemoteNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
import org.openqa.selenium.grid.data.CreateSessionResponse;
import org.openqa.selenium.grid.web.CommandHandler;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.NewSessionPayload;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.io.Reader;
import java.util.Objects;

class CreateSession implements CommandHandler {
Expand All @@ -43,7 +40,7 @@ public CreateSession(Json json, Distributor distributor) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
CreateSessionResponse sessionResponse = distributor.newSession(req);
resp.setContent(json.toJson(ImmutableMap.of("value", sessionResponse)).getBytes(UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class GetDistributorStatus implements CommandHandler {
Expand All @@ -41,7 +40,7 @@ public GetDistributorStatus(Json json, Distributor distributor) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
DistributorStatus status = distributor.getStatus();

resp.setContent(json.toJson(ImmutableMap.of("value", status)).getBytes(UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;
import java.util.UUID;

Expand All @@ -36,7 +35,7 @@ public RemoveNode(Distributor distributor, UUID nodeId) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
distributor.remove(nodeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class StatusHandler implements CommandHandler {
Expand All @@ -41,7 +40,7 @@ public StatusHandler(Distributor distributor, Json json) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
DistributorStatus status = distributor.getStatus();

ImmutableMap<String, Object> report = ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.MapConfig;

import java.util.Map;

class DefaultDistributorConfig extends MapConfig {

DefaultDistributorConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* either a session starts or nothing is successful.
* <p>
* To complicate matters, local ends may send a session request that is one of
* two different dialacts (presumably in the future there may be more. *sigh*)
* two different dialects (presumably in the future there may be more. *sigh*)
* and care must be taken to ensure that dialacts match, or that a converter
* of some sort is added. The Node may be the part of the system responsible
* for adding this converter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public void configure(HttpClient.Factory clientFactory, LocalNode.Builder node)
if (i == allConfigs.size()) {
throw new DockerException("Unable to find JSON config");
}
Capabilities sterotype = JSON.toType(allConfigs.get(i), Capabilities.class);
Capabilities stereotype = JSON.toType(allConfigs.get(i), Capabilities.class);

kinds.put(imageName, sterotype);
kinds.put(imageName, stereotype);
}

HttpClient client = clientFactory.createClient(new URL("http://localhost:2375"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.remote.Dialect;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.HttpClient;

import java.net.URI;
import java.net.URISyntaxException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class ForwardWebDriverCommand implements CommandHandler {
Expand All @@ -33,7 +32,7 @@ public ForwardWebDriverCommand(Node node) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
node.executeWebDriverCommand(req, resp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class GetNodeSession implements CommandHandler {
Expand All @@ -44,7 +43,7 @@ class GetNodeSession implements CommandHandler {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
Session session = node.getSession(id);

resp.setContent(json.toJson(ImmutableMap.of("value", session)).getBytes(UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class IsSessionOwner implements CommandHandler {
Expand All @@ -43,7 +42,7 @@ public IsSessionOwner(Node node, Json json, SessionId id) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
resp.setContent(json.toJson(
ImmutableMap.of("value", node.isSessionOwner(id))).getBytes(UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
import java.util.function.BiConsumer;
Expand All @@ -41,13 +40,11 @@ class NewNodeSession implements CommandHandler {
this.node = Objects.requireNonNull(node);

this.json = Objects.requireNonNull(json);
this.encodeJson = (res, obj) -> {
res.setContent(json.toJson(obj).getBytes(UTF_8));
};
this.encodeJson = (res, obj) -> res.setContent(json.toJson(obj).getBytes(UTF_8));
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
CreateSessionRequest incoming = json.toType(req.getContentString(), CreateSessionRequest.class);

CreateSessionResponse sessionResponse = node.newSession(incoming).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

public class StatusHandler implements CommandHandler {
Expand All @@ -41,7 +40,7 @@ public StatusHandler(Node node, Json json) {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
NodeStatus status = node.getStatus();

ImmutableMap<String, Object> report = ImmutableMap.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.IOException;
import java.util.Objects;

class StopNodeSession implements CommandHandler {
Expand All @@ -35,7 +34,7 @@ class StopNodeSession implements CommandHandler {
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
node.stop(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

package org.openqa.selenium.grid.node.local;

import static org.openqa.selenium.remote.http.HttpMethod.DELETE;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.grid.data.CreateSessionRequest;
import org.openqa.selenium.grid.data.Session;
import org.openqa.selenium.grid.data.SessionClosedEvent;
import org.openqa.selenium.grid.node.ActiveSession;
import org.openqa.selenium.grid.node.SessionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public GridStatusHandler(Json json, HttpClient.Factory clientFactory, Distributo
}

@Override
public void execute(HttpRequest req, HttpResponse resp) throws IOException {
public void execute(HttpRequest req, HttpResponse resp) {
long start = System.currentTimeMillis();

DistributorStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.openqa.selenium.grid.sessionmap.SessionMap;
import org.openqa.selenium.grid.web.CommandHandler;
import org.openqa.selenium.grid.web.ReverseProxyHandler;
import org.openqa.selenium.grid.web.WebDriverUrls;
import org.openqa.selenium.net.Urls;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.HttpClient;
Expand Down Expand Up @@ -58,7 +57,7 @@ public HandleSession(
.expireAfterAccess(Duration.ofMinutes(1))
.build(new CacheLoader<SessionId, CommandHandler>() {
@Override
public CommandHandler load(SessionId id) throws Exception {
public CommandHandler load(SessionId id) {
Session session = sessions.get(id);
if (session instanceof CommandHandler) {
return (CommandHandler) session;
Expand Down

0 comments on commit efbe341

Please sign in to comment.