Skip to content

Commit 3d4dce2

Browse files
committed
Rename CommandCatalog to CommandRegistry
Based on method names, CommandRegistry is more representative and more explicit about the concept than CommandCatalog.
1 parent cc5bf54 commit 3d4dce2

File tree

36 files changed

+268
-261
lines changed

36 files changed

+268
-261
lines changed
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 the original author or authors.
2+
* Copyright 2021-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@
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.CommandCatalog;
31-
import org.springframework.shell.core.command.CommandCatalogCustomizer;
30+
import org.springframework.shell.core.command.CommandRegistry;
31+
import org.springframework.shell.core.command.CommandRegistryCustomizer;
3232
import org.springframework.shell.core.command.CommandRegistration;
3333
import org.springframework.shell.core.command.CommandRegistration.BuilderSupplier;
3434
import org.springframework.shell.core.command.CommandRegistration.OptionNameModifier;
@@ -38,30 +38,30 @@
3838

3939
@AutoConfiguration
4040
@EnableConfigurationProperties(SpringShellProperties.class)
41-
public class CommandCatalogAutoConfiguration {
41+
public class CommandRegistryAutoConfiguration {
4242

4343
@Bean
44-
@ConditionalOnMissingBean(CommandCatalog.class)
45-
public CommandCatalog commandCatalog(ObjectProvider<MethodTargetRegistrar> methodTargetRegistrars,
46-
ObjectProvider<CommandResolver> commandResolvers,
47-
ObjectProvider<CommandCatalogCustomizer> commandCatalogCustomizers,
48-
ShellContext shellContext) {
44+
@ConditionalOnMissingBean(CommandRegistry.class)
45+
public CommandRegistry commandRegistry(ObjectProvider<MethodTargetRegistrar> methodTargetRegistrars,
46+
ObjectProvider<CommandResolver> commandResolvers,
47+
ObjectProvider<CommandRegistryCustomizer> commandRegistryCustomizers,
48+
ShellContext shellContext) {
4949
List<CommandResolver> resolvers = commandResolvers.orderedStream().collect(Collectors.toList());
50-
CommandCatalog catalog = CommandCatalog.of(resolvers, shellContext);
50+
CommandRegistry registry = CommandRegistry.of(resolvers, shellContext);
5151
methodTargetRegistrars.orderedStream().forEach(resolver -> {
52-
resolver.register(catalog);
52+
resolver.register(registry);
5353
});
54-
commandCatalogCustomizers.orderedStream().forEach(customizer -> {
55-
customizer.customize(catalog);
54+
commandRegistryCustomizers.orderedStream().forEach(customizer -> {
55+
customizer.customize(registry);
5656
});
57-
return catalog;
57+
return registry;
5858
}
5959

6060
@Bean
61-
public CommandCatalogCustomizer defaultCommandCatalogCustomizer(ObjectProvider<CommandRegistration> commandRegistrations) {
62-
return catalog -> {
61+
public CommandRegistryCustomizer defaultCommandRegistryCustomizer(ObjectProvider<CommandRegistration> commandRegistrations) {
62+
return registry -> {
6363
commandRegistrations.orderedStream().forEach(registration -> {
64-
catalog.register(registration);
64+
registry.register(registration);
6565
});
6666
};
6767
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2022 the original author or authors.
2+
* Copyright 2021-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,12 +38,13 @@
3838
import org.springframework.context.annotation.Bean;
3939
import org.springframework.context.event.ContextClosedEvent;
4040
import org.springframework.context.event.EventListener;
41-
import org.springframework.shell.core.command.CommandCatalog;
41+
import org.springframework.shell.core.command.CommandRegistry;
4242
import org.springframework.shell.core.config.UserConfigPathProvider;
4343
import org.springframework.util.StringUtils;
4444

4545
/**
4646
* @author Piotr Olaszewski
47+
* @author Mahmoud Ben Hassine
4748
*/
4849
@AutoConfiguration
4950
@EnableConfigurationProperties(SpringShellProperties.class)
@@ -57,7 +58,7 @@ public class LineReaderAutoConfiguration {
5758

5859
private Parser parser;
5960

60-
private CommandCatalog commandRegistry;
61+
private CommandRegistry commandRegistry;
6162

6263
private org.jline.reader.History jLineHistory;
6364

@@ -68,8 +69,8 @@ public class LineReaderAutoConfiguration {
6869
private UserConfigPathProvider userConfigPathProvider;
6970

7071
public LineReaderAutoConfiguration(Terminal terminal, Completer completer, Parser parser,
71-
CommandCatalog commandRegistry, org.jline.reader.History jLineHistory,
72-
SpringShellProperties springShellProperties, UserConfigPathProvider userConfigPathProvider) {
72+
CommandRegistry commandRegistry, org.jline.reader.History jLineHistory,
73+
SpringShellProperties springShellProperties, UserConfigPathProvider userConfigPathProvider) {
7374
this.terminal = terminal;
7475
this.completer = completer;
7576
this.parser = parser;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 the original author or authors.
2+
* Copyright 2017-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
import org.springframework.shell.core.ResultHandler;
3131
import org.springframework.shell.core.ResultHandlerService;
3232
import org.springframework.shell.core.Shell;
33-
import org.springframework.shell.core.command.CommandCatalog;
33+
import org.springframework.shell.core.command.CommandRegistry;
3434
import org.springframework.shell.core.config.ShellConversionServiceSupplier;
3535
import org.springframework.shell.core.context.ShellContext;
3636
import org.springframework.shell.core.exit.ExitCodeMappings;
@@ -64,9 +64,9 @@ public ResultHandlerService resultHandlerService(Set<ResultHandler<?>> resultHan
6464
}
6565

6666
@Bean
67-
public Shell shell(ResultHandlerService resultHandlerService, CommandCatalog commandRegistry, Terminal terminal,
68-
ShellConversionServiceSupplier shellConversionServiceSupplier, ShellContext shellContext,
69-
ExitCodeMappings exitCodeMappings) {
67+
public Shell shell(ResultHandlerService resultHandlerService, CommandRegistry commandRegistry, Terminal terminal,
68+
ShellConversionServiceSupplier shellConversionServiceSupplier, ShellContext shellContext,
69+
ExitCodeMappings exitCodeMappings) {
7070
Shell shell = new Shell(resultHandlerService, commandRegistry, terminal, shellContext, exitCodeMappings);
7171
shell.setConversionService(shellConversionServiceSupplier.get());
7272
return shell;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2023 the original author or authors.
2+
* Copyright 2017-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import org.springframework.boot.LazyInitializationExcludeFilter;
2020
import org.springframework.boot.autoconfigure.AutoConfiguration;
2121
import org.springframework.context.annotation.Bean;
22-
import org.springframework.shell.core.command.CommandCatalog;
22+
import org.springframework.shell.core.command.CommandRegistry;
2323
import org.springframework.shell.standard.CommandValueProvider;
2424
import org.springframework.shell.standard.EnumValueProvider;
2525
import org.springframework.shell.standard.FileValueProvider;
@@ -29,12 +29,13 @@
2929
* Sets up all required beans for supporting the standard Shell API.
3030
*
3131
* @author Eric Bottard
32+
* @author Mahmoud Ben Hassine
3233
*/
3334
@AutoConfiguration
3435
public class StandardAPIAutoConfiguration {
3536

3637
@Bean
37-
public ValueProvider commandValueProvider(CommandCatalog commandRegistry) {
38+
public ValueProvider commandValueProvider(CommandRegistry commandRegistry) {
3839
return new CommandValueProvider(commandRegistry);
3940
}
4041

spring-shell-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.springframework.shell.boot.ShellContextAutoConfiguration
33
org.springframework.shell.boot.SpringShellAutoConfiguration
44
org.springframework.shell.boot.ShellRunnerAutoConfiguration
55
org.springframework.shell.boot.ApplicationRunnerAutoConfiguration
6-
org.springframework.shell.boot.CommandCatalogAutoConfiguration
6+
org.springframework.shell.boot.CommandRegistryAutoConfiguration
77
org.springframework.shell.boot.LineReaderAutoConfiguration
88
org.springframework.shell.boot.CompleterAutoConfiguration
99
org.springframework.shell.boot.UserConfigAutoConfiguration
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2525
import org.springframework.context.annotation.Bean;
2626
import org.springframework.context.annotation.Configuration;
27-
import org.springframework.shell.core.command.CommandCatalog;
27+
import org.springframework.shell.core.command.CommandRegistry;
2828
import org.springframework.shell.core.command.CommandRegistration;
2929
import org.springframework.shell.core.command.CommandResolver;
3030
import org.springframework.shell.core.command.CommandRegistration.Builder;
@@ -33,42 +33,42 @@
3333

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

36-
class CommandCatalogAutoConfigurationTests {
36+
class CommandRegistryAutoConfigurationTests {
3737

3838
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
39-
.withConfiguration(AutoConfigurations.of(CommandCatalogAutoConfiguration.class,
39+
.withConfiguration(AutoConfigurations.of(CommandRegistryAutoConfiguration.class,
4040
JLineShellAutoConfiguration.class, ShellContextAutoConfiguration.class));
4141

4242
@Test
43-
void defaultCommandCatalog() {
44-
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CommandCatalog.class));
43+
void defaultCommandRegistry() {
44+
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CommandRegistry.class));
4545
}
4646

4747
@Test
4848
void testCommandResolvers() {
4949
this.contextRunner.withUserConfiguration(CustomCommandResolverConfiguration.class)
5050
.run((context) -> {
51-
CommandCatalog commandCatalog = context.getBean(CommandCatalog.class);
52-
assertThat(commandCatalog).extracting("resolvers").asInstanceOf(InstanceOfAssertFactories.LIST)
51+
CommandRegistry commandRegistry = context.getBean(CommandRegistry.class);
52+
assertThat(commandRegistry).extracting("resolvers").asInstanceOf(InstanceOfAssertFactories.LIST)
5353
.hasSize(1);
5454
});
5555
}
5656

5757
@Test
58-
void customCommandCatalog() {
59-
this.contextRunner.withUserConfiguration(CustomCommandCatalogConfiguration.class)
58+
void customCommandRegistry() {
59+
this.contextRunner.withUserConfiguration(CustomCommandRegistryConfiguration.class)
6060
.run((context) -> {
61-
CommandCatalog commandCatalog = context.getBean(CommandCatalog.class);
62-
assertThat(commandCatalog).isSameAs(CustomCommandCatalogConfiguration.testCommandCatalog);
61+
CommandRegistry commandRegistry = context.getBean(CommandRegistry.class);
62+
assertThat(commandRegistry).isSameAs(CustomCommandRegistryConfiguration.TEST_COMMAND_REGISTRY);
6363
});
6464
}
6565

6666
@Test
6767
void registerCommandRegistration() {
6868
this.contextRunner.withUserConfiguration(CustomCommandRegistrationConfiguration.class)
6969
.run(context -> {
70-
CommandCatalog commandCatalog = context.getBean(CommandCatalog.class);
71-
assertThat(commandCatalog.getRegistrations().get("customcommand")).isNotNull();
70+
CommandRegistry commandRegistry = context.getBean(CommandRegistry.class);
71+
assertThat(commandRegistry.getRegistrations().get("customcommand")).isNotNull();
7272
});
7373
}
7474

@@ -158,13 +158,13 @@ CommandResolver customCommandResolver() {
158158
}
159159

160160
@Configuration
161-
static class CustomCommandCatalogConfiguration {
161+
static class CustomCommandRegistryConfiguration {
162162

163-
static final CommandCatalog testCommandCatalog = CommandCatalog.of();
163+
static final CommandRegistry TEST_COMMAND_REGISTRY = CommandRegistry.of();
164164

165165
@Bean
166-
CommandCatalog customCommandCatalog() {
167-
return testCommandCatalog;
166+
CommandRegistry customCommandRegistry() {
167+
return TEST_COMMAND_REGISTRY;
168168
}
169169
}
170170

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3030
import org.springframework.context.annotation.Bean;
3131
import org.springframework.context.annotation.Configuration;
32-
import org.springframework.shell.core.command.CommandCatalog;
32+
import org.springframework.shell.core.command.CommandRegistry;
3333
import org.springframework.shell.core.config.UserConfigPathProvider;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
@@ -97,8 +97,8 @@ Parser mockParser() {
9797
}
9898

9999
@Bean
100-
CommandCatalog mockCommandCatalog() {
101-
return mock(CommandCatalog.class);
100+
CommandRegistry mockCommandRegistry() {
101+
return mock(CommandRegistry.class);
102102
}
103103

104104
@Bean

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,19 +16,20 @@
1616

1717
package org.springframework.shell.core;
1818

19-
import org.springframework.shell.core.command.CommandCatalog;
19+
import org.springframework.shell.core.command.CommandRegistry;
2020

2121
/**
2222
* Strategy interface for registering commands.
2323
*
2424
* @author Eric Bottard
2525
* @author Camilo Gonzalez
26+
* @author Mahmoud Ben Hassine
2627
*/
2728
public interface MethodTargetRegistrar {
2829

2930
/**
3031
* Register mappings from {@literal <command keyword(s)>} to actual behavior.
3132
*/
32-
void register(CommandCatalog registry);
33+
void register(CommandRegistry registry);
3334

3435
}

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 the original author or authors.
2+
* Copyright 2017-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,15 +38,10 @@
3838
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
3939
import org.springframework.core.convert.ConversionService;
4040
import org.springframework.core.convert.support.DefaultConversionService;
41-
import org.springframework.shell.core.command.CommandAlias;
42-
import org.springframework.shell.core.command.CommandCatalog;
43-
import org.springframework.shell.core.command.CommandExceptionResolver;
44-
import org.springframework.shell.core.command.CommandExecution;
41+
import org.springframework.shell.core.command.*;
42+
import org.springframework.shell.core.command.CommandRegistry;
4543
import org.springframework.shell.core.command.CommandExecution.CommandExecutionException;
4644
import org.springframework.shell.core.command.CommandExecution.CommandExecutionHandlerMethodArgumentResolvers;
47-
import org.springframework.shell.core.command.CommandHandlingResult;
48-
import org.springframework.shell.core.command.CommandOption;
49-
import org.springframework.shell.core.command.CommandRegistration;
5045
import org.springframework.shell.core.completion.CompletionResolver;
5146
import org.springframework.shell.core.context.InteractionMode;
5247
import org.springframework.shell.core.context.ShellContext;
@@ -60,6 +55,7 @@
6055
* @author Eric Bottard
6156
* @author Janne Valkealahti
6257
* @author Piotr Olaszewski
58+
* @author Mahmoud Ben Hassine
6359
*/
6460
public class Shell {
6561

@@ -73,7 +69,7 @@ public class Shell {
7369
public static final Object NO_INPUT = new Object();
7470

7571
private final Terminal terminal;
76-
private final CommandCatalog commandRegistry;
72+
private final CommandRegistry commandRegistry;
7773
protected List<CompletionResolver> completionResolvers = new ArrayList<>();
7874
private @Nullable CommandExecutionHandlerMethodArgumentResolvers argumentResolvers;
7975
private ConversionService conversionService = new DefaultConversionService();
@@ -91,8 +87,8 @@ public class Shell {
9187
private Validator validator = Utils.defaultValidator();
9288
private List<CommandExceptionResolver> exceptionResolvers = new ArrayList<>();
9389

94-
public Shell(ResultHandlerService resultHandlerService, CommandCatalog commandRegistry, Terminal terminal,
95-
ShellContext shellContext, ExitCodeMappings exitCodeMappings) {
90+
public Shell(ResultHandlerService resultHandlerService, CommandRegistry commandRegistry, Terminal terminal,
91+
ShellContext shellContext, ExitCodeMappings exitCodeMappings) {
9692
this.resultHandlerService = resultHandlerService;
9793
this.commandRegistry = commandRegistry;
9894
this.terminal = terminal;

0 commit comments

Comments
 (0)