Skip to content

Commit c2cc168

Browse files
bborttchristophd
authored andcommitted
fix: replace string concatenations and formatted strings with log patterns
originates from #1498.
1 parent b5744ab commit c2cc168

File tree

112 files changed

+868
-818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+868
-818
lines changed

connectors/citrus-docker/src/main/java/org/citrusframework/docker/actions/DockerExecuteAction.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,22 @@
2626
import org.citrusframework.actions.docker.DockerActionBuilder;
2727
import org.citrusframework.context.TestContext;
2828
import org.citrusframework.docker.client.DockerClient;
29-
import org.citrusframework.docker.command.*;
29+
import org.citrusframework.docker.command.AbstractDockerCommandBuilder;
30+
import org.citrusframework.docker.command.ContainerCreate;
31+
import org.citrusframework.docker.command.ContainerInspect;
32+
import org.citrusframework.docker.command.ContainerRemove;
33+
import org.citrusframework.docker.command.ContainerStart;
34+
import org.citrusframework.docker.command.ContainerStop;
35+
import org.citrusframework.docker.command.ContainerWait;
36+
import org.citrusframework.docker.command.DockerCommand;
37+
import org.citrusframework.docker.command.ImageBuild;
38+
import org.citrusframework.docker.command.ImageInspect;
39+
import org.citrusframework.docker.command.ImagePull;
40+
import org.citrusframework.docker.command.ImageRemove;
41+
import org.citrusframework.docker.command.Info;
42+
import org.citrusframework.docker.command.Ping;
43+
import org.citrusframework.docker.command.StaticDockerCommandBuilder;
44+
import org.citrusframework.docker.command.Version;
3045
import org.citrusframework.exceptions.CitrusRuntimeException;
3146
import org.citrusframework.exceptions.ValidationException;
3247
import org.citrusframework.message.DefaultMessage;
@@ -44,24 +59,33 @@
4459
*/
4560
public class DockerExecuteAction extends AbstractTestAction {
4661

47-
/** Docker client instance */
62+
/**
63+
* Docker client instance
64+
*/
4865
private final DockerClient dockerClient;
4966

50-
/** Docker command to execute */
67+
/**
68+
* Docker command to execute
69+
*/
5170
private final DockerCommand<?> command;
5271

53-
/** Expected command result for validation */
72+
/**
73+
* Expected command result for validation
74+
*/
5475
private final String expectedCommandResult;
5576

56-
/** JSON data binding */
77+
/**
78+
* JSON data binding
79+
*/
5780
private final ObjectMapper jsonMapper;
5881

59-
/** Validator used to validate expected json results */
82+
/**
83+
* Validator used to validate expected json results
84+
*/
6085
private final MessageValidator<? extends ValidationContext> jsonMessageValidator;
6186

6287
public static final String DEFAULT_JSON_MESSAGE_VALIDATOR = "defaultJsonMessageValidator";
6388

64-
/** Logger */
6589
private static final Logger logger = LoggerFactory.getLogger(DockerExecuteAction.class);
6690

6791
/**
@@ -81,13 +105,13 @@ public DockerExecuteAction(Builder builder) {
81105
public void doExecute(TestContext context) {
82106
try {
83107
if (logger.isDebugEnabled()) {
84-
logger.debug(String.format("Executing Docker command '%s'", command.getName()));
108+
logger.debug("Executing Docker command '{}'", command.getName());
85109
}
86110
command.execute(dockerClient, context);
87111

88112
validateCommandResult(command, context);
89113

90-
logger.info(String.format("Docker command execution successful: '%s'", command.getName()));
114+
logger.info("Docker command execution successful: '{}'", command.getName());
91115
} catch (CitrusRuntimeException e) {
92116
throw e;
93117
} catch (Exception e) {
@@ -97,8 +121,6 @@ public void doExecute(TestContext context) {
97121

98122
/**
99123
* Validate command results.
100-
* @param command
101-
* @param context
102124
*/
103125
private void validateCommandResult(DockerCommand command, TestContext context) {
104126
logger.debug("Starting Docker command result validation");
@@ -125,8 +147,6 @@ private void validateCommandResult(DockerCommand command, TestContext context) {
125147

126148
/**
127149
* Find proper JSON message validator. Uses several strategies to lookup default JSON message validator.
128-
* @param context
129-
* @return
130150
*/
131151
private MessageValidator<? extends ValidationContext> getMessageValidator(TestContext context) {
132152
if (jsonMessageValidator != null) {
@@ -155,23 +175,20 @@ private MessageValidator<? extends ValidationContext> getMessageValidator(TestCo
155175

156176
/**
157177
* Gets the docker command to execute.
158-
* @return
159178
*/
160179
public DockerCommand<?> getCommand() {
161180
return command;
162181
}
163182

164183
/**
165184
* Gets the docker client.
166-
* @return
167185
*/
168186
public DockerClient getDockerClient() {
169187
return dockerClient;
170188
}
171189

172190
/**
173191
* Gets the expected command result data.
174-
* @return
175192
*/
176193
public String getExpectedCommandResult() {
177194
return expectedCommandResult;
@@ -191,7 +208,6 @@ public static class Builder extends AbstractTestActionBuilder<DockerExecuteActio
191208

192209
/**
193210
* Fluent API action building entry method used in Java DSL.
194-
* @return
195211
*/
196212
public static Builder docker() {
197213
return new Builder();

connectors/citrus-docker/src/main/java/org/citrusframework/docker/client/DockerClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.citrusframework.docker.client;
1818

19-
import java.util.Objects;
20-
2119
import org.citrusframework.context.TestContext;
2220
import org.citrusframework.docker.command.DockerCommand;
2321
import org.citrusframework.endpoint.AbstractEndpoint;
@@ -32,17 +30,20 @@
3230
import org.slf4j.Logger;
3331
import org.slf4j.LoggerFactory;
3432

33+
import java.util.Objects;
34+
3535
/**
3636
* Docker client uses Java docker client implementation for executing docker commands.
3737
*
3838
* @since 2.4
3939
*/
4040
public class DockerClient extends AbstractEndpoint implements Producer, ReplyConsumer {
4141

42-
/** Logger */
4342
private static final Logger logger = LoggerFactory.getLogger(DockerClient.class);
4443

45-
/** Store of reply messages */
44+
/**
45+
* Store of reply messages
46+
*/
4647
private CorrelationManager<DockerCommand> correlationManager;
4748

4849
/**
@@ -54,7 +55,6 @@ public DockerClient() {
5455

5556
/**
5657
* Default constructor using endpoint configuration.
57-
* @param endpointConfiguration
5858
*/
5959
public DockerClient(DockerEndpointConfiguration endpointConfiguration) {
6060
super(endpointConfiguration);
@@ -74,13 +74,13 @@ public void send(Message message, TestContext context) {
7474
correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context);
7575

7676
if (logger.isDebugEnabled()) {
77-
logger.debug("Sending Docker request to: '" + getEndpointConfiguration().getDockerClientConfig().getDockerHost() + "'");
77+
logger.debug("Sending Docker request to: '{}'", getEndpointConfiguration().getDockerClientConfig().getDockerHost());
7878
}
7979

8080
DockerCommand command = message.getPayload(DockerCommand.class);
8181
command.execute(this, context);
8282

83-
logger.info("Docker request was sent to endpoint: '" + getEndpointConfiguration().getDockerClientConfig().getDockerHost() + "'");
83+
logger.info("Docker request was sent to endpoint: '{}'", getEndpointConfiguration().getDockerClientConfig().getDockerHost());
8484

8585
correlationManager.store(correlationKey, command);
8686

connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/CitrusJBang.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
package org.citrusframework.jbang;
1818

19+
import org.citrusframework.exceptions.CitrusRuntimeException;
20+
import org.citrusframework.util.StringUtils;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
1924
import java.io.BufferedReader;
2025
import java.io.ByteArrayInputStream;
2126
import java.io.File;
@@ -31,14 +36,8 @@
3136
import java.util.Map;
3237
import java.util.Optional;
3338

34-
import org.citrusframework.exceptions.CitrusRuntimeException;
35-
import org.citrusframework.util.StringUtils;
36-
import org.slf4j.Logger;
37-
import org.slf4j.LoggerFactory;
38-
3939
public class CitrusJBang {
4040

41-
/** Logger */
4241
private static final Logger logger = LoggerFactory.getLogger(CitrusJBang.class);
4342

4443
private final JBangSupport app;
@@ -55,7 +54,7 @@ public CitrusJBang(String app) {
5554

5655
String version = version();
5756
if (logger.isDebugEnabled()) {
58-
logger.debug("Citrus JBang version: " + version);
57+
logger.debug("Citrus JBang version: {}", version);
5958
}
6059
}
6160

connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/JBangSupport.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
package org.citrusframework.jbang;
1818

19+
import org.citrusframework.exceptions.CitrusRuntimeException;
20+
import org.citrusframework.util.FileUtils;
21+
import org.citrusframework.util.StringUtils;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
1925
import java.io.File;
2026
import java.io.FileInputStream;
2127
import java.io.IOException;
@@ -45,12 +51,6 @@
4551
import java.util.zip.ZipEntry;
4652
import java.util.zip.ZipInputStream;
4753

48-
import org.citrusframework.exceptions.CitrusRuntimeException;
49-
import org.citrusframework.util.FileUtils;
50-
import org.citrusframework.util.StringUtils;
51-
import org.slf4j.Logger;
52-
import org.slf4j.LoggerFactory;
53-
5454
/**
5555
* Support class prepares JBang executable and runs commands via spawned process using the JBang binary.
5656
*/
@@ -279,12 +279,12 @@ private static void download() {
279279
Path installPath = Paths.get(System.getProperty("user.home")).toAbsolutePath().resolve(".jbang").toAbsolutePath();
280280

281281
if (installPath.resolve(homePath).toFile().exists()) {
282-
LOG.info("Using local JBang in " + installPath);
282+
LOG.info("Using local JBang in {}", installPath);
283283
installDir = installPath.resolve(homePath);
284284
return;
285285
}
286286

287-
LOG.info("Downloading JBang from " + JBangSettings.getJBangDownloadUrl() + " and installing in " + installPath);
287+
LOG.info("Downloading JBang from {} and installing in {}", JBangSettings.getJBangDownloadUrl(), installPath);
288288

289289
try {
290290
Files.createDirectories(installPath);
@@ -432,7 +432,7 @@ private static ProcessAndOutput execute(List<String> command, Path workingDir,
432432
}
433433

434434
if (LOG.isDebugEnabled() && p.exitValue() != OK_EXIT_CODE) {
435-
LOG.debug("Command failed: " + String.join(" ", command));
435+
LOG.debug("Command failed: {}", String.join(" ", command));
436436
LOG.debug(output);
437437
}
438438

connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/ProcessAndOutput.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
package org.citrusframework.jbang;
1818

19+
import org.awaitility.core.ConditionTimeoutException;
20+
import org.citrusframework.exceptions.CitrusRuntimeException;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
1924
import java.io.BufferedReader;
2025
import java.io.File;
2126
import java.io.FileInputStream;
@@ -26,11 +31,6 @@
2631
import java.util.List;
2732
import java.util.stream.Collectors;
2833

29-
import org.awaitility.core.ConditionTimeoutException;
30-
import org.citrusframework.exceptions.CitrusRuntimeException;
31-
import org.slf4j.Logger;
32-
import org.slf4j.LoggerFactory;
33-
3434
/**
3535
* Process wrapper also holds the output that has been produced by the completed process.
3636
*/
@@ -182,7 +182,7 @@ public List<Long> getDescendants() {
182182
return process.descendants()
183183
.peek(p -> {
184184
if (LOG.isDebugEnabled()) {
185-
LOG.info(String.format("Found descendant process (pid:%d) for process '%d'", p.pid(), getProcessId()));
185+
LOG.info("Found descendant process (pid:{}) for process '{}'", p.pid(), getProcessId());
186186
}
187187
})
188188
.map(ProcessHandle::pid)

connectors/citrus-jbang-connector/src/main/java/org/citrusframework/jbang/engine/JBangTestEngine.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616

1717
package org.citrusframework.jbang.engine;
1818

19-
import java.awt.*;
20-
import java.awt.datatransfer.Clipboard;
21-
import java.awt.datatransfer.StringSelection;
22-
import java.io.File;
23-
import java.io.IOException;
24-
import java.nio.file.Path;
25-
import java.util.Collections;
26-
import java.util.List;
27-
import java.util.Optional;
28-
import java.util.stream.Collectors;
29-
3019
import org.citrusframework.CitrusSettings;
3120
import org.citrusframework.TestSource;
3221
import org.citrusframework.exceptions.CitrusRuntimeException;
@@ -39,6 +28,17 @@
3928
import org.citrusframework.util.FileUtils;
4029
import org.citrusframework.util.StringUtils;
4130

31+
import java.awt.*;
32+
import java.awt.datatransfer.Clipboard;
33+
import java.awt.datatransfer.StringSelection;
34+
import java.io.File;
35+
import java.io.IOException;
36+
import java.nio.file.Path;
37+
import java.util.Collections;
38+
import java.util.List;
39+
import java.util.Optional;
40+
import java.util.stream.Collectors;
41+
4242
/**
4343
* Test engine implementation runs tests via Citrus JBang as a separate JVM process.
4444
*/
@@ -90,10 +90,9 @@ private void runTestPackages(CitrusJBang citrus, TestRunConfiguration configurat
9090

9191
for (String packageName : packagesToRun) {
9292
if (StringUtils.hasText(packageName)) {
93-
logger.info(String.format("Running tests in directory %s", packageName));
93+
logger.info("Running tests in directory {}", packageName);
9494
} else {
95-
logger.info(String.format("Running tests in current working directory %s",
96-
Optional.ofNullable(workingDir).map(Path::toString).orElse(".")));
95+
logger.info("Running tests in current working directory {}", Optional.ofNullable(workingDir).map(Path::toString).orElse("."));
9796
}
9897

9998
citrus.run(packageName, Collections.emptyMap());
@@ -106,7 +105,7 @@ private void runTestSources(CitrusJBang citrus, TestRunConfiguration configurati
106105
.toList();
107106

108107
for (TestSource directory : directories) {
109-
logger.info(String.format("Running tests in directory %s", directory.getName()));
108+
logger.info("Running tests in directory {}", directory.getName());
110109
citrus.run(directory.getFilePath(), Collections.emptyMap());
111110
}
112111

@@ -116,7 +115,7 @@ private void runTestSources(CitrusJBang citrus, TestRunConfiguration configurati
116115

117116
for (TestSource source : sources) {
118117
try {
119-
logger.info(String.format("Running test source %s", source.getName()));
118+
logger.info("Running test source {}", source.getName());
120119

121120
if (source.getSourceFile() instanceof Resources.ByteArrayResource) {
122121
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();

0 commit comments

Comments
 (0)