Skip to content

Commit 5272ecb

Browse files
committed
Refine contribution #1283
- Use dependency injection for CommandHighlighter - Add Javadoc - Add missing license headers - Rename test class - Remove wildcard imports
1 parent 03c1f47 commit 5272ecb

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

spring-shell-core-autoconfigure/src/main/java/org/springframework/shell/core/autoconfigure/JLineShellAutoConfiguration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ public ShellRunner jlineShellRunner(JLineInputProvider inputProvider, CommandPar
111111

112112
@Bean
113113
public LineReader lineReader(Terminal terminal, Parser parser, CommandCompleter commandCompleter,
114-
CommandRegistry commandRegistry) {
114+
CommandHighlighter commandHighlighter) {
115115
LineReaderBuilder lineReaderBuilder = LineReaderBuilder.builder()
116116
.terminal(terminal)
117117
.appName("Spring Shell")
118118
.completer(commandCompleter)
119119
.history(jLineHistory)
120-
.highlighter(new CommandHighlighter(commandRegistry))
120+
.highlighter(commandHighlighter)
121121
.parser(parser);
122122

123123
LineReader lineReader = lineReaderBuilder.build();
@@ -176,6 +176,12 @@ public Parser parser() {
176176
return parser;
177177
}
178178

179+
@Bean
180+
@ConditionalOnMissingBean
181+
public CommandHighlighter commandHighlighter(CommandRegistry commandRegistry) {
182+
return new CommandHighlighter(commandRegistry);
183+
}
184+
179185
@Bean
180186
@ConditionalOnMissingBean
181187
public CommandCompleter commandCompleter(CommandRegistry commandRegistry) {

spring-shell-jline/src/main/java/org/springframework/shell/jline/CommandHighlighter.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2026-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.shell.jline;
217

318
import java.util.Comparator;
@@ -19,13 +34,17 @@ public class CommandHighlighter implements Highlighter {
1934

2035
private final CommandRegistry commandRegistry;
2136

37+
/**
38+
* Create a new {@link CommandHighlighter} instance.
39+
* @param commandRegistry the command registry
40+
*/
2241
public CommandHighlighter(CommandRegistry commandRegistry) {
2342
this.commandRegistry = commandRegistry;
2443
}
2544

2645
@Override
2746
public AttributedString highlight(LineReader reader, String buffer) {
28-
return commandRegistry.getCommands()
47+
return this.commandRegistry.getCommands()
2948
.stream()
3049
.flatMap(command -> Stream.concat(Stream.of(command.getName()), command.getAliases().stream()))
3150
.filter(buffer::startsWith)

spring-shell-jline/src/test/java/org/springframework/shell/jline/CommandHighlighterTest.java renamed to spring-shell-jline/src/test/java/org/springframework/shell/jline/CommandHighlighterTests.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2026-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.shell.jline;
217

318
import java.util.Collections;
@@ -12,13 +27,15 @@
1227
import org.springframework.shell.core.command.Command;
1328
import org.springframework.shell.core.command.CommandRegistry;
1429
import org.springframework.shell.jline.tui.style.ThemeResolver;
15-
import static org.assertj.core.api.Assertions.*;
16-
import static org.mockito.Mockito.*;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
import static org.mockito.Mockito.mock;
33+
import static org.mockito.Mockito.when;
1734

1835
/**
1936
* @author Piotr Olaszewski
2037
*/
21-
class CommandHighlighterTest {
38+
class CommandHighlighterTests {
2239

2340
private final LineReader lineReader = mock(LineReader.class);
2441

0 commit comments

Comments
 (0)