Skip to content

Commit ce9e138

Browse files
committed
GEODE-1912: use Spring shell's parser and delete our own parsing code
1 parent 4876c78 commit ce9e138

File tree

72 files changed

+1461
-8900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1461
-8900
lines changed

geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandManager.java

Lines changed: 113 additions & 432 deletions
Large diffs are not rendered by default.

geode-core/src/main/java/org/apache/geode/management/internal/cli/CommandResponseBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package org.apache.geode.management.internal.cli;
1616

17+
import org.apache.geode.management.cli.CliMetaData;
1718
import org.apache.geode.management.internal.cli.json.GfJsonException;
1819
import org.apache.geode.management.internal.cli.json.GfJsonObject;
1920
import org.apache.geode.management.internal.cli.remote.CommandExecutionContext;
@@ -24,8 +25,6 @@
2425
* @since GemFire 7.0
2526
*/
2627
public class CommandResponseBuilder {
27-
// Command Response Constants
28-
private static final String NO_TOKEN_ACCESSOR = "__NULL__";
2928

3029
public static CommandResponse prepareCommandResponse(String memberName, CommandResult result) {
3130
GfJsonObject content = null;
@@ -42,7 +41,7 @@ public static CommandResponse prepareCommandResponse(String memberName, CommandR
4241
getType(result), // contentType
4342
result.getStatus().getCode(), // status code
4443
"1/1", // page --- TODO - Abhishek - define a scrollable ResultData
45-
NO_TOKEN_ACCESSOR, // tokenAccessor for next results
44+
CliMetaData.ANNOTATION_NULL_VALUE, // tokenAccessor for next results
4645
getDebugInfo(result), // debugData
4746
result.getHeader(), // header
4847
content, // content

geode-core/src/main/java/org/apache/geode/management/internal/cli/GfshParseResult.java

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
*/
1515
package org.apache.geode.management.internal.cli;
1616

17+
import org.apache.commons.lang.StringUtils;
18+
import org.apache.geode.management.cli.CliMetaData;
19+
import org.apache.geode.management.internal.cli.shell.GfshExecutionStrategy;
20+
import org.apache.geode.management.internal.cli.shell.OperationInvoker;
21+
import org.springframework.shell.core.annotation.CliCommand;
22+
import org.springframework.shell.core.annotation.CliOption;
23+
import org.springframework.shell.event.ParseResult;
24+
25+
import java.lang.annotation.Annotation;
1726
import java.lang.reflect.Method;
1827
import java.util.Collections;
1928
import java.util.HashMap;
2029
import java.util.Map;
2130

22-
import org.springframework.shell.event.ParseResult;
23-
24-
import org.apache.geode.management.cli.CliMetaData;
25-
import org.apache.geode.management.internal.cli.shell.GfshExecutionStrategy;
26-
import org.apache.geode.management.internal.cli.shell.OperationInvoker;
27-
2831
/**
2932
* Immutable representation of the outcome of parsing a given shell line. * Extends
3033
* {@link ParseResult} to add a field to specify the command string that was input by the user.
@@ -41,7 +44,7 @@
4144
public class GfshParseResult extends ParseResult {
4245
private String userInput;
4346
private String commandName;
44-
private Map<String, String> paramValueStringMap;
47+
private Map<String, String> paramValueStringMap = new HashMap<>();
4548

4649
/**
4750
* Creates a GfshParseResult instance to represent parsing outcome.
@@ -52,12 +55,34 @@ public class GfshParseResult extends ParseResult {
5255
* @param userInput user specified commands string
5356
*/
5457
protected GfshParseResult(final Method method, final Object instance, final Object[] arguments,
55-
final String userInput, final String commandName,
56-
final Map<String, String> parametersAsString) {
58+
final String userInput) {
5759
super(method, instance, arguments);
58-
this.userInput = userInput;
59-
this.commandName = commandName;
60-
this.paramValueStringMap = new HashMap<String, String>(parametersAsString);
60+
this.userInput = userInput.trim();
61+
62+
CliCommand cliCommand = method.getAnnotation(CliCommand.class);
63+
commandName = cliCommand.value()[0];
64+
65+
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
66+
if (arguments == null) {
67+
return;
68+
}
69+
70+
for (int i = 0; i < arguments.length; i++) {
71+
Object argument = arguments[i];
72+
if (argument == null) {
73+
continue;
74+
}
75+
76+
CliOption cliOption = getCliOption(parameterAnnotations, i);
77+
78+
String argumentAsString;
79+
if (argument instanceof Object[]) {
80+
argumentAsString = StringUtils.join((Object[]) argument, ",");
81+
} else {
82+
argumentAsString = argument.toString();
83+
}
84+
paramValueStringMap.put(cliOption.key()[0], argumentAsString);
85+
}
6186
}
6287

6388
/**
@@ -67,26 +92,24 @@ public String getUserInput() {
6792
return userInput;
6893
}
6994

70-
7195
/**
7296
* @return the unmodifiable paramValueStringMap
7397
*/
7498
public Map<String, String> getParamValueStrings() {
7599
return Collections.unmodifiableMap(paramValueStringMap);
76100
}
77101

78-
@Override
79-
public String toString() {
80-
StringBuilder builder = new StringBuilder();
81-
builder.append(GfshParseResult.class.getSimpleName());
82-
builder.append(" [method=").append(getMethod());
83-
builder.append(", instance=").append(getInstance());
84-
builder.append(", arguments=").append(CliUtil.arrayToString(getArguments()));
85-
builder.append("]");
86-
return builder.toString();
87-
}
88-
89102
public String getCommandName() {
90103
return commandName;
91104
}
105+
106+
private CliOption getCliOption(Annotation[][] parameterAnnotations, int index) {
107+
Annotation[] annotations = parameterAnnotations[index];
108+
for (Annotation annotation : annotations) {
109+
if (annotation instanceof CliOption) {
110+
return (CliOption) annotation;
111+
}
112+
}
113+
return null;
114+
}
92115
}

0 commit comments

Comments
 (0)