Extract autoconfig

- Create separate spring-shell-autoconfigure and keep
  all autoconfig features there.
- Fixes #329
This commit is contained in:
Janne Valkealahti
2021-12-19 12:31:22 +00:00
parent a2f3dd9ed8
commit 5dcdc4c185
21 changed files with 133 additions and 56 deletions

View File

@@ -36,6 +36,7 @@
<module>spring-shell-docs</module>
<module>spring-shell-dependencies</module>
<module>spring-shell-starter</module>
<module>spring-shell-autoconfigure</module>
</modules>
<dependencyManagement>
@@ -75,6 +76,11 @@
<artifactId>spring-shell-table</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-autoconfigure</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-shell-autoconfigure</artifactId>
<name>Spring Shell Autoconfigure</name>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-standard-commands</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-jcommander-adapter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell;
package org.springframework.shell.boot;
import org.jline.reader.LineReader;
import org.jline.reader.Parser;
@@ -25,6 +25,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.shell.Shell;
import org.springframework.shell.jline.InteractiveShellApplicationRunner;
import org.springframework.shell.jline.PromptProvider;
import org.springframework.shell.jline.ScriptShellApplicationRunner;

View File

@@ -13,11 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell;
package org.springframework.shell.boot;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.CommandRegistry;
import org.springframework.shell.ConfigurableCommandRegistry;
import org.springframework.shell.MethodTargetRegistrar;
@Configuration(proxyBeanMethods = false)
public class CommandRegistryAutoConfiguration {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell;
package org.springframework.shell.boot;
import java.util.List;
import java.util.stream.Collectors;
@@ -26,6 +26,10 @@ import org.jline.reader.ParsedLine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.CompletingParsedLine;
import org.springframework.shell.CompletionContext;
import org.springframework.shell.CompletionProposal;
import org.springframework.shell.Shell;
@Configuration
public class CompleterAutoConfiguration {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,12 +14,13 @@
* limitations under the License.
*/
package org.springframework.shell.jcommander;
package org.springframework.shell.boot;
import com.beust.jcommander.JCommander;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.jcommander.JCommanderParameterResolver;
import org.springframework.context.annotation.Bean;
/**
@@ -28,7 +29,7 @@ import org.springframework.context.annotation.Bean;
* @author Eric Bottard
*/
@Configuration
@ConditionalOnClass(JCommander.class)
@ConditionalOnClass({ JCommander.class, JCommanderParameterResolver.class })
public class JCommanderParameterResolverAutoConfiguration {
@Bean

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell;
package org.springframework.shell.boot;
import org.jline.reader.impl.history.DefaultHistory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,11 +14,9 @@
* limitations under the License.
*/
package org.springframework.shell.jline;
package org.springframework.shell.boot;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import org.jline.reader.Parser;
import org.jline.terminal.Terminal;
@@ -30,6 +28,8 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.jline.ExtendedDefaultParser;
import org.springframework.shell.jline.PromptProvider;
/**
* Shell implementation using JLine to capture input and trigger completions.
@@ -63,16 +63,4 @@ public class JLineShellAutoConfiguration {
parser.setEofOnEscapedNewLine(true);
return parser;
}
/**
* Sanitize the buffer input given the customizations applied to the JLine parser (<em>e.g.</em> support for
* line continuations, <em>etc.</em>)
*/
static List<String> sanitizeInput(List<String> words) {
words = words.stream()
.map(s -> s.replaceAll("^\\n+|\\n+$", "")) // CR at beginning/end of line introduced by backslash continuation
.map(s -> s.replaceAll("\\n+", " ")) // CR in middle of word introduced by return inside a quoted string
.collect(Collectors.toList());
return words;
}
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell;
package org.springframework.shell.boot;
import java.io.IOException;
import java.nio.file.Paths;
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.shell.CommandRegistry;
@Configuration
public class LineReaderAutoConfiguration {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.shell;
package org.springframework.shell.boot;
import java.util.Collection;
@@ -32,6 +32,8 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.shell.ResultHandler;
import org.springframework.shell.Shell;
import org.springframework.shell.result.IterableResultHandler;
import org.springframework.shell.result.ResultHandlerConfig;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,19 +14,26 @@
* limitations under the License.
*/
package org.springframework.shell.standard.commands;
package org.springframework.shell.boot;
import java.util.List;
import org.jline.reader.Parser;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.shell.ParameterResolver;
import org.springframework.shell.Shell;
import org.springframework.shell.standard.commands.Clear;
import org.springframework.shell.standard.commands.Help;
import org.springframework.shell.standard.commands.History;
import org.springframework.shell.standard.commands.Quit;
import org.springframework.shell.standard.commands.Script;
import org.springframework.shell.standard.commands.Stacktrace;
/**
* Creates beans for standard commands.
@@ -34,6 +41,7 @@ import org.springframework.shell.Shell;
* @author Eric Bottard
*/
@Configuration
@ConditionalOnClass({ Help.Command.class })
public class StandardCommandsAutoConfiguration {
@Bean

View File

@@ -0,0 +1,10 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.shell.boot.SpringShellAutoConfiguration,\
org.springframework.shell.boot.ApplicationRunnerAutoConfiguration,\
org.springframework.shell.boot.CommandRegistryAutoConfiguration,\
org.springframework.shell.boot.LineReaderAutoConfiguration,\
org.springframework.shell.boot.CompleterAutoConfiguration,\
org.springframework.shell.boot.JLineAutoConfiguration,\
org.springframework.shell.boot.JLineShellAutoConfiguration,\
org.springframework.shell.boot.JCommanderParameterResolverAutoConfiguration,\
org.springframework.shell.boot.StandardCommandsAutoConfiguration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@@ -86,4 +88,16 @@ public class Utils {
.mapToObj(i -> createMethodParameter(executable, i));
}
/**
* Sanitize the buffer input given the customizations applied to the JLine
* parser (<em>e.g.</em> support for
* line continuations, <em>etc.</em>)
*/
public static List<String> sanitizeInput(List<String> words) {
words = words.stream()
.map(s -> s.replaceAll("^\\n+|\\n+$", "")) // CR at beginning/end of line introduced by backslash continuation
.map(s -> s.replaceAll("\\n+", " ")) // CR in middle of word introduced by return inside a quoted string
.collect(Collectors.toList());
return words;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ import org.springframework.shell.CompletingParsedLine;
* @author Original JLine author
* @author Eric Bottard
*/
class ExtendedDefaultParser implements Parser {
public class ExtendedDefaultParser implements Parser {
private char[] quoteChars = { '\'', '"' };

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,13 @@
package org.springframework.shell.jline;
import org.jline.reader.ParsedLine;
import org.springframework.shell.Input;
import java.util.List;
import org.jline.reader.ParsedLine;
import org.springframework.shell.Input;
import org.springframework.shell.Utils;
/**
* An implementation of {@link Input} backed by the result of a {@link org.jline.reader.Parser#parse(String, int)}.
*
@@ -41,6 +43,6 @@ class ParsedLineInput implements Input {
@Override
public List<String> words() {
return JLineShellAutoConfiguration.sanitizeInput(parsedLine.words());
return Utils.sanitizeInput(parsedLine.words());
}
}

View File

@@ -1,8 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.shell.SpringShellAutoConfiguration,\
org.springframework.shell.ApplicationRunnerAutoConfiguration,\
org.springframework.shell.CommandRegistryAutoConfiguration,\
org.springframework.shell.LineReaderAutoConfiguration,\
org.springframework.shell.CompleterAutoConfiguration,\
org.springframework.shell.JLineAutoConfiguration,\
org.springframework.shell.jline.JLineShellAutoConfiguration

View File

@@ -4,7 +4,7 @@
<artifactId>spring-shell-docs</artifactId>
<name>Spring Shell Documentation</name>
<packaging>jar</packaging>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.shell</groupId>

View File

@@ -1,2 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.shell.jcommander.JCommanderParameterResolverAutoConfiguration

View File

@@ -19,16 +19,16 @@ package org.springframework.shell.samples.noautoconf;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.shell.SpringShellAutoConfiguration;
import org.springframework.shell.jcommander.JCommanderParameterResolverAutoConfiguration;
import org.springframework.shell.jline.JLineShellAutoConfiguration;
import org.springframework.shell.boot.JCommanderParameterResolverAutoConfiguration;
import org.springframework.shell.boot.JLineShellAutoConfiguration;
import org.springframework.shell.boot.SpringShellAutoConfiguration;
import org.springframework.shell.boot.StandardCommandsAutoConfiguration;
import org.springframework.shell.samples.jcommander.JCommanderCommands;
import org.springframework.shell.samples.standard.Commands;
import org.springframework.shell.samples.standard.DynamicCommands;
import org.springframework.shell.samples.standard.TableCommands;
import org.springframework.shell.standard.FileValueProvider;
import org.springframework.shell.standard.StandardAPIAutoConfiguration;
import org.springframework.shell.standard.commands.StandardCommandsAutoConfiguration;
/**
* This class shows how to use the full extent of Spring Shell without relying on Boot auto configuration.

View File

@@ -1,2 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.shell.standard.commands.StandardCommandsAutoConfiguration

View File

@@ -4,17 +4,21 @@
<artifactId>spring-shell-starter</artifactId>
<name>Spring Shell Starter</name>
<packaging>jar</packaging>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<description>Starter Dependency for Using Spring Shell</description>
<dependencies>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-core</artifactId>
@@ -36,5 +40,5 @@
<artifactId>spring-shell-table</artifactId>
</dependency>
</dependencies>
</project>