Skip to content

Commit cf83eb8

Browse files
committed
Extract autoconfig
- Create separate spring-shell-autoconfigure and keep all autoconfig features there. - Fixes #329
1 parent a2f3dd9 commit cf83eb8

File tree

21 files changed

+132
-55
lines changed

21 files changed

+132
-55
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<module>spring-shell-docs</module>
3737
<module>spring-shell-dependencies</module>
3838
<module>spring-shell-starter</module>
39+
<module>spring-shell-autoconfigure</module>
3940
</modules>
4041

4142
<dependencyManagement>
@@ -75,6 +76,11 @@
7576
<artifactId>spring-shell-table</artifactId>
7677
<version>3.0.0-SNAPSHOT</version>
7778
</dependency>
79+
<dependency>
80+
<groupId>org.springframework.shell</groupId>
81+
<artifactId>spring-shell-autoconfigure</artifactId>
82+
<version>3.0.0-SNAPSHOT</version>
83+
</dependency>
7884
<dependency>
7985
<groupId>org.jline</groupId>
8086
<artifactId>jline</artifactId>

spring-shell-autoconfigure/pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>spring-shell-autoconfigure</artifactId>
6+
<name>Spring Shell Autoconfigure</name>
7+
<packaging>jar</packaging>
8+
9+
<parent>
10+
<groupId>org.springframework.shell</groupId>
11+
<artifactId>spring-shell-parent</artifactId>
12+
<version>3.0.0-SNAPSHOT</version>
13+
</parent>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-autoconfigure</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.springframework.shell</groupId>
22+
<artifactId>spring-shell-core</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.shell</groupId>
26+
<artifactId>spring-shell-standard-commands</artifactId>
27+
<optional>true</optional>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.beust</groupId>
31+
<artifactId>jcommander</artifactId>
32+
<optional>true</optional>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.shell</groupId>
36+
<artifactId>spring-shell-jcommander-adapter</artifactId>
37+
<optional>true</optional>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-test</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
</project>

spring-shell-core/src/main/java/org/springframework/shell/ApplicationRunnerAutoConfiguration.java renamed to spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/ApplicationRunnerAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.shell;
16+
package org.springframework.shell.boot;
1717

1818
import org.jline.reader.LineReader;
1919
import org.jline.reader.Parser;
@@ -25,6 +25,7 @@
2525
import org.springframework.context.annotation.Configuration;
2626
import org.springframework.core.env.ConfigurableEnvironment;
2727
import org.springframework.core.env.Environment;
28+
import org.springframework.shell.Shell;
2829
import org.springframework.shell.jline.InteractiveShellApplicationRunner;
2930
import org.springframework.shell.jline.PromptProvider;
3031
import org.springframework.shell.jline.ScriptShellApplicationRunner;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.shell;
16+
package org.springframework.shell.boot;
1717

1818
import org.springframework.beans.factory.ObjectProvider;
1919
import org.springframework.context.annotation.Bean;
2020
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.shell.CommandRegistry;
22+
import org.springframework.shell.ConfigurableCommandRegistry;
23+
import org.springframework.shell.MethodTargetRegistrar;
2124

2225
@Configuration(proxyBeanMethods = false)
2326
public class CommandRegistryAutoConfiguration {

spring-shell-core/src/main/java/org/springframework/shell/CompleterAutoConfiguration.java renamed to spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/CompleterAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.shell;
16+
package org.springframework.shell.boot;
1717

1818
import java.util.List;
1919
import java.util.stream.Collectors;
@@ -26,6 +26,10 @@
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.shell.CompletingParsedLine;
30+
import org.springframework.shell.CompletionContext;
31+
import org.springframework.shell.CompletionProposal;
32+
import org.springframework.shell.Shell;
2933

3034
@Configuration
3135
public class CompleterAutoConfiguration {
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2021 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.
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.shell.jcommander;
17+
package org.springframework.shell.boot;
1818

1919
import com.beust.jcommander.JCommander;
2020

2121
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2222
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.shell.jcommander.JCommanderParameterResolver;
2324
import org.springframework.context.annotation.Bean;
2425

2526
/**
@@ -28,7 +29,7 @@
2829
* @author Eric Bottard
2930
*/
3031
@Configuration
31-
@ConditionalOnClass(JCommander.class)
32+
@ConditionalOnClass({ JCommander.class, JCommanderParameterResolver.class })
3233
public class JCommanderParameterResolverAutoConfiguration {
3334

3435
@Bean

spring-shell-core/src/main/java/org/springframework/shell/JLineAutoConfiguration.java renamed to spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/JLineAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.shell;
16+
package org.springframework.shell.boot;
1717

1818
import org.jline.reader.impl.history.DefaultHistory;
1919

spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java renamed to spring-shell-autoconfigure/src/main/java/org/springframework/shell/boot/JLineShellAutoConfiguration.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2021 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.
@@ -14,11 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.shell.jline;
17+
package org.springframework.shell.boot;
1818

1919
import java.io.IOException;
20-
import java.util.List;
21-
import java.util.stream.Collectors;
2220

2321
import org.jline.reader.Parser;
2422
import org.jline.terminal.Terminal;
@@ -30,6 +28,8 @@
3028
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3129
import org.springframework.context.annotation.Bean;
3230
import org.springframework.context.annotation.Configuration;
31+
import org.springframework.shell.jline.ExtendedDefaultParser;
32+
import org.springframework.shell.jline.PromptProvider;
3333

3434
/**
3535
* Shell implementation using JLine to capture input and trigger completions.
@@ -63,16 +63,4 @@ public Parser parser() {
6363
parser.setEofOnEscapedNewLine(true);
6464
return parser;
6565
}
66-
67-
/**
68-
* Sanitize the buffer input given the customizations applied to the JLine parser (<em>e.g.</em> support for
69-
* line continuations, <em>etc.</em>)
70-
*/
71-
static List<String> sanitizeInput(List<String> words) {
72-
words = words.stream()
73-
.map(s -> s.replaceAll("^\\n+|\\n+$", "")) // CR at beginning/end of line introduced by backslash continuation
74-
.map(s -> s.replaceAll("\\n+", " ")) // CR in middle of word introduced by return inside a quoted string
75-
.collect(Collectors.toList());
76-
return words;
77-
}
7866
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.shell;
16+
package org.springframework.shell.boot;
1717

1818
import java.io.IOException;
1919
import java.nio.file.Paths;
@@ -35,6 +35,7 @@
3535
import org.springframework.context.annotation.Configuration;
3636
import org.springframework.context.event.ContextClosedEvent;
3737
import org.springframework.context.event.EventListener;
38+
import org.springframework.shell.CommandRegistry;
3839

3940
@Configuration
4041
public class LineReaderAutoConfiguration {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2021 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.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.shell;
17+
package org.springframework.shell.boot;
1818

1919
import java.util.Collection;
2020

@@ -32,6 +32,8 @@
3232
import org.springframework.core.convert.converter.ConverterFactory;
3333
import org.springframework.core.convert.converter.GenericConverter;
3434
import org.springframework.core.convert.support.DefaultConversionService;
35+
import org.springframework.shell.ResultHandler;
36+
import org.springframework.shell.Shell;
3537
import org.springframework.shell.result.IterableResultHandler;
3638
import org.springframework.shell.result.ResultHandlerConfig;
3739

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2021 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.
@@ -14,26 +14,34 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.shell.standard.commands;
17+
package org.springframework.shell.boot;
1818

1919
import java.util.List;
2020

2121
import org.jline.reader.Parser;
2222

2323
import org.springframework.beans.factory.ObjectProvider;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2425
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2627
import org.springframework.context.annotation.Bean;
2728
import org.springframework.context.annotation.Configuration;
2829
import org.springframework.shell.ParameterResolver;
2930
import org.springframework.shell.Shell;
31+
import org.springframework.shell.standard.commands.Clear;
32+
import org.springframework.shell.standard.commands.Help;
33+
import org.springframework.shell.standard.commands.History;
34+
import org.springframework.shell.standard.commands.Quit;
35+
import org.springframework.shell.standard.commands.Script;
36+
import org.springframework.shell.standard.commands.Stacktrace;
3037

3138
/**
3239
* Creates beans for standard commands.
3340
*
3441
* @author Eric Bottard
3542
*/
3643
@Configuration
44+
@ConditionalOnClass({ Help.Command.class })
3745
public class StandardCommandsAutoConfiguration {
3846

3947
@Bean
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2+
org.springframework.shell.boot.SpringShellAutoConfiguration,\
3+
org.springframework.shell.boot.ApplicationRunnerAutoConfiguration,\
4+
org.springframework.shell.boot.CommandRegistryAutoConfiguration,\
5+
org.springframework.shell.boot.LineReaderAutoConfiguration,\
6+
org.springframework.shell.boot.CompleterAutoConfiguration,\
7+
org.springframework.shell.boot.JLineAutoConfiguration,\
8+
org.springframework.shell.boot.JLineShellAutoConfiguration,\
9+
org.springframework.shell.boot.JCommanderParameterResolverAutoConfiguration,\
10+
org.springframework.shell.boot.StandardCommandsAutoConfiguration

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2021 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.
@@ -20,6 +20,8 @@
2020
import java.lang.reflect.Executable;
2121
import java.lang.reflect.Method;
2222
import java.lang.reflect.Parameter;
23+
import java.util.List;
24+
import java.util.stream.Collectors;
2325
import java.util.stream.IntStream;
2426
import java.util.stream.Stream;
2527

@@ -86,4 +88,16 @@ public static Stream<MethodParameter> createMethodParameters(Executable executab
8688
.mapToObj(i -> createMethodParameter(executable, i));
8789
}
8890

91+
/**
92+
* Sanitize the buffer input given the customizations applied to the JLine
93+
* parser (<em>e.g.</em> support for
94+
* line continuations, <em>etc.</em>)
95+
*/
96+
public static List<String> sanitizeInput(List<String> words) {
97+
words = words.stream()
98+
.map(s -> s.replaceAll("^\\n+|\\n+$", "")) // CR at beginning/end of line introduced by backslash continuation
99+
.map(s -> s.replaceAll("\\n+", " ")) // CR in middle of word introduced by return inside a quoted string
100+
.collect(Collectors.toList());
101+
return words;
102+
}
89103
}

spring-shell-core/src/main/java/org/springframework/shell/jline/ExtendedDefaultParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2021 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.
@@ -35,7 +35,7 @@
3535
* @author Original JLine author
3636
* @author Eric Bottard
3737
*/
38-
class ExtendedDefaultParser implements Parser {
38+
public class ExtendedDefaultParser implements Parser {
3939

4040
private char[] quoteChars = { '\'', '"' };
4141

spring-shell-core/src/main/java/org/springframework/shell/jline/ParsedLineInput.java

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

1717
package org.springframework.shell.jline;
1818

19+
import java.util.List;
20+
1921
import org.jline.reader.ParsedLine;
20-
import org.springframework.shell.Input;
2122

22-
import java.util.List;
23+
import org.springframework.shell.Input;
24+
import org.springframework.shell.Utils;
2325

2426
/**
2527
* An implementation of {@link Input} backed by the result of a {@link org.jline.reader.Parser#parse(String, int)}.
@@ -41,6 +43,6 @@ public String rawText() {
4143

4244
@Override
4345
public List<String> words() {
44-
return JLineShellAutoConfiguration.sanitizeInput(parsedLine.words());
46+
return Utils.sanitizeInput(parsedLine.words());
4547
}
4648
}
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2-
org.springframework.shell.SpringShellAutoConfiguration,\
3-
org.springframework.shell.ApplicationRunnerAutoConfiguration,\
4-
org.springframework.shell.CommandRegistryAutoConfiguration,\
5-
org.springframework.shell.LineReaderAutoConfiguration,\
6-
org.springframework.shell.CompleterAutoConfiguration,\
7-
org.springframework.shell.JLineAutoConfiguration,\
8-
org.springframework.shell.jline.JLineShellAutoConfiguration

spring-shell-docs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<artifactId>spring-shell-docs</artifactId>
66
<name>Spring Shell Documentation</name>
7-
<packaging>jar</packaging>
7+
<packaging>pom</packaging>
88

99
<parent>
1010
<groupId>org.springframework.shell</groupId>

0 commit comments

Comments
 (0)