@Override public void handle(String line) throws CommandLineException { wrapped.handle(line); }
private static void executeCommands(final CommandContext ctx, final Iterable<String> commands, final boolean failOnError) throws MojoExecutionException { for (String cmd : commands) { try { if (failOnError) { ctx.handle(cmd); } else { ctx.handleSafe(cmd); } } catch (CommandFormatException e) { throw new MojoExecutionException(String.format("Command '%s' is invalid. %s", cmd, e.getLocalizedMessage()), e); } catch (CommandLineException e) { throw new MojoExecutionException(String.format("Command execution failed for command '%s'. %s", cmd, e.getLocalizedMessage()), e); } } }
/** * Sends command line to CLI. * * @param line specifies the command line. * @param readEcho if set to true reads the echo response form the CLI. * @throws Exception */ public boolean sendLine(String line, boolean ignoreError) { consoleOut.reset(); if(ignoreError) { ctx.handleSafe(line); return ctx.getExitCode() == 0; } else { try { ctx.handle(line); } catch (CommandLineException e) { Assert.fail("Failed to execute line '" + line + "': " + e.getLocalizedMessage()); } } return true; }
@Override public void handle(String line) throws CommandLineException { wrapped.handle(line); }
/** * Sends command line to CLI. * * @param line specifies the command line. * @param ignoreError if set to false, asserts that handling the line did not result in a {@link org.jboss.as.cli.CommandLineException}. * * @return true if the CLI is in a non-error state following handling the line */ public boolean sendLine(String line, boolean ignoreError) { consoleOut.reset(); if(ignoreError) { ctx.handleSafe(line); return ctx.getExitCode() == 0; } else { try { ctx.handle(line); } catch (CommandLineException e) { StringWriter stackTrace = new StringWriter(); e.printStackTrace(new PrintWriter(stackTrace)); Assert.fail(String.format("Failed to execute line '%s'%n%s", line, stackTrace.toString())); } } return true; }
public void handle(String line) throws CommandLineException { delegate.handle(line); }
public void handle(String line) throws CommandLineException { delegate.handle(line); }
/** * Sends command line to CLI. * * @param line specifies the command line. * @throws org.jboss.as.cli.CommandLineException */ public void sendLineForValidation(String line) throws CommandLineException { consoleOut.reset(); ctx.handle(line); } /**
private void executeCommands(final CommandContext ctx) throws IOException { for (String cmd : commands) { try { ctx.handle(cmd); } catch (CommandFormatException e) { throw new IllegalArgumentException(String.format("Command '%s' is invalid. %s", cmd, e.getLocalizedMessage()), e); } catch (CommandLineException e) { throw new IllegalArgumentException(String.format("Command execution failed for command '%s'. %s", cmd, e.getLocalizedMessage()), e); } } }
private void executeScripts(final CommandContext ctx) throws IOException { for (File script : scripts) { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(script), "UTF-8")); String line = reader.readLine(); while (!ctx.isTerminated() && line != null) { try { ctx.handle(line.trim()); } catch (CommandFormatException e) { throw new IllegalArgumentException(String.format("Command '%s' is invalid. %s", line, e.getLocalizedMessage()), e); } catch (CommandLineException e) { throw new IllegalArgumentException(String.format("Command execution failed for command '%s'. %s", line, e.getLocalizedMessage()), e); } line = reader.readLine(); } } catch (Exception e) { throw new IllegalStateException("Failed to process file '" + script.getAbsolutePath() + "'", e); } finally { IoUtils.safeClose(reader); } } }
@Override protected void executeInternal(String command) throws Exception { try { context.handle(command); } catch (CommandLineException e) { if (context.getBatchManager().isBatchActive()) { context.getBatchManager().discardActiveBatch(); } throw new IllegalArgumentException(String.format("Command execution failed for command '%s'. %s", command, e.getLocalizedMessage()), e); } }
private void executeBlock(CommandContext ctx, List<String> block, String blockName) throws CommandLineException { if(block != null && !block.isEmpty()) { final BatchManager batchManager = ctx.getBatchManager(); // this is to discard a batch started by the block in case the block fails // as the cli remains in the batch mode in case run-batch resulted in an error final boolean discardActivatedBatch = !batchManager.isBatchActive(); try { for (String l : block) { ctx.handle(l); } } finally { if(discardActivatedBatch && batchManager.isBatchActive()) { batchManager.discardActiveBatch(); } } } }
public static void execute(CommandContext ctx, ModelNode request, FailureConsumer consumer, boolean noReload) throws CommandException { execute(ctx, request, consumer); if (!noReload) { try { String mode = Util.getRunningMode(ctx); ctx.handle("reload --admin-only=" + (Util.ADMIN_ONLY.equals(mode) ? true : false)); ctx.printLine("Server reloaded."); } catch (Exception ex) { throw new CommandException(ex.getLocalizedMessage(), ex); } } else { ctx.printLine("Warning: server has not been reloaded. Call 'reload' to apply changes."); } } }
public static void execute(CommandContext ctx, ModelNode request, FailureConsumer consumer, boolean noReload) throws CommandException { execute(ctx, request, consumer); if (!noReload) { try { String mode = Util.getRunningMode(ctx); ctx.handle("reload --admin-only=" + (Util.ADMIN_ONLY.equals(mode) ? true : false)); ctx.printLine("Server reloaded."); } catch (Exception ex) { throw new CommandException(ex.getLocalizedMessage(), ex); } } else { ctx.printLine("Warning: server has not been reloaded. Call 'reload' to apply changes."); } } }
private void executeBlock(CommandContext ctx, List<String> block, String blockName) throws CommandLineException { if(block != null && !block.isEmpty()) { final BatchManager batchManager = ctx.getBatchManager(); // this is to discard a batch started by the block in case the block fails // as the cli remains in the batch mode in case run-batch resulted in an error final boolean discardActivatedBatch = !batchManager.isBatchActive(); try { for (String l : block) { ctx.handle(l); } } finally { if(discardActivatedBatch && batchManager.isBatchActive()) { batchManager.discardActiveBatch(); } } } }
private void executeBlock(CommandContext ctx, List<String> block, String blockName) throws CommandLineException { if(block != null && !block.isEmpty()) { final BatchManager batchManager = ctx.getBatchManager(); // this is to discard a batch started by the block in case the block fails // as the cli remains in the batch mode in case run-batch resulted in an error final boolean discardActivatedBatch = !batchManager.isBatchActive(); try { for (String l : block) { ctx.handle(l); } } finally { if(discardActivatedBatch && batchManager.isBatchActive()) { batchManager.discardActiveBatch(); } } } } }
private void executeBlock(CommandContext ctx, List<String> block, String blockName) throws CommandLineException { if(block != null && !block.isEmpty()) { final BatchManager batchManager = ctx.getBatchManager(); // this is to discard a batch started by the block in case the block fails // as the cli remains in the batch mode in case run-batch resulted in an error final boolean discardActivatedBatch = !batchManager.isBatchActive(); try { for (String l : block) { ctx.handle(l); } } finally { if(discardActivatedBatch && batchManager.isBatchActive()) { batchManager.discardActiveBatch(); } } } } }
void run(CommandContext ctx, boolean discard) throws CommandLineException { try { registration.unregister(); if (!discard) { for (ModelNode v : result) { String value = v.asString(); ctx.setVariable(varName, value); for (String cmd : forBlock) { ctx.handle(cmd); } } } } finally { ctx.setVariable(varName, null); if (registration.isActive()) { registration.unregister(); } ctx.remove(Scope.CONTEXT, CTX_KEY); } } }
void run(CommandContext ctx, boolean discard) throws CommandLineException { try { registration.unregister(); if (!discard) { for (ModelNode v : result) { String value = v.asString(); ctx.setVariable(varName, value); for (String cmd : forBlock) { ctx.handle(cmd); } } } } finally { ctx.setVariable(varName, null); if (registration.isActive()) { registration.unregister(); } ctx.remove(Scope.CONTEXT, CTX_KEY); } } }