From 0b6a9cfd53176ea4deafb55e7cafbf873164dc7e Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Mon, 9 Sep 2024 16:39:06 -0700 Subject: [PATCH] Clean up usage of third-party libraries (#1710) --- .../test/acceptance/controller/JBossController.java | 7 ++++--- .../test/acceptance/controller/JenkinsLogWatcher.java | 4 ++-- .../test/acceptance/controller/LocalController.java | 4 ++-- .../test/acceptance/controller/TomcatController.java | 5 +++-- .../test/acceptance/controller/WinstoneController.java | 4 ++-- .../test/acceptance/junit/FailureDiagnostics.java | 2 +- .../java/org/jenkinsci/test/acceptance/junit/Wait.java | 2 +- .../plugins/docker_build_step/DockerCommand.java | 3 +-- .../plugins/mock_security_realm/MockSecurityRealm.java | 2 +- .../test/acceptance/po/CapybaraPortingLayerImpl.java | 5 ++--- .../java/org/jenkinsci/test/acceptance/po/Jenkins.java | 2 +- .../java/org/jenkinsci/test/acceptance/po/PageObject.java | 2 +- .../org/jenkinsci/test/acceptance/po/ToolInstallation.java | 6 +++--- .../java/org/jenkinsci/test/acceptance/po/WizardLogin.java | 4 ++-- src/test/java/plugins/AuthorizeProjectTest.java | 3 +-- src/test/java/plugins/GerritTriggerTest.java | 5 ++--- src/test/java/plugins/JabberPluginTest.java | 4 ++-- 17 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/controller/JBossController.java b/src/main/java/org/jenkinsci/test/acceptance/controller/JBossController.java index fedf9298a3..d69023ec55 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/controller/JBossController.java +++ b/src/main/java/org/jenkinsci/test/acceptance/controller/JBossController.java @@ -11,7 +11,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; -import org.codehaus.plexus.util.FileUtils; +import java.nio.file.Files; +import org.apache.commons.io.FileUtils; import org.jenkinsci.test.acceptance.utils.IOUtil; import org.jenkinsci.utils.process.CommandBuilder; import org.jenkinsci.utils.process.ProcessInputStream; @@ -62,8 +63,8 @@ public ProcessInputStream startProcess() throws IOException { if (context.exists()) { org.apache.commons.io.FileUtils.forceDelete(context); } - org.apache.commons.io.FileUtils.write( - context, + Files.writeString( + context.toPath(), "\n" + " \n" + "", diff --git a/src/main/java/org/jenkinsci/test/acceptance/controller/JenkinsLogWatcher.java b/src/main/java/org/jenkinsci/test/acceptance/controller/JenkinsLogWatcher.java index d859cb410c..5274589b41 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/controller/JenkinsLogWatcher.java +++ b/src/main/java/org/jenkinsci/test/acceptance/controller/JenkinsLogWatcher.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Date; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -14,7 +15,6 @@ import java.util.concurrent.TimeoutException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.input.TeeInputStream; import org.jenkinsci.test.acceptance.log.LogListenable; import org.jenkinsci.test.acceptance.log.LogListener; @@ -110,7 +110,7 @@ private String failedToLoadMessage() { msg += "\nprocess is " + (reader.isAlive() ? "alive" : "dead"); msg += "\nnow = " + new Date(); try { - msg += "\n" + FileUtils.readFileToString(logFile, StandardCharsets.UTF_8); + msg += "\n" + Files.readString(logFile.toPath(), StandardCharsets.UTF_8); } catch (IOException ignored) { // ignore } diff --git a/src/main/java/org/jenkinsci/test/acceptance/controller/LocalController.java b/src/main/java/org/jenkinsci/test/acceptance/controller/LocalController.java index 0bd4545b48..73105f020b 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/controller/LocalController.java +++ b/src/main/java/org/jenkinsci/test/acceptance/controller/LocalController.java @@ -18,8 +18,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; import org.codehaus.plexus.util.Expand; -import org.codehaus.plexus.util.StringUtils; import org.jenkinsci.test.acceptance.junit.FailureDiagnostics; import org.jenkinsci.test.acceptance.log.LogListenable; import org.jenkinsci.test.acceptance.log.LogListener; @@ -148,7 +148,7 @@ public void populateJenkinsHome(byte[] _template, boolean clean) throws IOExcept } File template = File.createTempFile("template", ".dat"); try { - FileUtils.writeByteArrayToFile(template, _template); + Files.write(template.toPath(), _template); Expand expand = new Expand(); expand.setSrc(template); expand.setOverwrite(true); diff --git a/src/main/java/org/jenkinsci/test/acceptance/controller/TomcatController.java b/src/main/java/org/jenkinsci/test/acceptance/controller/TomcatController.java index 5a2cc099ac..348a01b063 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/controller/TomcatController.java +++ b/src/main/java/org/jenkinsci/test/acceptance/controller/TomcatController.java @@ -11,6 +11,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import org.apache.commons.io.FileUtils; import org.jenkinsci.test.acceptance.utils.IOUtil; import org.jenkinsci.utils.process.CommandBuilder; @@ -56,8 +57,8 @@ public ProcessInputStream startProcess() throws IOException { if (context.exists()) { FileUtils.forceDelete(context); } - FileUtils.write( - context, + Files.writeString( + context.toPath(), "\n" + " \n" + "", diff --git a/src/main/java/org/jenkinsci/test/acceptance/controller/WinstoneController.java b/src/main/java/org/jenkinsci/test/acceptance/controller/WinstoneController.java index 310808d6a6..b2f6c589b2 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/controller/WinstoneController.java +++ b/src/main/java/org/jenkinsci/test/acceptance/controller/WinstoneController.java @@ -8,11 +8,11 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.logging.Logger; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.jenkinsci.utils.process.CommandBuilder; import org.jenkinsci.utils.process.ProcessInputStream; @@ -60,7 +60,7 @@ public WinstoneController(Injector i, int httpPort) { @Override protected void onReady() throws IOException { if (this.httpPort == 0 && portFile != null) { - String s = FileUtils.readFileToString(portFile, StandardCharsets.UTF_8); + String s = Files.readString(portFile.toPath(), StandardCharsets.UTF_8); try { this.httpPort = Integer.parseInt(s); } catch (NumberFormatException e) { diff --git a/src/main/java/org/jenkinsci/test/acceptance/junit/FailureDiagnostics.java b/src/main/java/org/jenkinsci/test/acceptance/junit/FailureDiagnostics.java index 7c60b79d7c..013fabc3c8 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/junit/FailureDiagnostics.java +++ b/src/main/java/org/jenkinsci/test/acceptance/junit/FailureDiagnostics.java @@ -9,7 +9,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Stream; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.jenkinsci.test.acceptance.guice.TestName; import org.jenkinsci.test.acceptance.guice.TestScope; import org.junit.rules.TestWatcher; diff --git a/src/main/java/org/jenkinsci/test/acceptance/junit/Wait.java b/src/main/java/org/jenkinsci/test/acceptance/junit/Wait.java index 33a1727dfd..badfee38e9 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/junit/Wait.java +++ b/src/main/java/org/jenkinsci/test/acceptance/junit/Wait.java @@ -23,12 +23,12 @@ */ package org.jenkinsci.test.acceptance.junit; -import com.google.common.base.Function; import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.time.ZoneId; import java.util.concurrent.Callable; +import java.util.function.Function; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; import org.jenkinsci.test.acceptance.utils.ElasticTime; diff --git a/src/main/java/org/jenkinsci/test/acceptance/plugins/docker_build_step/DockerCommand.java b/src/main/java/org/jenkinsci/test/acceptance/plugins/docker_build_step/DockerCommand.java index 1639086f48..f269d879ed 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/plugins/docker_build_step/DockerCommand.java +++ b/src/main/java/org/jenkinsci/test/acceptance/plugins/docker_build_step/DockerCommand.java @@ -23,7 +23,6 @@ */ package org.jenkinsci.test.acceptance.plugins.docker_build_step; -import com.google.common.base.Joiner; import org.jenkinsci.test.acceptance.po.Describable; import org.jenkinsci.test.acceptance.po.PageAreaImpl; @@ -85,7 +84,7 @@ public RemoveContainers(DockerBuildStep area) { } public RemoveContainers containerIds(String... ids) { - control("containerIds").set(Joiner.on(',').join(ids)); + control("containerIds").set(String.join(",", ids)); return this; } } diff --git a/src/main/java/org/jenkinsci/test/acceptance/plugins/mock_security_realm/MockSecurityRealm.java b/src/main/java/org/jenkinsci/test/acceptance/plugins/mock_security_realm/MockSecurityRealm.java index ade38f2ab0..e79c9efaaa 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/plugins/mock_security_realm/MockSecurityRealm.java +++ b/src/main/java/org/jenkinsci/test/acceptance/plugins/mock_security_realm/MockSecurityRealm.java @@ -1,6 +1,6 @@ package org.jenkinsci.test.acceptance.plugins.mock_security_realm; -import org.codehaus.plexus.util.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.jenkinsci.test.acceptance.po.Control; import org.jenkinsci.test.acceptance.po.Describable; import org.jenkinsci.test.acceptance.po.GlobalSecurityConfig; diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/CapybaraPortingLayerImpl.java b/src/main/java/org/jenkinsci/test/acceptance/po/CapybaraPortingLayerImpl.java index 71bca5985f..44f5802a55 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/CapybaraPortingLayerImpl.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/CapybaraPortingLayerImpl.java @@ -1,6 +1,5 @@ package org.jenkinsci.test.acceptance.po; -import com.google.common.base.Joiner; import com.google.inject.Injector; import edu.umd.cs.findbugs.annotations.CheckForNull; import jakarta.inject.Inject; @@ -518,8 +517,8 @@ protected T find(String caption) { protected T findCaption(Class type, Finder call) { String[] captions = type.getAnnotation(Describable.class).value(); - RuntimeException cause = new NoSuchElementException( - "None of the captions exists: " + Joiner.on(", ").join(captions)); + RuntimeException cause = + new NoSuchElementException("None of the captions exists: " + String.join(", ", captions)); for (String caption : captions) { try { T out = call.find(caption); diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/Jenkins.java b/src/main/java/org/jenkinsci/test/acceptance/po/Jenkins.java index 13ca19340b..6ff40865cc 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/Jenkins.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/Jenkins.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Function; import com.google.inject.Injector; import hudson.util.VersionNumber; import java.io.FileOutputStream; @@ -15,6 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.logging.Level; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ObjectUtils; diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/PageObject.java b/src/main/java/org/jenkinsci/test/acceptance/po/PageObject.java index a5be5261d6..7807da0dc2 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/PageObject.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/PageObject.java @@ -1,7 +1,6 @@ package org.jenkinsci.test.acceptance.po; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Function; import com.google.inject.Injector; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -12,6 +11,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.function.Function; import org.kohsuke.randname.RandomNameGenerator; import org.openqa.selenium.By; import org.openqa.selenium.TimeoutException; diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/ToolInstallation.java b/src/main/java/org/jenkinsci/test/acceptance/po/ToolInstallation.java index 8540d199d2..55a99d7845 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/ToolInstallation.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/ToolInstallation.java @@ -26,9 +26,9 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.time.Duration; import java.util.concurrent.Callable; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.SystemUtils; import org.jenkinsci.utils.process.CommandBuilder; import org.openqa.selenium.NoSuchElementException; @@ -166,7 +166,7 @@ protected String fakeHome(String binary, String homeEnvName) { final String code = String.format("#!/bin/sh\nexport %s=\nexec %s \"$@\"\n", homeEnvName, path); final File command = new File(home, "bin/" + binary); - FileUtils.writeStringToFile(command, code, StandardCharsets.UTF_8); + Files.writeString(command.toPath(), code, StandardCharsets.UTF_8); command.setExecutable(true); } else { String path = @@ -175,7 +175,7 @@ protected String fakeHome(String binary, String homeEnvName) { path = path.replaceAll("\r\n.*", ""); final String code = String.format("set %s=\r\ncall %s %%*\r\n", homeEnvName, path); final File command = new File(home, "bin/" + binary + ".cmd"); - FileUtils.writeStringToFile(command, code, StandardCharsets.UTF_8); + Files.writeString(command.toPath(), code, StandardCharsets.UTF_8); command.setExecutable(true); } return home.getAbsolutePath(); diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/WizardLogin.java b/src/main/java/org/jenkinsci/test/acceptance/po/WizardLogin.java index abe786b033..b31a114a0a 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/WizardLogin.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/WizardLogin.java @@ -32,7 +32,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.apache.commons.io.FileUtils; +import java.nio.file.Files; import org.jenkinsci.test.acceptance.controller.JenkinsController; import org.jenkinsci.test.acceptance.controller.LocalController; import org.junit.Assume; @@ -90,6 +90,6 @@ public String getPassword(JenkinsController controller) throws IOException { controller, instanceOf(LocalController.class)); File passwordFile = new File(((LocalController) controller).getJenkinsHome(), "secrets/initialAdminPassword"); - return FileUtils.readFileToString(passwordFile, StandardCharsets.UTF_8).trim(); + return Files.readString(passwordFile.toPath(), StandardCharsets.UTF_8).trim(); } } diff --git a/src/test/java/plugins/AuthorizeProjectTest.java b/src/test/java/plugins/AuthorizeProjectTest.java index 4926006490..140512788b 100644 --- a/src/test/java/plugins/AuthorizeProjectTest.java +++ b/src/test/java/plugins/AuthorizeProjectTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import com.google.common.base.Joiner; import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest; import org.jenkinsci.test.acceptance.junit.WithPlugins; import org.jenkinsci.test.acceptance.plugins.authorize_project.ProjectDefaultBuildAccessControl; @@ -61,7 +60,7 @@ public void testProjectRunByUser() { private void setupUsers(final GlobalSecurityConfig security, final String... users) { final MockSecurityRealm realm = security.useRealm(MockSecurityRealm.class); - realm.configure(Joiner.on("\n").join(users)); + realm.configure(String.join("\n", users)); } private void authorizeUserToLaunchProject(final String user) { diff --git a/src/test/java/plugins/GerritTriggerTest.java b/src/test/java/plugins/GerritTriggerTest.java index 5853bd318f..867517b7f4 100644 --- a/src/test/java/plugins/GerritTriggerTest.java +++ b/src/test/java/plugins/GerritTriggerTest.java @@ -50,7 +50,6 @@ import java.util.logging.SimpleFormatter; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest; import org.jenkinsci.test.acceptance.junit.TestActivation; @@ -151,8 +150,8 @@ public void setupSSHWrapper() throws IOException { ssh = File.createTempFile("jenkins", "ssh"); ssh.deleteOnExit(); - FileUtils.writeStringToFile( - ssh, + Files.writeString( + ssh.toPath(), "#!/bin/sh\n" + "exec ssh -o StrictHostKeyChecking=no -i " + gtPrivateKey + " \"$@\"", StandardCharsets.UTF_8); Files.setPosixFilePermissions( diff --git a/src/test/java/plugins/JabberPluginTest.java b/src/test/java/plugins/JabberPluginTest.java index 4b153fd1a9..07396b422e 100644 --- a/src/test/java/plugins/JabberPluginTest.java +++ b/src/test/java/plugins/JabberPluginTest.java @@ -7,7 +7,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.apache.commons.io.FileUtils; +import java.nio.file.Files; import org.jenkinsci.test.acceptance.docker.DockerContainerHolder; import org.jenkinsci.test.acceptance.docker.fixtures.JabberContainer; import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest; @@ -95,6 +95,6 @@ public void jabber_notification_success_publishing() throws IOException, Interru j.startBuild().shouldSucceed(); sleep(20000); File logfile = jabber.getLogbotLogFile(); - assertThat(FileUtils.readFileToString(logfile, StandardCharsets.UTF_8), containsString("SUCCESS")); + assertThat(Files.readString(logfile.toPath(), StandardCharsets.UTF_8), containsString("SUCCESS")); } }