Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions java/src/org/openqa/selenium/grid/commands/DefaultHubConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

package org.openqa.selenium.grid.commands;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.openqa.selenium.grid.config.MapConfig;

class DefaultHubConfig extends MapConfig {

DefaultHubConfig() {
super(
ImmutableMap.of(
Map.of(
"events",
ImmutableMap.of(
Map.of(
"publish", "tcp://*:4442",
"subscribe", "tcp://*:4443",
"bind", true),
"sessions",
ImmutableMap.of(
Map.of(
"implementation", "org.openqa.selenium.grid.sessionmap.local.LocalSessionMap"),
"server", ImmutableMap.of("port", 4444)));
"server", Map.of("port", 4444)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

package org.openqa.selenium.grid.commands;

import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.openqa.selenium.grid.config.MapConfig;

class DefaultStandaloneConfig extends MapConfig {

DefaultStandaloneConfig() {
super(
ImmutableMap.of(
"events",
ImmutableMap.of("implementation", "org.openqa.selenium.events.local.GuavaEventBus"),
Map.of(
"events", Map.of("implementation", "org.openqa.selenium.events.local.GuavaEventBus"),
"sessions",
ImmutableMap.of(
Map.of(
"implementation",
"org.openqa.selenium.grid.sessionmap.local.LocalSessionMap")));
}
Expand Down
19 changes: 7 additions & 12 deletions java/src/org/openqa/selenium/grid/commands/EventBusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
import static org.openqa.selenium.remote.http.Contents.asJson;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
Expand Down Expand Up @@ -70,7 +65,7 @@ public String getDescription() {

@Override
public Set<Role> getConfigurableRoles() {
return ImmutableSet.of(EVENT_BUS_ROLE, HTTPD_ROLE);
return Set.of(EVENT_BUS_ROLE, HTTPD_ROLE);
}

@Override
Expand All @@ -91,13 +86,13 @@ protected String getSystemPropertiesConfigPrefix() {
@Override
protected Config getDefaultConfig() {
return new MapConfig(
ImmutableMap.of(
Map.of(
"events",
ImmutableMap.of(
Map.of(
"bind", true,
"publish", "tcp://*:4442",
"subscribe", "tcp://*:4443"),
"server", ImmutableMap.of("port", 5557)));
"server", Map.of("port", 5557)));
}

public Server<?> asServer(Config initialConfig) {
Expand Down Expand Up @@ -198,9 +193,9 @@ private HttpResponse httpResponse(boolean ready, String message) {
.addHeader("Content-Type", JSON_UTF_8)
.setContent(
asJson(
ImmutableMap.of(
Map.of(
"value",
ImmutableMap.of(
Map.of(
"ready", ready,
"message", message))));
}
Expand Down
4 changes: 1 addition & 3 deletions java/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.openqa.selenium.remote.http.Route.combine;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableSet;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
Expand Down Expand Up @@ -88,8 +87,7 @@ public String getDescription() {

@Override
public Set<Role> getConfigurableRoles() {
return ImmutableSet.of(
DISTRIBUTOR_ROLE, EVENT_BUS_ROLE, HTTPD_ROLE, SESSION_QUEUE_ROLE, ROUTER_ROLE);
return Set.of(DISTRIBUTOR_ROLE, EVENT_BUS_ROLE, HTTPD_ROLE, SESSION_QUEUE_ROLE, ROUTER_ROLE);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions java/src/org/openqa/selenium/grid/commands/Standalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.openqa.selenium.remote.http.Route.combine;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableSet;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -94,8 +93,7 @@ public String getDescription() {

@Override
public Set<Role> getConfigurableRoles() {
return ImmutableSet.of(
DISTRIBUTOR_ROLE, HTTPD_ROLE, NODE_ROLE, ROUTER_ROLE, SESSION_QUEUE_ROLE);
return Set.of(DISTRIBUTOR_ROLE, HTTPD_ROLE, NODE_ROLE, ROUTER_ROLE, SESSION_QUEUE_ROLE);
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions java/src/org/openqa/selenium/grid/config/AnnotatedConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package org.openqa.selenium.grid.config;

import com.beust.jcommander.Parameter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.primitives.Primitives;
import java.lang.reflect.Field;
import java.util.ArrayDeque;
Expand All @@ -35,6 +32,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import org.openqa.selenium.internal.Require;

/**
Expand Down Expand Up @@ -175,17 +173,18 @@ public Optional<List<String>> getAll(String section, String option) {
return Optional.empty();
}

return Optional.of(ImmutableList.copyOf(values));
return Optional.of(List.copyOf(values));
}

@Override
public Set<String> getSectionNames() {
return ImmutableSortedSet.copyOf(config.keySet());
return Collections.unmodifiableSortedSet(new TreeSet<>(config.keySet()));
}

@Override
public Set<String> getOptions(String section) {
Require.nonNull("Section name to get options for", section);
return ImmutableSortedSet.copyOf(config.getOrDefault(section, ImmutableMap.of()).keySet());
return Collections.unmodifiableSortedSet(
new TreeSet<>(config.getOrDefault(section, Map.of()).keySet()));
}
}
15 changes: 6 additions & 9 deletions java/src/org/openqa/selenium/grid/config/CompoundConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@

package org.openqa.selenium.grid.config;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static java.util.Comparator.naturalOrder;

import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.openqa.selenium.internal.Require;

public class CompoundConfig implements Config {
Expand All @@ -37,7 +34,7 @@ public CompoundConfig(Config... allConfigsInDescendingOrderOfImportance) {
throw new ConfigException("List of config files must be greater than 0.");
}

this.allConfigs = ImmutableList.copyOf(allConfigsInDescendingOrderOfImportance);
this.allConfigs = List.of(allConfigsInDescendingOrderOfImportance);
}

@Override
Expand All @@ -51,7 +48,7 @@ public Optional<List<String>> getAll(String section, String option) {
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(Collection::stream)
.collect(toImmutableList());
.collect(Collectors.toUnmodifiableList());

return values.isEmpty() ? Optional.empty() : Optional.of(values);
}
Expand All @@ -61,7 +58,7 @@ public Set<String> getSectionNames() {
return allConfigs.stream()
.map(Config::getSectionNames)
.flatMap(Collection::stream)
.collect(toImmutableSortedSet(naturalOrder()));
.collect(Collectors.toCollection(TreeSet::new));
}

@Override
Expand All @@ -71,6 +68,6 @@ public Set<String> getOptions(String section) {
return allConfigs.stream()
.map(config -> config.getOptions(section))
.flatMap(Collection::stream)
.collect(toImmutableSortedSet(naturalOrder()));
.collect(Collectors.toCollection(TreeSet::new));
}
}
20 changes: 11 additions & 9 deletions java/src/org/openqa/selenium/grid/config/ConcatenatingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@

package org.openqa.selenium.grid.config;

import static java.util.Comparator.naturalOrder;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.openqa.selenium.internal.Require;

public class ConcatenatingConfig implements Config {
Expand All @@ -48,7 +46,7 @@ public ConcatenatingConfig(String prefix, char separator, Map<?, ?> values) {
entry ->
new AbstractMap.SimpleImmutableEntry<>(
String.valueOf(entry.getKey()), String.valueOf(entry.getValue())))
.collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
}

@Override
Expand All @@ -62,7 +60,7 @@ public Optional<List<String>> getAll(String section, String option) {
.filter(entry -> key.equalsIgnoreCase(entry.getKey()))
.map(Map.Entry::getValue)
.findFirst()
.map(ImmutableList::of);
.map(List::of);
}

@Override
Expand All @@ -76,7 +74,9 @@ public Set<String> getSectionNames() {
.filter(key -> key.indexOf(separator) > -1)
.map(key -> key.substring(0, key.indexOf(separator)))
.map(key -> key.toLowerCase(Locale.ENGLISH))
.collect(ImmutableSortedSet.toImmutableSortedSet(naturalOrder()));
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(TreeSet::new), Collections::unmodifiableSortedSet));
}

@Override
Expand All @@ -90,6 +90,8 @@ public Set<String> getOptions(String section) {
.filter(key -> key.length() > actualPrefix.length() + 1)
.map(key -> key.substring(actualPrefix.length()))
.map(key -> key.toLowerCase(Locale.ENGLISH))
.collect(ImmutableSortedSet.toImmutableSortedSet(naturalOrder()));
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(TreeSet::new), Collections::unmodifiableSortedSet));
}
}
3 changes: 1 addition & 2 deletions java/src/org/openqa/selenium/grid/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.grid.config;

import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -95,7 +94,7 @@ default List<String> toEntryList(Map<String, Object> mapItem) {
// add record separator
entryList.add(DELIMITER);
// return immutable config settings list
return ImmutableList.<String>builder().addAll(entryList).build();
return List.copyOf(entryList);
}

default String toJson(Object value) {
Expand Down
23 changes: 11 additions & 12 deletions java/src/org/openqa/selenium/grid/config/ConfigFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@
import static org.openqa.selenium.grid.config.StandardGridRoles.ALL_ROLES;

import com.beust.jcommander.Parameter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import java.io.PrintStream;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.openqa.selenium.json.Json;

public class ConfigFlags implements HasRoles {

private static final ImmutableSet<String> IGNORED_SECTIONS =
ImmutableSet.of("java", "lc", "term");
private static final Set<String> IGNORED_SECTIONS = Set.of("java", "lc", "term");

@Parameter(
names = "--config",
Expand All @@ -61,7 +60,7 @@ public Set<Role> getRoles() {

public Config readConfigFiles() {
if (configFiles == null || configFiles.isEmpty()) {
return new MapConfig(ImmutableMap.of());
return new MapConfig(Map.of());
}

return new CompoundConfig(configFiles.stream().map(Configs::from).toArray(Config[]::new));
Expand Down Expand Up @@ -106,12 +105,12 @@ public boolean dumpConfigHelp(Config config, Set<Role> currentRoles, PrintStream
.collect(
Collectors.toMap(
DescribedOption::section,
ImmutableSortedSet::of,
(l, r) ->
ImmutableSortedSet.<DescribedOption>naturalOrder()
.addAll(l)
.addAll(r)
.build()));
option -> Collections.unmodifiableSortedSet(new TreeSet<>(Set.of(option))),
(l, r) -> {
SortedSet<DescribedOption> merged = new TreeSet<>(l);
merged.addAll(r);
return Collections.unmodifiableSortedSet(merged);
}));

StringBuilder demoToml = new StringBuilder();
demoToml.append("Configuration help for Toml config file").append("\n\n");
Expand Down
Loading
Loading