private File getOutputFile(ParseResult parseResult) { return (File) parseResult.getArguments()[1]; }
@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); }
public HeadlessGfsh(String name, int timeout, Properties envProps, String parentDir) throws ClassNotFoundException, IOException { this.timeout = timeout; System.setProperty("jline.terminal", GfshUnsupportedTerminal.class.getName()); this.shell = new HeadlessGfshShell(name, this, parentDir); this.shell.setEnvProperty(Gfsh.ENV_APP_RESULT_VIEWER, "non-basic"); if (envProps != null) { for (String key : envProps.stringPropertyNames()) { this.shell.setEnvProperty(key, envProps.getProperty(key)); } } // This allows us to avoid race conditions during startup - in particular a NPE on the // ConsoleReader which is // created in a separate thread during start() CountDownLatch shellStarted = new CountDownLatch(1); this.shell.addShellStatusListener((oldStatus, newStatus) -> { if (newStatus.getStatus() == Status.STARTED) { shellStarted.countDown(); } }); this.shell.start(); try { shellStarted.await(); } catch (InterruptedException e) { e.printStackTrace(System.out); } }
/** * 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();
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); } } }
protected void setShellStatus(final Status shellStatus, final String msg, final ParseResult parseResult) { Assert.notNull(shellStatus, "Shell status required"); synchronized (this.shellStatus) { ShellStatus st; if (msg == null || msg.length() == 0) { st = new ShellStatus(shellStatus); } else { st = new ShellStatus(shellStatus, msg, parseResult); } if (this.shellStatus.equals(st)) { return; } for (ShellStatusListener listener : shellStatusListeners) { listener.onShellStatusChange(this.shellStatus, st); } this.shellStatus = st; } } }
@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; } }
protected void setShellStatus(final Status shellStatus) { setShellStatus(shellStatus, null, null); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((message == null) ? 0 : message.hashCode()); result = prime * result + ((parseResult == null) ? 0 : parseResult.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); return result; }
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); } }
/** * 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();
public void run() { while (!shellStatus.getStatus().equals(Status.SHUTTING_DOWN) && !shutdownHookFired) { synchronized (flashInfoMap) { long now = System.currentTimeMillis(); Set<String> toRemove = new HashSet<String>(); for (String slot : flashInfoMap.keySet()) { FlashInfo flashInfo = flashInfoMap.get(slot); if (flashInfo.flashMessageUntil < now) { // Message has expired, so clear it toRemove.add(slot); doAnsiFlash(flashInfo.rowNumber, Level.ALL, ""); } else { // The expiration time for this message has not been reached, so preserve it doAnsiFlash(flashInfo.rowNumber, flashInfo.flashLevel, flashInfo.flashMessage); } } for (String slot : toRemove) { flashInfoMap.remove(slot); } } try { Thread.sleep(200); } catch (InterruptedException ignore) { } } } }, getProductName() + " JLine Flash Message Manager");
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());