Add Javadoc.

Fixes #27
This commit is contained in:
Eric Bottard
2017-05-17 12:08:01 +02:00
parent a676a34299
commit ea8908c019
15 changed files with 163 additions and 13 deletions

View File

@@ -36,6 +36,11 @@ import org.springframework.shell2.standard.EnumValueProvider;
import org.springframework.shell2.standard.StandardParameterResolver;
/**
* Main entry point for the application.
*
* <p>Creates the application context and start the REPL.</p>
*
* @author Eric Bottard
*/
@SpringBootApplication
@ComponentScan(basePackageClasses = {ArrayConverter.class, Bootstrap.class}, excludeFilters = @ComponentScan.Filter(

View File

@@ -20,7 +20,11 @@ import org.springframework.shell2.standard.ShellComponent;
import org.springframework.shell2.standard.ShellMethod;
/**
* Created by ericbottard on 27/12/15.
* Example commands for easy testing.
*
* To be removed in final project.
*
* @author Eric Bottard
*/
@ShellComponent("")
public class Commands {

View File

@@ -33,7 +33,10 @@ public class ExitRequest extends RuntimeException {
this.code = code;
}
/**
* The exit code to be returned when the process exits.
*/
public int status() {
return 0;
return code;
}
}

View File

@@ -21,7 +21,9 @@ import java.lang.reflect.Method;
import org.springframework.util.Assert;
/**
* Created by ericbottard on 27/11/15.
* Represents a shell command behavior, <em>i.e.</em> code to be executed when a command is requested.
*
* @author Eric Bottard
*/
public class MethodTarget {

View File

@@ -21,10 +21,15 @@ import java.util.Map;
import org.springframework.context.ApplicationContext;
/**
* Created by ericbottard on 09/12/15.
* Strategy interface for discovering commands.
*
* @author Eric Bottard
*/
public interface MethodTargetResolver {
/**
* Return a mapping from {@literal <command keyword(s)>} to actual behavior.
*/
public Map<String, MethodTarget> resolve(ApplicationContext context);
}

View File

@@ -21,16 +21,31 @@ import java.util.List;
import org.springframework.core.MethodParameter;
/**
* Created by ericbottard on 27/11/15.
* Implementations of this interface are responsible, once the command has been identified, of transforming the textual
* input to an actual parameter object.
*/
public interface ParameterResolver {
/**
* Should return true if this resolver recognizes the given method parameter (<em>e.g.</em> it
* has the correct annotation or the correct type).
*/
boolean supports(MethodParameter parameter);
/**
* Turn the given textual input into an actual object, maybe using some conversion or lookup mechanism.
*/
Object resolve(MethodParameter methodParameter, List<String> words);
/**
* Describe a supported parameter, so that integrated help can be generated.
*/
ParameterDescription describe(MethodParameter parameter);
/**
* Invoked during TAB completion. If the {@link CompletionContext} can be interpreted as the start
* of a supported {@link MethodParameter} value, one or several proposals should be returned.
*/
List<CompletionProposal> complete(MethodParameter parameter, CompletionContext context);
}

View File

@@ -19,11 +19,17 @@ package org.springframework.shell2;
import java.util.Map;
/**
* Created by ericbottard on 17/12/15.
* Implementing this interface allows sub-systems (such as the {@literal help} command) to
* discover available commands.
*
* @author Eric Bottard
*/
public interface Shell {
/**
* Return the mapping from command trigger keywords to implementation.
*/
public Map<String, MethodTarget> listCommands();
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Contains default commands that ought to apply to each shell app.
*
* @author Eric Bottard
*/
package org.springframework.shell2.commands;

View File

@@ -36,7 +36,9 @@ import org.springframework.shell2.ParameterResolver;
import org.springframework.util.ReflectionUtils;
/**
* Created by ericbottard on 15/12/15.
* Provides integration with JCommander.
*
* @author Eric Bottard
*/
public class JCommanderParameterResolver implements ParameterResolver {
@@ -50,8 +52,7 @@ public class JCommanderParameterResolver implements ParameterResolver {
Class<?> parameterType = parameter.getParameterType();
ReflectionUtils.doWithFields(parameterType, field -> {
ReflectionUtils.makeAccessible(field);
boolean hasAnnotation = Arrays.asList(field.getAnnotations())
.stream()
boolean hasAnnotation = Arrays.stream(field.getAnnotations())
.map(Annotation::annotationType)
.anyMatch(JCOMMANDER_ANNOTATIONS::contains);
isSupported.compareAndSet(false, hasAnnotation);
@@ -60,8 +61,7 @@ public class JCommanderParameterResolver implements ParameterResolver {
ReflectionUtils.doWithMethods(parameterType, method -> {
ReflectionUtils.makeAccessible(method);
boolean hasAnnotation = Arrays.asList(method.getAnnotations())
.stream()
boolean hasAnnotation = Arrays.stream(method.getAnnotations())
.map(Annotation::annotationType)
.anyMatch(Parameter.class::equals);
isSupported.compareAndSet(false, hasAnnotation);

View File

@@ -0,0 +1,22 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides integration with JCommander.
*
* @author Eric Bottard
*/
package org.springframework.shell2.jcommander;

View File

@@ -38,7 +38,9 @@ import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
/**
* Created by ericbottard on 09/12/15.
* Resolves parameters by looking at the {@link CliOption} annotation and acting accordingly.
*
* @author Eric Bottard
*/
@Component
public class LegacyParameterResolver implements ParameterResolver {

View File

@@ -0,0 +1,20 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides integration with Spring Shell 1.
*/
package org.springframework.shell2.legacy;

View File

@@ -0,0 +1,22 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Contains strategies for dealing with results of commands.
*
* @author Eric Bottard
*/
package org.springframework.shell2.result;

View File

@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
import org.springframework.stereotype.Component;
/**
* Indicates that an annotated class may contain shell methods (themselves annotated with {@link @ShellMethod}) that
* Indicates that an annotated class may contain shell methods (themselves annotated with {@link ShellMethod}) that
* is,
* methods that may be invoked reflectively by the shell.
*

View File

@@ -0,0 +1,22 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Contains infrastructure for describing commands with the "new" preferred Spring Shell programming model.
*
* @author Eric Bottard
*/
package org.springframework.shell2.standard;