Document PromptProvider, ApplicationRunner and ConversionService.

Make the default ConversionService register converters in the ctx
This commit is contained in:
Eric Bottard
2017-09-19 13:57:28 +02:00
parent b9df6c48a9
commit a50b741af1
4 changed files with 200 additions and 5 deletions

View File

@@ -16,14 +16,20 @@
package org.springframework.shell;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
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.result.ResultHandlerConfig;
@@ -39,8 +45,22 @@ public class SpringShellAutoConfiguration {
@Bean
@ConditionalOnMissingBean(ConversionService.class)
public ConversionService conversionService() {
return new DefaultConversionService();
public ConversionService conversionService(ApplicationContext applicationContext) {
Collection<Converter> converters = applicationContext.getBeansOfType(Converter.class).values();
Collection<GenericConverter> genericConverters = applicationContext.getBeansOfType(GenericConverter.class).values();
Collection<ConverterFactory> converterFactories = applicationContext.getBeansOfType(ConverterFactory.class).values();
DefaultConversionService defaultConversionService = new DefaultConversionService();
for (Converter converter : converters) {
defaultConversionService.addConverter(converter);
}
for (GenericConverter genericConverter : genericConverters) {
defaultConversionService.addConverter(genericConverter);
}
for (ConverterFactory converterFactory : converterFactories) {
defaultConversionService.addConverterFactory(converterFactory);
}
return defaultConversionService;
}
@Bean

View File

@@ -46,9 +46,10 @@ import org.springframework.shell.Shell;
*
* @author Eric Bottard
*/
//tag::documentation[]
@Order(DefaultShellApplicationRunner.PRECEDENCE)
public class DefaultShellApplicationRunner implements ApplicationRunner {
//end::documentation[]
public static final int PRECEDENCE = 0;
private final LineReader lineReader;
@@ -66,6 +67,7 @@ public class DefaultShellApplicationRunner implements ApplicationRunner {
this.shell = shell;
}
//tag::documentation[]
@Override
public void run(ApplicationArguments args) throws Exception {
List<File> scriptsToRun = args.getNonOptionArgs().stream()
@@ -84,7 +86,7 @@ public class DefaultShellApplicationRunner implements ApplicationRunner {
}
}
}
//end::documentation[]
public static class JLineInputProvider implements InputProvider {
private final LineReader lineReader;