Skip to content

Commit 866f067

Browse files
committed
Refactor
Signed-off-by: Piotr Olaszewski <[email protected]>
1 parent 597b403 commit 866f067

File tree

78 files changed

+1528
-1920
lines changed

Some content is hidden

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

78 files changed

+1528
-1920
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
*/
1616
package org.springframework.shell.boot;
1717

18-
import org.springframework.shell.core.command.CommandRegistration;
18+
import org.springframework.shell.core.command.Command;
1919

2020
/**
21-
* Callback interface that can be used to customize a {@link CommandRegistration.Builder}.
21+
* Callback interface that can be used to customize a {@link Command.Builder}.
2222
*
2323
* @author Janne Valkealahti
2424
*/
2525
@FunctionalInterface
2626
public interface CommandRegistrationCustomizer {
2727

2828
/**
29-
* Callback to customize a {@link CommandRegistration.Builder} instance.
29+
* Callback to customize a {@link Command.Builder} instance.
3030
* @param commandRegistrationBuilder the command registration builder to customize
3131
*/
32-
void customize(CommandRegistration.Builder commandRegistrationBuilder);
32+
void customize(Command.Builder commandRegistrationBuilder);
3333

3434
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.shell.core.MethodTargetRegistrar;
2929
import org.springframework.shell.boot.SpringShellProperties.Help;
30+
import org.springframework.shell.core.command.Command;
3031
import org.springframework.shell.core.command.CommandRegistry;
3132
import org.springframework.shell.core.command.CommandRegistryCustomizer;
32-
import org.springframework.shell.core.command.CommandRegistration;
33-
import org.springframework.shell.core.command.CommandRegistration.BuilderSupplier;
34-
import org.springframework.shell.core.command.CommandRegistration.OptionNameModifier;
33+
import org.springframework.shell.core.command.BuilderSupplier;
34+
import org.springframework.shell.core.command.OptionNameModifier;
3535
import org.springframework.shell.core.command.support.OptionNameModifierSupport;
3636
import org.springframework.shell.core.command.CommandResolver;
3737
import org.springframework.shell.core.context.ShellContext;
@@ -57,8 +57,7 @@ public CommandRegistry commandRegistry(ObjectProvider<MethodTargetRegistrar> met
5757
}
5858

5959
@Bean
60-
public CommandRegistryCustomizer defaultCommandRegistryCustomizer(
61-
ObjectProvider<CommandRegistration> commandRegistrations) {
60+
public CommandRegistryCustomizer defaultCommandRegistryCustomizer(ObjectProvider<Command> commandRegistrations) {
6261
return registry -> {
6362
commandRegistrations.orderedStream().forEach(registration -> {
6463
registry.register(registration);
@@ -120,7 +119,7 @@ public CommandRegistrationCustomizer defaultOptionNameModifierCommandRegistratio
120119
public BuilderSupplier commandRegistrationBuilderSupplier(
121120
ObjectProvider<CommandRegistrationCustomizer> customizerProvider) {
122121
return () -> {
123-
CommandRegistration.Builder builder = CommandRegistration.builder();
122+
Command.Builder builder = Command.builder();
124123
customizerProvider.orderedStream().forEach((customizer) -> customizer.customize(builder));
125124
return builder;
126125
};

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import org.springframework.context.annotation.Bean;
2626
import org.springframework.context.annotation.Configuration;
2727
import org.springframework.shell.core.command.CommandRegistry;
28-
import org.springframework.shell.core.command.CommandRegistration;
28+
import org.springframework.shell.core.command.Command;
2929
import org.springframework.shell.core.command.CommandResolver;
30-
import org.springframework.shell.core.command.CommandRegistration.Builder;
31-
import org.springframework.shell.core.command.CommandRegistration.BuilderSupplier;
32-
import org.springframework.shell.core.command.CommandRegistration.OptionNameModifier;
30+
import org.springframework.shell.core.command.Command.Builder;
31+
import org.springframework.shell.core.command.BuilderSupplier;
32+
import org.springframework.shell.core.command.OptionNameModifier;
3333

3434
import static org.assertj.core.api.Assertions.assertThat;
3535

@@ -162,8 +162,8 @@ CommandRegistry customCommandRegistry() {
162162
static class CustomCommandRegistrationConfiguration {
163163

164164
@Bean
165-
CommandRegistration commandRegistration() {
166-
return CommandRegistration.builder()
165+
Command commandRegistration() {
166+
return Command.builder()
167167
.command("customcommand")
168168
.withTarget(targetSpec -> targetSpec.function(ctx -> null))
169169
.build();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.List;
2121

2222
import org.springframework.core.ResolvableType;
23-
import org.springframework.shell.core.command.CommandOption;
23+
import org.springframework.shell.core.command.metadata.CommandOption;
2424
import org.springframework.shell.core.completion.CompletionContext;
2525
import org.springframework.shell.core.completion.CompletionProposal;
2626

@@ -37,7 +37,7 @@ public List<CompletionProposal> complete(CompletionContext completionContext) {
3737
List<CompletionProposal> result = new ArrayList<>();
3838
CommandOption commandOption = completionContext.getCommandOption();
3939
if (commandOption != null) {
40-
ResolvableType type = commandOption.getType();
40+
ResolvableType type = commandOption.type();
4141
if (type != null) {
4242
Class<?> clazz = type.getRawClass();
4343
if (clazz != null) {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.shell.core.command.CommandRegistry;
4343
import org.springframework.shell.core.command.CommandExecution.CommandExecutionException;
4444
import org.springframework.shell.core.command.CommandExecution.CommandExecutionHandlerMethodArgumentResolvers;
45+
import org.springframework.shell.core.command.metadata.CommandOption;
4546
import org.springframework.shell.core.completion.CompletionContext;
4647
import org.springframework.shell.core.completion.CompletionProposal;
4748
import org.springframework.shell.core.completion.CompletionResolver;
@@ -217,14 +218,14 @@ else if (processExceptionNonInt != null && processExceptionNonInt.exitCode() !=
217218
String line = words.stream().collect(Collectors.joining(" ")).trim();
218219
String command = findLongestCommand(line, false);
219220

220-
Map<String, CommandRegistration> registrations = commandRegistry.getRegistrations();
221+
Map<String, Command> registrations = commandRegistry.getRegistrations();
221222
if (command == null) {
222223
return new CommandNotFound(words, new HashMap<>(registrations), input.rawText());
223224
}
224225

225226
log.debug(String.format("Evaluate input with line=[%s], command=[%s]", line, command));
226227

227-
Optional<CommandRegistration> commandRegistration = registrations.values().stream().filter(r -> {
228+
Optional<Command> commandRegistration = registrations.values().stream().filter(r -> {
228229
if (r.getCommand().equals(command)) {
229230
return true;
230231
}
@@ -359,7 +360,7 @@ public List<CompletionProposal> complete(CompletionContext context) {
359360
String best = findLongestCommand(prefix, true);
360361
if (best != null) {
361362
context = context.drop(best.split(" ").length);
362-
CommandRegistration registration = commandRegistry.getRegistrations().get(best);
363+
Command registration = commandRegistry.getRegistrations().get(best);
363364
CompletionContext argsContext = context.commandRegistration(registration);
364365

365366
for (CompletionResolver resolver : completionResolvers) {
@@ -378,7 +379,7 @@ public List<CompletionProposal> complete(CompletionContext context) {
378379
}
379380

380381
List<CompletionProposal> argProposals = matchedArgOptions.stream().flatMap(o -> {
381-
Function<CompletionContext, List<CompletionProposal>> completion = o.getCompletion();
382+
Function<CompletionContext, List<CompletionProposal>> completion = o.completion();
382383
if (completion != null) {
383384
List<CompletionProposal> apply = completion.apply(argsContext.commandOption(o));
384385
return apply.stream();
@@ -399,7 +400,7 @@ private List<CommandOption> matchOptions(List<CommandOption> options, String arg
399400
if (trimmed.length() == 1) {
400401
Character trimmedChar = trimmed.charAt(0);
401402
options.stream().filter(o -> {
402-
for (Character sn : o.getShortNames()) {
403+
for (Character sn : o.shortNames()) {
403404
if (trimmedChar.equals(sn)) {
404405
return true;
405406
}
@@ -410,7 +411,7 @@ private List<CommandOption> matchOptions(List<CommandOption> options, String arg
410411
else if (trimmed.length() > 1) {
411412
trimmed.chars().mapToObj(i -> (char) i).forEach(c -> {
412413
options.stream().forEach(o -> {
413-
for (Character sn : o.getShortNames()) {
414+
for (Character sn : o.shortNames()) {
414415
if (c.equals(sn)) {
415416
matched.add(o);
416417
}
@@ -421,7 +422,7 @@ else if (trimmed.length() > 1) {
421422
}
422423
else if (count == 2) {
423424
options.stream().filter(o -> {
424-
for (String ln : o.getLongNames()) {
425+
for (String ln : o.longNames()) {
425426
if (trimmed.equals(ln)) {
426427
return true;
427428
}
@@ -448,7 +449,7 @@ private List<CompletionProposal> commandsStartingWith(String prefix) {
448449
.collect(Collectors.toList());
449450
}
450451

451-
private CompletionProposal toCommandProposal(String command, CommandRegistration registration) {
452+
private CompletionProposal toCommandProposal(String command, Command registration) {
452453
return new CompletionProposal(command).dontQuote(true)
453454
.category("Available commands")
454455
.description(registration.getDescription());
@@ -460,7 +461,7 @@ private CompletionProposal toCommandProposal(String command, CommandRegistration
460461
* @return a valid command name, or {@literal null} if none matched
461462
*/
462463
private @Nullable String findLongestCommand(String prefix, boolean filterHidden) {
463-
Map<String, CommandRegistration> registrations = commandRegistry.getRegistrations();
464+
Map<String, Command> registrations = commandRegistry.getRegistrations();
464465
if (filterHidden) {
465466
registrations = Utils.removeHiddenCommands(registrations);
466467
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
import org.springframework.core.DefaultParameterNameDiscoverer;
3838
import org.springframework.core.MethodParameter;
39-
import org.springframework.shell.core.command.CommandRegistration;
39+
import org.springframework.shell.core.command.Command;
4040

4141
/**
4242
* Some text utilities.
@@ -177,11 +177,10 @@ public static <T> List<List<T>> split(T[] array, Predicate<T> predicate) {
177177
* @param registrations a command registrations
178178
* @return same map with removed hidden commands
179179
*/
180-
public static Map<String, CommandRegistration> removeHiddenCommands(
181-
Map<String, CommandRegistration> registrations) {
182-
Iterator<Map.Entry<String, CommandRegistration>> iter = registrations.entrySet().iterator();
180+
public static Map<String, Command> removeHiddenCommands(Map<String, Command> registrations) {
181+
Iterator<Map.Entry<String, Command>> iter = registrations.entrySet().iterator();
183182
while (iter.hasNext()) {
184-
Map.Entry<String, CommandRegistration> entry = iter.next();
183+
Map.Entry<String, Command> entry = iter.next();
185184
if (entry.getValue().isHidden()) {
186185
iter.remove();
187186
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.springframework.shell.core.command;
2+
3+
import java.util.function.Supplier;
4+
5+
/**
6+
* Interface used to supply instance of a {@link Command.Builder}. Meant to be a single
7+
* point access to centrally configured builder in an application context.
8+
*/
9+
@FunctionalInterface
10+
public interface BuilderSupplier extends Supplier<Command.Builder> {
11+
12+
}

0 commit comments

Comments
 (0)