diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/WriteYamlStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/WriteYamlStep.java index afeb55b8..6f8729c0 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/WriteYamlStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/WriteYamlStep.java @@ -39,6 +39,7 @@ import java.io.*; import java.net.URL; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.FileAlreadyExistsException; import java.util.*; @@ -309,7 +310,7 @@ protected Void run () throws Exception { Charset cs; if (StringUtils.isEmpty(step.getCharset())) { - cs = Charset.forName("UTF-8"); //If it doesn't exist then something is broken in the jvm + cs = StandardCharsets.UTF_8; //If it doesn't exist then something is broken in the jvm } else { cs = Charset.forName(step.getCharset()); //Will throw stuff directly to the user } diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/mf/ReadManifestStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/mf/ReadManifestStepExecution.java index b3a8c4c5..d976bf07 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/mf/ReadManifestStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/mf/ReadManifestStepExecution.java @@ -36,6 +36,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.jar.Manifest; @@ -69,7 +70,7 @@ protected SimpleManifest doRun() throws Exception { } private SimpleManifest parseText(String text) throws IOException { - Manifest manifest = new Manifest(new ByteArrayInputStream(text.getBytes("UTF-8"))); + Manifest manifest = new Manifest(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8))); return new SimpleManifest(manifest); } diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/csv/WriteCSVStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/csv/WriteCSVStepExecution.java index 2768568f..f99b7b00 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/csv/WriteCSVStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/csv/WriteCSVStepExecution.java @@ -29,6 +29,7 @@ import hudson.FilePath; import java.io.FileNotFoundException; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import org.apache.commons.lang.StringUtils; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution; @@ -68,7 +69,7 @@ protected Void run() throws Exception { throw new FileNotFoundException(Messages.CSVStepExecution_fileIsDirectory(path.getRemote())); } - try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), "UTF-8")) { + try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), StandardCharsets.UTF_8)) { CSVFormat format = step.getFormat(); if (format == null) { format = CSVFormat.DEFAULT; diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FileHashStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FileHashStep.java index c30fac39..e1c37892 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FileHashStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/FileHashStep.java @@ -3,9 +3,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import hudson.FilePath; import hudson.model.Descriptor; -import hudson.remoting.VirtualChannel; import hudson.util.FormValidation; -import jenkins.MasterToSlaveFileCallable; import org.apache.commons.lang.StringUtils; import org.jenkinsci.plugins.workflow.steps.Step; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -14,15 +12,7 @@ import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution; import org.kohsuke.stapler.QueryParameter; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.Collections; -import java.util.Formatter; import java.util.Locale; import java.util.Set; diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepExecution.java index 6e899ea6..34123444 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepExecution.java @@ -38,6 +38,7 @@ import java.io.FileNotFoundException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -74,7 +75,7 @@ protected Object doRun() throws Exception { FilePath f = ws.child(step.getFile()); if (f.exists() && !f.isDirectory()) { try (InputStream is = f.read()) { - json = JSONSerializer.toJSON(IOUtils.toString(is, "UTF-8")); + json = JSONSerializer.toJSON(IOUtils.toString(is, StandardCharsets.UTF_8)); } } else if (f.isDirectory()) { throw new IllegalArgumentException(Messages.JSONStepExecution_fileIsDirectory(f.getRemote())); diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepExecution.java index 0d67c15a..358f3f3c 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepExecution.java @@ -32,6 +32,7 @@ import java.io.FileNotFoundException; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; /** * Execution of {@link WriteJSONStep}. @@ -61,7 +62,7 @@ protected Void run() throws Exception { throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote())); } - try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), "UTF-8")) { + try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), StandardCharsets.UTF_8)) { step.execute(writer); } return null; diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java index 93c2e68f..17d0dc25 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/UnZipStepExecution.java @@ -130,7 +130,7 @@ public Map invoke(File zipFile, VirtualChannel channel) throws I } PrintStream logger = listener.getLogger(); boolean doGlob = !StringUtils.isBlank(glob); - Map strMap = new TreeMap(); + Map strMap = new TreeMap<>(); try (ZipFile zip = new ZipFile(zipFile, Charset.forName(charset))) { logger.println("Extracting from " + zipFile.getAbsolutePath()); Enumeration entries = zip.entries(); diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/ZipStepExecution.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/ZipStepExecution.java index a66fd323..87604bff 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/ZipStepExecution.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/zip/ZipStepExecution.java @@ -93,7 +93,7 @@ protected Void run() throws Exception { int count = source.act(new ZipItFileCallable(destination, step.getGlob(), step.getExclude(), step.isOverwrite())); listener.getLogger().println("Zipped " + count + " entries."); if (step.isArchive()) { - Run build = getContext().get(Run.class); + Run build = getContext().get(Run.class); if (build == null) { throw new MissingContextVariableException(Run.class); } @@ -102,7 +102,7 @@ protected Void run() throws Exception { throw new MissingContextVariableException(Launcher.class); } listener.getLogger().println("Archiving " + destination.getRemote()); - Map files = new HashMap(); + Map files = new HashMap<>(); String s = step.getZipFile().replace('\\', '/'); files.put(s, s); build.pickArtifactManager().archive(ws, launcher, new BuildListenerAdapter(listener), files); diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/CompareVersionsStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/CompareVersionsStepTest.java index 44c32324..c261f850 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/CompareVersionsStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/CompareVersionsStepTest.java @@ -37,7 +37,7 @@ import java.util.List; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class CompareVersionsStepTest { @Rule diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/ReadCSVStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/ReadCSVStepTest.java index 3dcff087..d672d641 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/ReadCSVStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/ReadCSVStepTest.java @@ -140,14 +140,14 @@ public void readFileWithFormat() throws Exception { j.assertBuildStatusSuccess(p.scheduleBuild2(0)); } - private String getCSV(char separator) throws IOException { + private String getCSV(char separator) { String line0 = String.join(String.valueOf(separator), "key", "value", "attr"); String line1 = String.join(String.valueOf(separator), "a", "b", "c"); String line2 = String.join(String.valueOf(separator), "1", "2", "3"); return String.join("\n", line0, line1, line2); } - private String getCSV() throws IOException { + private String getCSV() { return getCSV(','); } diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/WriteCSVStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/WriteCSVStepTest.java index e149d429..cde6bd9e 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/WriteCSVStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/csv/WriteCSVStepTest.java @@ -69,7 +69,7 @@ public void writeFile() throws Exception { j.assertBuildStatusSuccess(p.scheduleBuild2(0)); // file exists by default so we check that should not be empty - assertThat(output.length(), greaterThan(0l)); + assertThat(output.length(), greaterThan(0L)); String lines = new String(Files.readAllBytes(Paths.get(output.toURI()))); assertThat(lines.split("\r\n|\r|\n").length, equalTo(3)); @@ -114,7 +114,7 @@ public void writeFileWithHeader() throws Exception { j.assertBuildStatusSuccess(p.scheduleBuild2(0)); // file exists by default so we check that should not be empty - assertThat(output.length(), greaterThan(0l)); + assertThat(output.length(), greaterThan(0L)); String lines = new String(Files.readAllBytes(Paths.get(output.toURI()))); assertThat(lines.split("\r\n|\r|\n").length, equalTo(3)); diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TeeStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TeeStepTest.java index 9e6cbbf1..f1997f3b 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TeeStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TeeStepTest.java @@ -38,6 +38,7 @@ import org.junit.Rule; import org.jvnet.hudson.test.BuildWatcher; import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.JenkinsSessionRule; import static org.hamcrest.MatcherAssert.assertThat; @@ -77,7 +78,7 @@ public void smokes() throws Throwable { SemaphoreStep.success("wait/1", null); WorkflowRun b = r.jenkins.getItemByFullName("p", WorkflowJob.class).getBuildByNumber(1); r.assertBuildStatus(Result.SUCCESS, r.waitForCompletion(b)); - assertThat(r.getLog(b), stringContainsInOrder("got: first message second message", Functions.isWindows() ? "WS>rem" : "+ true")); + assertThat(JenkinsRule.getLog(b), stringContainsInOrder("got: first message second message", Functions.isWindows() ? "WS>rem" : "+ true")); }); } diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStepTest.java index c9ad473c..53b6ca0a 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/fs/TouchStepTest.java @@ -50,7 +50,7 @@ public void setup() throws Exception { @Test public void configRoundTrip() throws Exception { TouchStep step = new TouchStep("target/my.tag"); - step.setTimestamp(10000l); + step.setTimestamp(10000L); TouchStep step2 = new StepConfigTester(j).configRoundTrip(step); j.assertEqualDataBoundBeans(step, step2); diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepTest.java index c4e734b6..ef7478f0 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/ReadJSONStepTest.java @@ -130,7 +130,7 @@ public void readFileAndText() throws Exception { j.assertLogContains(Messages.ReadJSONStepExecution_tooManyArguments("readJSON"), run); } - private String getJSON() throws IOException { + private String getJSON() { JSONArray tags = new JSONArray(); for (int i = 0; i < 3; i++) { tags.add(i); diff --git a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepTest.java b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepTest.java index 004c7a97..e02bcc18 100644 --- a/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/pipeline/utility/steps/json/WriteJSONStepTest.java @@ -34,7 +34,6 @@ import static org.junit.Assert.assertNotNull; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -116,7 +115,7 @@ public void writeFile() throws Exception { j.assertBuildStatusSuccess(p.scheduleBuild2(0)); // file exists by default so we check that should not be empty - assertThat(output.length(), greaterThan(0l)); + assertThat(output.length(), greaterThan(0L)); String jsonResult = new String(Files.readAllBytes(Paths.get(output.toURI()))); JSON json = JSONSerializer.toJSON(jsonResult); @@ -187,7 +186,7 @@ public void checkCannotReturnTextAndFile() throws Exception { j.assertLogContains(Messages.WriteJSONStepExecution_bothReturnTextAndFile("writeJSON"), run); } - private String getJSON(int elements) throws IOException { + private String getJSON(int elements) { JSONArray root = new JSONArray(); for (int i = 0; i < elements; i++) { JSONObject jsonElement = new JSONObject(); @@ -197,4 +196,4 @@ private String getJSON(int elements) throws IOException { return root.toString(); } -} \ No newline at end of file +}