@Override public GfshParseResult parse(String userInput) { String rawInput = convertToSimpleParserInput(userInput); // this tells the simpleParser not to interpret backslash as escaping character rawInput = rawInput.replace("\\", "\\\\"); // User SimpleParser to parse the input ParseResult result = super.parse(rawInput); if (result == null) { return null; } return new GfshParseResult(result.getMethod(), result.getInstance(), result.getArguments(), userInput); }
/** * This Code piece allows lens cli to be able to parse list arguments. It can already parse keyword args. * More details at https://github.com/spring-projects/spring-shell/issues/72 * @param parseResult * @return */ @Override public ParseResult beforeInvocation(ParseResult parseResult) { Object[] args = parseResult.getArguments(); if (args != null && Sets.newHashSet(args).size() == 1) { if (args[0] instanceof String) { String[] split = ((String) args[0]).split("\\s+"); Object[] newArgs = new String[args.length]; System.arraycopy(split, 0, newArgs, 0, split.length); parseResult = new ParseResult(parseResult.getMethod(), parseResult.getInstance(), newArgs); } } return parseResult; }
public Object execute(ParseResult parseResult) throws RuntimeException { Object obj = null; String command = null; try { String method = parseResult.getMethod().getName(); String className = parseResult.getInstance().getClass().getCanonicalName(); command = className + "." + method; Util.log("Executing command " + command + " with Gfsh instance " + gfshThreadLocal.get()); long l1 = System.currentTimeMillis(); obj = oldStrategy.execute(parseResult); long l2 = System.currentTimeMillis(); Util.log("Completed execution of command " + command + " in " + (l2-l1) + " ms."); if(obj!=null){ Util.log("Command output class is " + obj.getClass()); }else{ obj = "VOID"; } } catch (Exception e) { addError("Error running command " , e); throw new RuntimeException(e); } Util.debug("Adding outuut and notifying threads .."); addOutput(command, obj); if(command.equals(EXIT_SHELL_COMMAND)) resultLatch.countDown(); return obj; }
parse = parser.parse(input); assertNotNull(parse); assertEquals("Check ParseResult method", parse.getMethod(), METHOD_command1); assertEquals("Check no. of method arguments", 5, parse.getArguments().length); assertEquals("Check argument1", "ARGUMENT1_VALUE", parse.getArguments()[0]); assertEquals("Check argument2", ARGUMENT2_UNSPECIFIED_DEFAULT_VALUE, parse.getArguments()[1]); assertEquals("Check option1 value", "somevalue", parse.getArguments()[2]); assertEquals("Check option2 value", null, parse.getArguments()[3]); assertEquals("Check option3 value", OPTION3_UNSPECIFIED_DEFAULT_VALUE, parse.getArguments()[4]); parse = parser.parse(input); assertNotNull(parse); assertEquals("Check ParseResult method", parse.getMethod(), METHOD_command1); assertEquals("Check no. of method arguments", 5, parse.getArguments().length); assertEquals("Check argument1", "ARGUMENT1_VALUE", parse.getArguments()[0]); assertEquals("Check argument2", "ARGUMENT2_VALUE", parse.getArguments()[1]); assertEquals("Check option1 value", "option1value", parse.getArguments()[2]); assertEquals("Check option2 value", OPTION2_SPECIFIED_DEFAULT_VALUE, parse.getArguments()[3]); assertEquals("Check option3 value", OPTION3_UNSPECIFIED_DEFAULT_VALUE, parse.getArguments()[4]); parse = parser.parse(input); assertNotNull(parse); assertEquals("Check ParseResult method", parse.getMethod(), METHOD_command1);
public Object execute(ParseResult parseResult) { Result result; Method method = parseResult.getMethod();
private File getOutputFile(ParseResult parseResult) { return (File) parseResult.getArguments()[1]; }
public Object execute(ParseResult parseResult) throws RuntimeException { Assert.notNull(parseResult, "Parse result required"); synchronized (mutex) { Assert.isTrue(isReadyForCommands(), "SimpleExecutionStrategy not yet ready for commands"); Object target = parseResult.getInstance(); if (target instanceof ExecutionProcessor) { ExecutionProcessor processor = ((ExecutionProcessor) target); parseResult = processor.beforeInvocation(parseResult); try { Object result = invoke(parseResult); processor.afterReturningInvocation(parseResult, result); return result; } catch (Throwable th) { processor.afterThrowingInvocation(parseResult, th); return handleThrowable(th); } } else { return invoke(parseResult); } } }
if (parameterAnnotations.length == 0) { return new ParseResult(methodTarget.getMethod(), methodTarget.getTarget(), null); return new ParseResult(methodTarget.getMethod(), methodTarget.getTarget(), arguments.toArray());
@Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ShellStatus other = (ShellStatus) obj; if (message == null) { if (other.message != null) return false; } else if (!message.equals(other.message)) return false; if (parseResult == null) { if (other.parseResult != null) return false; } else if (!parseResult.equals(other.parseResult)) return false; if (status == null) { if (other.status != null) return false; } else if (!status.equals(other.status)) return false; return true; } }
/** * This Code piece allows lens cli to be able to parse list arguments. It can already parse keyword args. * More details at https://github.com/spring-projects/spring-shell/issues/72 * @param parseResult * @return */ @Override public ParseResult beforeInvocation(ParseResult parseResult) { Object[] args = parseResult.getArguments(); if (args != null && Sets.newHashSet(args).size() == 1) { if (args[0] instanceof String) { String[] split = ((String) args[0]).split("\\s+"); Object[] newArgs = new String[args.length]; System.arraycopy(split, 0, newArgs, 0, split.length); parseResult = new ParseResult(parseResult.getMethod(), parseResult.getInstance(), newArgs); } } return parseResult; }
Method method = parseResult.getMethod();
private Object invoke(ParseResult parseResult) { try { Method method = parseResult.getMethod(); ReflectionUtils.makeAccessible(method); return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments()); } catch (Throwable th) { logger.severe("Command failed " + th); return handleThrowable(th); } }
public static Object execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) { CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); if (steps != null) { boolean endStepReached = false;
public static Object execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) { CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); if (steps != null) { boolean endStepReached = false;
public Object execute(ParseResult parseResult){ Object result = null; Method method = parseResult.getMethod(); try { Method reflectmethod = parseResult.getMethod(); MultiStepCommand cmd = reflectmethod.getAnnotation(MultiStepCommand.class); if(cmd!=null){ result = ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());
public Object execute(ParseResult parseResult){ Object result = null; Method method = parseResult.getMethod(); try { Method reflectmethod = parseResult.getMethod(); MultiStepCommand cmd = reflectmethod.getAnnotation(MultiStepCommand.class); if(cmd!=null){ result = ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());