From 5c419b372a9eedfe3f8d950d260af5faab9f0b87 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Tue, 20 Aug 2024 10:31:07 +0200 Subject: [PATCH] Fix code issues in exec package (#169) ## Description Fix few issues in exec package in logging etc... ## Type of Change Please delete options that are not relevant. * Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit/integration tests pass locally with my changes Signed-off-by: David Kornel --- .../java/io/skodjob/testframe/executor/Exec.java | 6 +++--- .../io/skodjob/testframe/executor/ExecResult.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/executor/Exec.java b/test-frame-common/src/main/java/io/skodjob/testframe/executor/Exec.java index ccba1d8..a2d05de 100644 --- a/test-frame-common/src/main/java/io/skodjob/testframe/executor/Exec.java +++ b/test-frame-common/src/main/java/io/skodjob/testframe/executor/Exec.java @@ -45,7 +45,7 @@ public class Exec { private static final Pattern ERROR_PATTERN = Pattern.compile("Error from server \\(([a-zA-Z0-9]+)\\):"); private static final Pattern INVALID_PATTERN = Pattern .compile("The ([a-zA-Z0-9]+) \"([a-z0-9.-]+)\" is invalid:"); - private static final Pattern PATH_SPLITTER = Pattern.compile(System.getProperty("path.separator")); + private static final Pattern PATH_SPLITTER = Pattern.compile(File.pathSeparator); private static final int MAXIMUM_EXEC_LOG_CHARACTER_SIZE = 2000; private static final Object LOCK = new Object(); @@ -271,7 +271,7 @@ public static ExecResult exec(String input, List command, Set en */ public int execute(String input, List commands, Set envVars, long timeoutMs) throws IOException, InterruptedException, ExecutionException { - LOGGER.trace("Running command - " + join(" ", commands.toArray(new String[0]))); + LOGGER.trace("Running command - {}", join(" ", commands.toArray(new String[0]))); ProcessBuilder builder = new ProcessBuilder(); builder.command(commands); if (envVars != null) { @@ -432,7 +432,7 @@ public Future read() { while (scanner.hasNextLine()) { data.append(scanner.nextLine()); if (appendLineSeparator) { - data.append(System.getProperty("line.separator")); + data.append(System.lineSeparator()); } } scanner.close(); diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/executor/ExecResult.java b/test-frame-common/src/main/java/io/skodjob/testframe/executor/ExecResult.java index 80635c3..fb5773a 100644 --- a/test-frame-common/src/main/java/io/skodjob/testframe/executor/ExecResult.java +++ b/test-frame-common/src/main/java/io/skodjob/testframe/executor/ExecResult.java @@ -4,6 +4,7 @@ */ package io.skodjob.testframe.executor; +import java.io.Serial; import java.io.Serializable; /** @@ -11,6 +12,7 @@ */ public class ExecResult implements Serializable { + @Serial private static final long serialVersionUID = 1L; /** @@ -84,11 +86,9 @@ public String err() { */ @Override public String toString() { - final StringBuilder sb = new StringBuilder("ExecResult{"); - sb.append("returnCode=").append(returnCode); - sb.append(", stdOut='").append(stdOut).append('\''); - sb.append(", stdErr='").append(stdErr).append('\''); - sb.append('}'); - return sb.toString(); + return "ExecResult{" + "returnCode=" + returnCode + + ", stdOut='" + stdOut + '\'' + + ", stdErr='" + stdErr + '\'' + + '}'; } }