Skip to content

Commit f91b255

Browse files
committed
Create BuilderSupplier interface
- Fixes #607
1 parent 9b4e347 commit f91b255

File tree

20 files changed

+56
-76
lines changed

20 files changed

+56
-76
lines changed

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

Lines changed: 3 additions & 3 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-2023 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,7 +16,6 @@
1616
package org.springframework.shell.boot;
1717

1818
import java.util.List;
19-
import java.util.function.Supplier;
2019
import java.util.stream.Collectors;
2120

2221
import org.springframework.beans.factory.ObjectProvider;
@@ -29,6 +28,7 @@
2928
import org.springframework.shell.command.CommandCatalog;
3029
import org.springframework.shell.command.CommandCatalogCustomizer;
3130
import org.springframework.shell.command.CommandRegistration;
31+
import org.springframework.shell.command.CommandRegistration.BuilderSupplier;
3232
import org.springframework.shell.command.CommandResolver;
3333

3434
@AutoConfiguration
@@ -76,7 +76,7 @@ public CommandRegistrationCustomizer helpOptionsCommandRegistrationCustomizer(Sp
7676

7777
@Bean
7878
@ConditionalOnMissingBean
79-
public Supplier<CommandRegistration.Builder> commandRegistrationBuilderSupplier(
79+
public BuilderSupplier commandRegistrationBuilderSupplier(
8080
ObjectProvider<CommandRegistrationCustomizer> customizerProvider) {
8181
return () -> {
8282
CommandRegistration.Builder builder = CommandRegistration.builder();

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-2023 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,8 +16,6 @@
1616

1717
package org.springframework.shell.boot;
1818

19-
import java.util.function.Supplier;
20-
2119
import org.springframework.boot.autoconfigure.AutoConfiguration;
2220
import org.springframework.context.ApplicationContext;
2321
import org.springframework.context.annotation.Bean;
@@ -55,7 +53,7 @@ public ValueProvider fileValueProvider() {
5553

5654
@Bean
5755
public MethodTargetRegistrar standardMethodTargetResolver(ApplicationContext applicationContext,
58-
Supplier<CommandRegistration.Builder> builder) {
56+
CommandRegistration.BuilderSupplier builder) {
5957
return new StandardMethodTargetRegistrar(applicationContext, builder);
6058
}
6159
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -137,6 +137,14 @@ public static Builder builder() {
137137
return new DefaultBuilder();
138138
}
139139

140+
/**
141+
* Interface used to supply instance of a {@link Builder}. Meant to be a single
142+
* point access to centrally configured builder in an application context.
143+
*/
144+
@FunctionalInterface
145+
public interface BuilderSupplier extends Supplier<Builder> {
146+
}
147+
140148
/**
141149
* Spec defining an option.
142150
*/

spring-shell-docs/src/main/asciidoc/using-shell-commands-programmaticmodel.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include::{snippets}/CommandRegistrationBeanSnippets.java[tag=plain]
1212
====
1313

1414
If all your commands have something in common, an instance of
15-
a _Supplier<CommandRegistration.Builder>_ is created which can
15+
a _CommandRegistration.BuilderSupplier_ is created which can
1616
be autowired. Default implementation of this supplier returns
1717
a new builder so you don't need to worry about its internal state.
1818

spring-shell-docs/src/test/java/org/springframework/shell/docs/CommandRegistrationBeanSnippets.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.shell.docs;
1717

18-
import java.util.function.Supplier;
19-
2018
import org.springframework.context.annotation.Bean;
2119
import org.springframework.shell.boot.CommandRegistrationCustomizer;
2220
import org.springframework.shell.command.CommandRegistration;
@@ -37,7 +35,7 @@ CommandRegistration commandRegistration() {
3735
class Dump2 {
3836
// tag::fromsupplier[]
3937
@Bean
40-
CommandRegistration commandRegistration(Supplier<CommandRegistration.Builder> builder) {
38+
CommandRegistration commandRegistration(CommandRegistration.BuilderSupplier builder) {
4139
return builder.get()
4240
.command("mycommand")
4341
.build();

spring-shell-samples/src/main/java/org/springframework/shell/samples/e2e/ArityCommands.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.shell.samples.e2e;
1717

18-
import java.util.function.Supplier;
19-
2018
import org.springframework.context.annotation.Bean;
2119
import org.springframework.shell.command.CommandRegistration;
2220
import org.springframework.shell.command.CommandRegistration.OptionArity;
@@ -40,7 +38,7 @@ public String testBooleanArity1DefaultTrue(
4038
}
4139

4240
@Bean
43-
public CommandRegistration testBooleanArity1DefaultTrueRegistration(Supplier<CommandRegistration.Builder> builder) {
41+
public CommandRegistration testBooleanArity1DefaultTrueRegistration(CommandRegistration.BuilderSupplier builder) {
4442
return builder.get()
4543
.command(REG, "boolean-arity1-default-true")
4644
.group(GROUP)

spring-shell-samples/src/main/java/org/springframework/shell/samples/e2e/DefaultValueCommands.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.shell.samples.e2e;
1717

18-
import java.util.function.Supplier;
19-
2018
import org.springframework.context.annotation.Bean;
2119
import org.springframework.shell.command.CommandRegistration;
2220
import org.springframework.shell.standard.ShellComponent;
@@ -39,7 +37,7 @@ public String testDefaultValue(
3937
}
4038

4139
@Bean
42-
public CommandRegistration testDefaultValueRegistration(Supplier<CommandRegistration.Builder> builder) {
40+
public CommandRegistration testDefaultValueRegistration(CommandRegistration.BuilderSupplier builder) {
4341
return builder.get()
4442
.command(REG, "default-value")
4543
.group(GROUP)
@@ -64,7 +62,7 @@ public String testDefaultValueBoolean1(
6462
}
6563

6664
@Bean
67-
public CommandRegistration testDefaultValueBoolean1Registration(Supplier<CommandRegistration.Builder> builder) {
65+
public CommandRegistration testDefaultValueBoolean1Registration(CommandRegistration.BuilderSupplier builder) {
6866
return builder.get()
6967
.command(REG, "default-value-boolean1")
7068
.group(GROUP)
@@ -90,7 +88,7 @@ public String testDefaultValueBoolean2(
9088
}
9189

9290
@Bean
93-
public CommandRegistration testDefaultValueBoolean2Registration(Supplier<CommandRegistration.Builder> builder) {
91+
public CommandRegistration testDefaultValueBoolean2Registration(CommandRegistration.BuilderSupplier builder) {
9492
return builder.get()
9593
.command(REG, "default-value-boolean2")
9694
.group(GROUP)
@@ -116,7 +114,7 @@ public String testDefaultValueBoolean3(
116114
}
117115

118116
@Bean
119-
public CommandRegistration testDefaultValueBoolean3Registration(Supplier<CommandRegistration.Builder> builder) {
117+
public CommandRegistration testDefaultValueBoolean3Registration(CommandRegistration.BuilderSupplier builder) {
120118
return builder.get()
121119
.command(REG, "default-value-boolean3")
122120
.group(GROUP)

spring-shell-samples/src/main/java/org/springframework/shell/samples/e2e/ErrorHandlingCommands.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -17,7 +17,6 @@
1717

1818
import java.io.IOException;
1919
import java.io.PrintWriter;
20-
import java.util.function.Supplier;
2120

2221
import org.jline.terminal.Terminal;
2322

@@ -87,7 +86,7 @@ void errorHandler3(CustomException4 e, Terminal terminal) {
8786
}
8887

8988
@Bean
90-
CommandRegistration testErrorHandlingRegistration(Supplier<CommandRegistration.Builder> builder) {
89+
CommandRegistration testErrorHandlingRegistration(CommandRegistration.BuilderSupplier builder) {
9190
return builder.get()
9291
.command(REG, "error-handling")
9392
.group(GROUP)

spring-shell-samples/src/main/java/org/springframework/shell/samples/e2e/ExitCodeCommands.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.shell.samples.e2e;
1717

18-
import java.util.function.Supplier;
19-
2018
import org.springframework.context.annotation.Bean;
2119
import org.springframework.shell.command.CommandRegistration;
2220
import org.springframework.shell.standard.ShellComponent;
@@ -30,7 +28,7 @@
3028
public class ExitCodeCommands extends BaseE2ECommands {
3129

3230
@Bean
33-
public CommandRegistration testExitCodeRegistration(Supplier<CommandRegistration.Builder> builder) {
31+
public CommandRegistration testExitCodeRegistration(CommandRegistration.BuilderSupplier builder) {
3432
return builder.get()
3533
.command(REG, "exit-code")
3634
.group(GROUP)

spring-shell-samples/src/main/java/org/springframework/shell/samples/e2e/HelpOptionCommands.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 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.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.shell.samples.e2e;
1717

18-
import java.util.function.Supplier;
19-
2018
import org.springframework.beans.factory.annotation.Autowired;
2119
import org.springframework.context.annotation.Bean;
2220
import org.springframework.shell.command.CommandRegistration;
@@ -28,7 +26,7 @@
2826
public class HelpOptionCommands extends BaseE2ECommands {
2927

3028
@Autowired
31-
Supplier<CommandRegistration.Builder> builder;
29+
CommandRegistration.BuilderSupplier builder;
3230

3331
@ShellMethod(key = LEGACY_ANNO + "help-option-default", group = GROUP)
3432
public String testHelpOptionDefault(

0 commit comments

Comments
 (0)