Decoupling the MethodTargetResolver from the ApplicationContext
Fixes #39
This commit is contained in:
@@ -44,12 +44,10 @@ import org.jline.terminal.Terminal;
|
||||
import org.jline.utils.AttributedString;
|
||||
import org.jline.utils.AttributedStringBuilder;
|
||||
import org.jline.utils.AttributedStyle;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.shell2.result.TypeHierarchyResultHandler;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -95,7 +93,7 @@ public class JLineShell implements Shell {
|
||||
@PostConstruct
|
||||
public void init() throws Exception {
|
||||
for (MethodTargetResolver resolver : applicationContext.getBeansOfType(MethodTargetResolver.class).values()) {
|
||||
methodTargets.putAll(resolver.resolve(applicationContext));
|
||||
methodTargets.putAll(resolver.resolve());
|
||||
}
|
||||
|
||||
LineReaderBuilder lineReaderBuilder = LineReaderBuilder.builder()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2017 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.
|
||||
@@ -18,18 +18,17 @@ package org.springframework.shell2;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* Strategy interface for discovering commands.
|
||||
*
|
||||
* @author Eric Bottard
|
||||
* @author Camilo Gonzalez
|
||||
*/
|
||||
public interface MethodTargetResolver {
|
||||
|
||||
/**
|
||||
* Return a mapping from {@literal <command keyword(s)>} to actual behavior.
|
||||
*/
|
||||
public Map<String, MethodTarget> resolve(ApplicationContext context);
|
||||
public Map<String, MethodTarget> resolve();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2017 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.shell2.standard;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.shell2.MethodTarget;
|
||||
import org.springframework.shell2.MethodTargetResolver;
|
||||
@@ -31,12 +32,16 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Eric Bottard
|
||||
* @author Florent Biville
|
||||
* @author Camilo Gonzalez
|
||||
*/
|
||||
@Component
|
||||
public class StandardMethodTargetResolver implements MethodTargetResolver {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public Map<String, MethodTarget> resolve(ApplicationContext applicationContext) {
|
||||
public Map<String, MethodTarget> resolve() {
|
||||
Map<String, MethodTarget> methodTargets = new HashMap<>();
|
||||
Map<String, Object> commandBeans = applicationContext.getBeansWithAnnotation(ShellComponent.class);
|
||||
for (Object bean : commandBeans.values()) {
|
||||
|
||||
Reference in New Issue
Block a user