Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all usages of Guava #496

Merged
merged 2 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions build-monitor-acceptance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
</dependency>
<!-- / serenity -->

<!-- TODO remove when minimum Jenkins core baseline is 2.321 or higher -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.smartcodeltd.jenkinsci.plugins.build_monitor.model;

import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -19,7 +19,7 @@ public String name() {
}

public List<ProjectStatus> status() {
return ImmutableList.copyOf(status);
return Collections.unmodifiableList(new ArrayList<>(status));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.smartcodeltd.jenkinsci.plugins.build_monitor.model;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -37,8 +36,10 @@ public static List<ProjectStatus> fromMultiple(String cssClasses) {
// todo: Java 8?
List<ProjectStatus> statuses = new ArrayList<>();

for(String statusClass : Sets.intersection(projectStatusClasses(), setOf(split(cssClasses)))) {
statuses.add(ProjectStatus.from(statusClass));
for (String statusClass : projectStatusClasses()) {
if (setOf(split(cssClasses)).contains(statusClass)) {
statuses.add(ProjectStatus.from(statusClass));
}
}

return statuses;
Expand Down Expand Up @@ -66,7 +67,7 @@ private static List<String> split(String spaceSeparatedItems) {
}

private static <T> Set<T> setOf(List<T> items) {
return ImmutableSet.copyOf(items);
return Collections.unmodifiableSet(new HashSet<>(items));
}

private static <T> List<String> stringRepresentationsOf(Collection<T> items) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.integration.jenkins;

import com.beust.jcommander.internal.Lists;
import net.serenitybdd.integration.jenkins.client.JenkinsClient;
import net.serenitybdd.integration.jenkins.environment.PluginDescription;
import net.serenitybdd.integration.jenkins.environment.rules.ApplicativeTestRule;
Expand All @@ -17,9 +16,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.google.common.collect.ImmutableList.copyOf;
import static java.lang.String.format;
import static java.util.Arrays.asList;
import static net.serenitybdd.integration.utils.ListFunctions.concat;
Expand All @@ -32,9 +31,9 @@ public class JenkinsInstance implements TestRule {

private JenkinsClient client = null; // instantiated when the Jenkins server is up and running

private List<? extends ApplicativeTestRule<JenkinsInstance>> customRulesToApplyBeforeStart = Lists.newArrayList();
private List<? extends ApplicativeTestRule<JenkinsInstance>> customRulesToApplyBeforeStart = new ArrayList<>();
private List<? extends ApplicativeTestRule<JenkinsInstance>> defaultRules;
private List<? extends ApplicativeTestRule<JenkinsInstance>> customRulesToApplyAfterStart = Lists.newArrayList();
private List<? extends ApplicativeTestRule<JenkinsInstance>> customRulesToApplyAfterStart = new ArrayList<>();

/**
* @param pluginUnderTest
Expand Down Expand Up @@ -102,13 +101,13 @@ public void setPort(int portNumber) {
}

public <ATR extends ApplicativeTestRule<JenkinsInstance>> JenkinsInstance beforeStartApply(List<ATR> customRulesToBeApplied) {
this.customRulesToApplyBeforeStart = copyOf(customRulesToBeApplied);
this.customRulesToApplyBeforeStart = Collections.unmodifiableList(new ArrayList<>(customRulesToBeApplied));

return this;
}

public <ATR extends ApplicativeTestRule<JenkinsInstance>> JenkinsInstance afterStartApply(List<ATR> customRulesToBeApplied) {
this.customRulesToApplyAfterStart = copyOf(customRulesToBeApplied);
this.customRulesToApplyAfterStart = Collections.unmodifiableList(new ArrayList<>(customRulesToBeApplied));

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import net.serenitybdd.integration.jenkins.environment.rules.ApplicativeTestRule;

import java.util.ArrayList;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;

public class TestEnvironment {
private final JenkinsInstance instance;
private final List<ApplicativeTestRule<JenkinsInstance>> rulesToBeAppliedBeforeJenkinsStart = newArrayList();
private final List<ApplicativeTestRule<JenkinsInstance>> rulesToBeAppliedAfterJenkinsStart = newArrayList();
private final List<ApplicativeTestRule<JenkinsInstance>> rulesToBeAppliedBeforeJenkinsStart = new ArrayList<>();
private final List<ApplicativeTestRule<JenkinsInstance>> rulesToBeAppliedAfterJenkinsStart = new ArrayList<>();

public TestEnvironment(JenkinsInstance instance) {
this.instance = instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.serenitybdd.integration.jenkins.client;

import com.google.common.base.Joiner;

import hudson.cli.CLI;
import net.serenitybdd.integration.jenkins.process.JenkinsProcess;
import org.jdeferred.Promise;
Expand Down Expand Up @@ -148,7 +146,7 @@ public void setExternalBuildResult(String projectName, String result) {
}

private synchronized int executeGroovy(Promise<Matcher, ?, ?> promise, String... groovyScriptLines) throws InterruptedException {
String script = Joiner.on(";\n").join(groovyScriptLines);
String script = String.join(";\n", groovyScriptLines);

//TODO use RealJenkinsRule
//return executor.call("groovy", "=").execute(withInput(script), info(logger), error(logger));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.serenitybdd.integration.jenkins.environment;

import com.github.zafarkhaja.semver.Version;
import com.google.common.base.Charsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -11,6 +10,7 @@
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
Expand All @@ -26,11 +26,12 @@ public class UpdateCenter {
private final Path tempDir;

private List<Version> jenkinsLTSVersions = Arrays.asList(
Version.valueOf("2.303.3"),
Version.valueOf("2.303.2"),
Version.valueOf("2.303.1"),
Version.valueOf("2.289.3"),
Version.valueOf("2.277.4"),
Version.valueOf("2.263.4"),
Version.valueOf("2.249.3")
Version.valueOf("2.289.2"),
Version.valueOf("2.289.1")
);


Expand Down Expand Up @@ -76,7 +77,7 @@ String getUpdateVersionToUse(String jenkinsVersionString) {
}

private String stripJSONPEnvelope(Path jsonp) throws IOException {
return Files.readAllLines(jsonp, Charsets.UTF_8).get(1);
return Files.readAllLines(jsonp, StandardCharsets.UTF_8).get(1);
}

private Path download(URL link) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.io.IOException;
import java.net.ServerSocket;

import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;

public class FindFreePort implements ApplicativeTestRule<JenkinsInstance> {
Expand All @@ -31,7 +30,9 @@ public static FindFreePort useFreePortFromTheFollowingRange(int rangeStart, int
}

public FindFreePort(int rangeStart, int rangeEnd) {
checkArgument(rangeStart <= rangeEnd, format("Start of the port range (%d) should be lower than the end of the range (%d)", rangeStart, rangeEnd));
if (rangeStart > rangeEnd) {
throw new IllegalArgumentException(format("Start of the port range (%d) should be lower than the end of the range (%d)", rangeStart, rangeEnd));
}

this.rangeStart = rangeStart;
this.rangeEnd = rangeEnd;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.integration.jenkins.environment.rules;

import com.google.common.base.Joiner;
import net.serenitybdd.integration.jenkins.JenkinsInstance;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
Expand All @@ -12,8 +11,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Arrays.asList;

public class InstallPluginsFromDisk implements ApplicativeTestRule<JenkinsInstance> {
Expand All @@ -31,7 +30,7 @@ public TestRule applyTo(final JenkinsInstance jenkins) {
@Override
protected void starting(Description description) {
Path pluginsDir = jenkins.home().resolve("plugins");
String plugins = Joiner.on(", ").join(pluginsToInstall);
String plugins = pluginsToInstall.stream().map(Object::toString).collect(Collectors.joining(", "));

Log.info("Installing {} into {}", plugins, pluginsDir);

Expand All @@ -47,7 +46,9 @@ protected void starting(Description description) {
}

private Path existing(Path plugin) {
checkArgument(Files.exists(plugin), String.format("Plugin file '%s' doesn't exist and couldn't be installed.", plugin));
if (!Files.exists(plugin)) {
throw new IllegalArgumentException(String.format("Plugin file '%s' doesn't exist and couldn't be installed.", plugin));
}

return plugin;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.integration.jenkins.environment.rules;

import com.google.common.base.Charsets;
import net.serenitybdd.integration.jenkins.JenkinsInstance;
import net.serenitybdd.integration.jenkins.environment.UpdateCenter;
import org.junit.rules.TestRule;
Expand All @@ -10,6 +9,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -47,7 +47,7 @@ private void warmUpUpdateCenterCacheFor(JenkinsInstance jenkins) {
String json = updateCenter.jsonFor(jenkins.version());
Path destination = Files.createDirectories(jenkins.home().resolve("updates")).resolve("default.json");

Files.write(destination, json.getBytes(Charsets.UTF_8));
Files.write(destination, json.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("Couldn't warm up the Update Center cache", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package net.serenitybdd.integration.utils;

import com.beust.jcommander.internal.Lists;
import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ListFunctions {
public static <T> List<T> concat(List<? extends T>... lists) {
if (lists.length == 0) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
}

List<T> combined = Lists.newArrayList();
List<T> combined = new ArrayList<>();

for (List<? extends T> list : lists) {
combined.addAll(list);
Expand All @@ -34,6 +32,6 @@ public static <T> T head(List<T> list) {
}

public static <T> List<T> tail(List<T> list) {
return ImmutableList.copyOf(list.subList(1, list.size()));
return Collections.unmodifiableList(new ArrayList<>(list.subList(1, list.size())));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.screenplay.jenkins.actions;

import com.google.common.base.Joiner;
import net.serenitybdd.screenplay.Action;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.actions.Click;
Expand All @@ -20,11 +19,11 @@ public static EnterCode asFollows(String... lines) {
}

public Action intoTheCodeMirror(Target editorField) {
return instrumented(EnterCodeIntoCodeMirrorEditor.class, editorField, Joiner.on(System.lineSeparator()).join(lines));
return instrumented(EnterCodeIntoCodeMirrorEditor.class, editorField, String.join(System.lineSeparator(), lines));
}

public Action intoThePipelineEditor(Target editorField) {
return instrumented(EnterCodeIntoPipelineEditor.class, editorField, Joiner.on(System.lineSeparator()).join(lines));
return instrumented(EnterCodeIntoPipelineEditor.class, editorField, String.join(System.lineSeparator(), lines));
}

public EnterCode(List<String> lines) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.serenitybdd.screenplay.jenkins.targets;

import com.google.common.base.Joiner;
import net.serenitybdd.screenplay.targets.Target;

import static java.lang.String.format;
Expand All @@ -9,22 +8,16 @@ public class Setting {

public static Target defining(String name) {
return Target.the(format("the '%s' field", name))
.locatedBy(lastElementMatching(either(xpathFor("input"), xpathFor("textarea"), xpathFor("select"),
xpathForTableLayout("input"), xpathForTableLayout("textarea"), xpathForTableLayout("select"))))
.locatedBy(lastElementMatching(either(xpathFor("input"), xpathFor("textarea"), xpathFor("select"))))
.of(name);
}

private static String xpathForTableLayout(String fieldType) {
// TODO: Deprecated Layout Since 2.277.1
return format("//tr[td[contains(@class, 'setting-name') and contains(., '{0}')]]//%s", fieldType);
}

private static String xpathFor(String fieldType) {
return format("//div[contains(@class, 'tr') and div[contains(@class, 'setting-name') and contains(., '{0}')]]//%s", fieldType);
}

private static String either(String... xpaths) {
return Joiner.on(" | ").join(xpaths);
return String.join(" | ", xpaths);
}

private static String lastElementMatching(String xpath) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.serenitybdd.screenplay.jenkins.tasks.configuration;

import com.beust.jcommander.internal.Lists;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Task;

import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -42,5 +42,5 @@ private Performable[] perform(List<Performable> todos) {
return todos.toArray(new Performable[todos.size()]);
}

private final List<Performable> todos = Lists.newArrayList();
private final List<Performable> todos = new ArrayList<>();
}
Loading