Skip to content

Commit bcf1026

Browse files
committed
Remove compile time dependency to slf4j
This commit removes the compile time dependency to slf4j in favor of apache commons-logging (which is transitively coming from Spring Framework) and adds log4j as a test dependency where needed. Resolves #1214
1 parent c4f86aa commit bcf1026

File tree

46 files changed

+283
-258
lines changed

Some content is hidden

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

46 files changed

+283
-258
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
<jline.version>3.30.6</jline.version>
5555
<antlr-st4.version>4.3.4</antlr-st4.version>
5656
<commons-io.version>2.20.0</commons-io.version>
57-
<slf4j.version>2.0.17</slf4j.version>
5857
<jakarta.validation-api.version>3.1.1</jakarta.validation-api.version>
5958
<errorprone.version>2.42.0</errorprone.version>
6059
<nullaway.version>0.12.10</nullaway.version>
@@ -68,6 +67,7 @@
6867
<awaitility.version>4.3.0</awaitility.version>
6968
<hibernate-validator.version>9.0.1.Final</hibernate-validator.version>
7069
<jakarta.el.version>4.0.2</jakarta.el.version>
70+
<log4j.version>2.25.2</log4j.version>
7171

7272
<!-- documentation dependencies -->
7373
<antora-maven-plugin.version>1.0.0-alpha.5</antora-maven-plugin.version>

spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/LineReaderAutoConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.jline.utils.AttributedString;
3030
import org.jline.utils.AttributedStringBuilder;
3131
import org.jline.utils.AttributedStyle;
32-
import org.slf4j.Logger;
33-
import org.slf4j.LoggerFactory;
32+
import org.apache.commons.logging.Log;
33+
import org.apache.commons.logging.LogFactory;
3434

3535
import org.springframework.beans.factory.annotation.Value;
3636
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -50,7 +50,7 @@
5050
@EnableConfigurationProperties(SpringShellProperties.class)
5151
public class LineReaderAutoConfiguration {
5252

53-
private final static Logger log = LoggerFactory.getLogger(LineReaderAutoConfiguration.class);
53+
private final static Log log = LogFactory.getLog(LineReaderAutoConfiguration.class);
5454

5555
private Terminal terminal;
5656

@@ -129,14 +129,14 @@ public void setErrorIndex(int errorIndex) {
129129
if (this.springShellProperties.getHistory().isEnabled()) {
130130
// Discover history location
131131
Path userConfigPath = this.userConfigPathProvider.provide();
132-
log.debug("Resolved userConfigPath {}", userConfigPath);
132+
log.debug("Resolved userConfigPath " + userConfigPath);
133133
String historyFileName = this.springShellProperties.getHistory().getName();
134134
if (!StringUtils.hasText(historyFileName)) {
135135
historyFileName = fallbackHistoryFileName;
136136
}
137-
log.debug("Resolved historyFileName {}", historyFileName);
137+
log.debug("Resolved historyFileName " + historyFileName);
138138
String historyPath = userConfigPath.resolve(historyFileName).toAbsolutePath().toString();
139-
log.debug("Resolved historyPath {}", historyPath);
139+
log.debug("Resolved historyPath " + historyPath);
140140
// set history file
141141
lineReader.setVariable(LineReader.HISTORY_FILE, Paths.get(historyPath));
142142
}

spring-shell-autoconfigure/src/test/java/org/springframework/shell/boot/UserConfigAutoConfigurationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.nio.file.Path;
1919

2020
import org.junit.jupiter.api.Test;
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
21+
import org.apache.commons.logging.Log;
22+
import org.apache.commons.logging.LogFactory;
2323

2424
import org.springframework.boot.autoconfigure.AutoConfigurations;
2525
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -29,7 +29,7 @@
2929

3030
class UserConfigAutoConfigurationTests {
3131

32-
private static final Logger log = LoggerFactory.getLogger(UserConfigAutoConfigurationTests.class);
32+
private static final Log log = LogFactory.getLog(UserConfigAutoConfigurationTests.class);
3333

3434
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
3535
.withConfiguration(AutoConfigurations.of(UserConfigAutoConfiguration.class));
@@ -41,7 +41,7 @@ void testDefaults() {
4141
UserConfigPathProvider provider = context.getBean(UserConfigPathProvider.class);
4242
Path path = provider.provide();
4343
assertThat(path).isNotNull();
44-
log.info("Path testDefaults: {}", path.toAbsolutePath());
44+
log.info("Path testDefaults: " + path.toAbsolutePath());
4545
});
4646
}
4747

@@ -52,7 +52,7 @@ void testUserConfig() {
5252
UserConfigPathProvider provider = context.getBean(UserConfigPathProvider.class);
5353
Path path = provider.provide();
5454
assertThat(path).isNotNull();
55-
log.info("Path testUserConfig: {}", path.toAbsolutePath());
55+
log.info("Path testUserConfig: " + path.toAbsolutePath());
5656
});
5757
}
5858

spring-shell-core/pom.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@
6161
<artifactId>commons-io</artifactId>
6262
<version>${commons-io.version}</version>
6363
</dependency>
64-
<dependency>
65-
<groupId>org.slf4j</groupId>
66-
<artifactId>slf4j-api</artifactId>
67-
<version>${slf4j.version}</version>
68-
</dependency>
6964
<dependency>
7065
<groupId>jakarta.validation</groupId>
7166
<artifactId>jakarta.validation-api</artifactId>
@@ -133,9 +128,9 @@
133128
<scope>test</scope>
134129
</dependency>
135130
<dependency>
136-
<groupId>org.slf4j</groupId>
137-
<artifactId>slf4j-simple</artifactId>
138-
<version>${slf4j.version}</version>
131+
<groupId>org.apache.logging.log4j</groupId>
132+
<artifactId>log4j-core</artifactId>
133+
<version>${log4j.version}</version>
139134
<scope>test</scope>
140135
</dependency>
141136
</dependencies>

spring-shell-core/src/main/java/org/springframework/shell/core/Shell.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import org.jline.terminal.Terminal;
3232
import org.jline.utils.Signals;
3333
import org.jspecify.annotations.Nullable;
34-
import org.slf4j.Logger;
35-
import org.slf4j.LoggerFactory;
34+
import org.apache.commons.logging.Log;
35+
import org.apache.commons.logging.LogFactory;
3636

3737
import org.springframework.beans.factory.annotation.Autowired;
3838
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
@@ -63,7 +63,7 @@
6363
*/
6464
public class Shell {
6565

66-
private static final Logger log = LoggerFactory.getLogger(Shell.class);
66+
private static final Log log = LogFactory.getLog(Shell.class);
6767

6868
private final ResultHandlerService resultHandlerService;
6969

@@ -222,7 +222,7 @@ else if (processExceptionNonInt != null && processExceptionNonInt.exitCode() !=
222222
return new CommandNotFound(words, new HashMap<>(registrations), input.rawText());
223223
}
224224

225-
log.debug("Evaluate input with line=[{}], command=[{}]", line, command);
225+
log.debug(String.format("Evaluate input with line=[%s], command=[%s]", line, command));
226226

227227
Optional<CommandRegistration> commandRegistration = registrations.values().stream().filter(r -> {
228228
if (r.getCommand().equals(command)) {

spring-shell-core/src/main/java/org/springframework/shell/core/command/annotation/MethodCommandExceptionResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import org.jline.terminal.Terminal;
2222
import org.jspecify.annotations.Nullable;
23-
import org.slf4j.Logger;
24-
import org.slf4j.LoggerFactory;
23+
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
2525

2626
import org.springframework.core.MethodParameter;
2727
import org.springframework.core.annotation.AnnotationUtils;
@@ -39,7 +39,7 @@
3939
*/
4040
public class MethodCommandExceptionResolver implements CommandExceptionResolver {
4141

42-
private final static Logger log = LoggerFactory.getLogger(MethodCommandExceptionResolver.class);
42+
private final static Log log = LogFactory.getLog(MethodCommandExceptionResolver.class);
4343

4444
private final Object bean;
4545

spring-shell-core/src/main/java/org/springframework/shell/core/command/annotation/support/CommandRegistrationFactoryBean.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.util.stream.Stream;
2424

2525
import org.jspecify.annotations.Nullable;
26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
26+
import org.apache.commons.logging.Log;
27+
import org.apache.commons.logging.LogFactory;
2828

2929
import org.springframework.beans.BeansException;
3030
import org.springframework.beans.factory.FactoryBean;
@@ -77,7 +77,7 @@
7777
class CommandRegistrationFactoryBean
7878
implements FactoryBean<CommandRegistration>, ApplicationContextAware, InitializingBean {
7979

80-
private final Logger log = LoggerFactory.getLogger(CommandRegistrationFactoryBean.class);
80+
private final Log log = LogFactory.getLog(CommandRegistrationFactoryBean.class);
8181

8282
public static final String COMMAND_BEAN_TYPE = "commandBeanType";
8383

@@ -237,7 +237,7 @@ private void onCommandParameter(MethodParameter mp, Builder builder) {
237237
.get(Option.class);
238238

239239
Option so = mp.getParameterAnnotation(Option.class);
240-
log.debug("Registering with mp='{}' so='{}'", mp, so);
240+
log.debug("Registering with mp='" + mp + "' so='" + so + "'");
241241
if (so != null) {
242242
List<String> longNames = new ArrayList<>();
243243
List<Character> shortNames = new ArrayList<>();
@@ -255,12 +255,13 @@ private void onCommandParameter(MethodParameter mp, Builder builder) {
255255
String longName = mp.getParameterName();
256256
Class<?> parameterType = mp.getParameterType();
257257
if (longName != null) {
258-
log.debug("Using mp='{}' longName='{}' parameterType='{}'", mp, longName, parameterType);
258+
log.debug(String.format("Using mp='%s' longName='%s' parameterType='%s'", mp, longName,
259+
parameterType));
259260
longNames.add(longName);
260261
}
261262
}
262263
if (!longNames.isEmpty() || !shortNames.isEmpty()) {
263-
log.debug("Registering longNames='{}' shortNames='{}'", longNames, shortNames);
264+
log.debug(String.format("Registering longNames='%s' shortNames='%s'", longNames, shortNames));
264265
Class<?> parameterType = mp.getParameterType();
265266
OptionSpec optionSpec = builder.withOption();
266267
optionSpec.type(parameterType);
@@ -345,7 +346,7 @@ else if (ClassUtils.isAssignable(boolean.class, parameterType)) {
345346
return;
346347
}
347348
if (longName != null) {
348-
log.debug("Using mp='{}' longName='{}' parameterType='{}'", mp, longName, parameterType);
349+
log.debug(String.format("Using mp='%s' longName='%s' parameterType='%s'", mp, longName, parameterType));
349350
OptionSpec optionSpec = builder.withOption();
350351
optionSpec.longNames(longName);
351352
optionSpec.type(parameterType);

spring-shell-core/src/main/java/org/springframework/shell/core/command/invocation/InvocableShellMethod.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import jakarta.validation.Validator;
2929

3030
import org.jspecify.annotations.Nullable;
31-
import org.slf4j.Logger;
32-
import org.slf4j.LoggerFactory;
31+
import org.apache.commons.logging.Log;
32+
import org.apache.commons.logging.LogFactory;
3333

3434
import org.springframework.beans.factory.BeanFactory;
3535
import org.springframework.core.BridgeMethodResolver;
@@ -67,8 +67,7 @@
6767
*/
6868
public class InvocableShellMethod {
6969

70-
/** Public for wrapping with fallback logger. */
71-
public static final Logger log = LoggerFactory.getLogger(InvocableShellMethod.class);
70+
public static final Log log = LogFactory.getLog(InvocableShellMethod.class);
7271

7372
private static final Object[] EMPTY_ARGS = new Object[0];
7473

spring-shell-core/src/main/java/org/springframework/shell/core/command/parser/AbstractNodeVisitor.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import java.util.List;
1919

20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
20+
import org.apache.commons.logging.Log;
21+
import org.apache.commons.logging.LogFactory;
2222

2323
import org.springframework.shell.core.command.parser.Parser.ParseResult;
2424

@@ -30,17 +30,17 @@
3030
*/
3131
public abstract class AbstractNodeVisitor implements NodeVisitor {
3232

33-
private final static Logger log = LoggerFactory.getLogger(AbstractNodeVisitor.class);
33+
private final static Log log = LogFactory.getLog(AbstractNodeVisitor.class);
3434

3535
@Override
3636
public final ParseResult visit(List<NonterminalAstNode> nonterminalNodes, List<TerminalAstNode> terminalNodes) {
3737
for (NonterminalAstNode ntn : nonterminalNodes) {
38-
log.debug("visit {}", ntn);
38+
log.debug("visit " + ntn);
3939
if (ntn instanceof CommandNode node) {
40-
log.debug("onEnterRootCommandNode {}", node);
40+
log.debug("onEnterRootCommandNode " + node);
4141
onEnterRootCommandNode(node);
4242
visitChildren(node);
43-
log.debug("onExitRootCommandNode {}", node);
43+
log.debug("onExitRootCommandNode " + node);
4444
onExitRootCommandNode(node);
4545
}
4646
}
@@ -150,64 +150,64 @@ public final ParseResult visit(List<NonterminalAstNode> nonterminalNodes, List<T
150150
protected abstract void onExitDirectiveNode(DirectiveNode node);
151151

152152
private void visitChildren(NonterminalAstNode node) {
153-
log.debug("visitChildren {}", node);
153+
log.debug("visitChildren " + node);
154154
for (AstNode syntaxNode : node.getChildren()) {
155155
visitInternal(syntaxNode);
156156
}
157157
}
158158

159159
private void enterCommandNode(CommandNode node) {
160-
log.debug("enterCommandNode {}", node);
160+
log.debug("enterCommandNode " + node);
161161
onEnterCommandNode(node);
162162
}
163163

164164
private void exitCommandNode(CommandNode node) {
165-
log.debug("exitCommandNode {}", node);
165+
log.debug("exitCommandNode " + node);
166166
onExitCommandNode(node);
167167
}
168168

169169
private void enterOptionNode(OptionNode node) {
170-
log.debug("enterOptionNode {}", node);
170+
log.debug("enterOptionNode " + node);
171171
onEnterOptionNode(node);
172172
}
173173

174174
private void exitOptionNode(OptionNode node) {
175-
log.debug("exitOptionNode {}", node);
175+
log.debug("exitOptionNode " + node);
176176
onExitOptionNode(node);
177177
}
178178

179179
private void enterCommandArgumentNode(CommandArgumentNode node) {
180-
log.debug("enterCommandArgumentNode {}", node);
180+
log.debug("enterCommandArgumentNode " + node);
181181
onEnterCommandArgumentNode(node);
182182
}
183183

184184
private void exitCommandArgumentNode(CommandArgumentNode node) {
185-
log.debug("exitCommandArgumentNode {}", node);
185+
log.debug("exitCommandArgumentNode " + node);
186186
onExitCommandArgumentNode(node);
187187
}
188188

189189
private void enterOptionArgumentNode(OptionArgumentNode node) {
190-
log.debug("enterOptionArgumentNode {}", node);
190+
log.debug("enterOptionArgumentNode " + node);
191191
onEnterOptionArgumentNode(node);
192192
}
193193

194194
private void exitOptionArgumentNode(OptionArgumentNode node) {
195-
log.debug("exitOptionArgumentNode {}", node);
195+
log.debug("exitOptionArgumentNode " + node);
196196
onExitOptionArgumentNode(node);
197197
}
198198

199199
private void enterDirectiveNode(DirectiveNode node) {
200-
log.debug("enterDirectiveNode {}", node);
200+
log.debug("enterDirectiveNode " + node);
201201
onEnterDirectiveNode(node);
202202
}
203203

204204
private void exitDirectiveNode(DirectiveNode node) {
205-
log.debug("exitDirectiveNode {}", node);
205+
log.debug("exitDirectiveNode " + node);
206206
onExitDirectiveNode(node);
207207
}
208208

209209
private void visitInternal(AstNode node) {
210-
log.debug("visitInternal {}", node);
210+
log.debug("visitInternal " + node);
211211
if (node instanceof CommandNode n) {
212212
enterCommandNode(n);
213213
visitChildren(n);

spring-shell-core/src/main/java/org/springframework/shell/core/command/parser/Lexer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.util.regex.Pattern;
2424
import java.util.stream.Collectors;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
26+
import org.apache.commons.logging.Log;
27+
import org.apache.commons.logging.LogFactory;
2828

2929
import org.springframework.shell.core.command.parser.CommandModel.CommandInfo;
3030
import org.springframework.shell.core.command.parser.ParserConfig.Feature;
@@ -64,7 +64,7 @@ public record LexerResult(List<Token> tokens, List<MessageResult> messageResults
6464
*/
6565
public class DefaultLexer implements Lexer {
6666

67-
private final static Logger log = LoggerFactory.getLogger(DefaultLexer.class);
67+
private final static Log log = LogFactory.getLog(DefaultLexer.class);
6868

6969
private final CommandModel commandModel;
7070

@@ -122,7 +122,7 @@ private List<String> extractDirectives(List<String> arguments) {
122122

123123
@Override
124124
public LexerResult tokenize(List<String> arguments) {
125-
log.debug("Tokenizing arguments {}", arguments);
125+
log.debug("Tokenizing arguments " + arguments);
126126
List<MessageResult> errorResults = new ArrayList<>();
127127
List<Token> tokenList = new ArrayList<Token>();
128128

@@ -237,7 +237,7 @@ else if (isLastTokenOfType(tokenList, TokenType.ARGUMENT)) {
237237

238238
}
239239

240-
log.debug("Generated token list {}", tokenList);
240+
log.debug("Generated token list " + tokenList);
241241
return new LexerResult(tokenList, errorResults);
242242
}
243243

0 commit comments

Comments
 (0)