use of org.jline.terminal.impl.ExternalTerminal in project Payara by payara.
the class MultimodeCommand method executeCommand.
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
LineReader reader = null;
// restore echo flag, saved in validate
programOpts.setEcho(echo);
try {
if (file == null) {
System.out.println(strings.get("multimodeIntro"));
Completer completer = getAllCommandsCompleter();
Terminal asadminTerminal = TerminalBuilder.builder().name(ASADMIN).system(true).encoding(encoding != null ? Charset.forName(encoding) : Charset.defaultCharset()).build();
reader = newLineReaderBuilder().terminal(asadminTerminal).completer(completer).build();
reader.unsetOpt(LineReader.Option.INSERT_TAB);
} else {
printPrompt = false;
if (!file.canRead()) {
throw new CommandException("File: " + file + " can not be read");
}
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
return;
}
@Override
public void write(byte[] b) throws IOException {
return;
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
return;
}
};
Terminal asadminTerminal = new ExternalTerminal(ASADMIN, "", new FileInputStream(file), out, encoding != null ? Charset.forName(encoding) : Charset.defaultCharset());
reader = newLineReaderBuilder().terminal(asadminTerminal).build();
}
return executeCommands(reader);
} catch (IOException e) {
throw new CommandException(e);
} finally {
try {
if (file != null && reader != null && reader.getTerminal() != null) {
reader.getTerminal().close();
}
} catch (Exception e) {
// ignore it
}
}
}
use of org.jline.terminal.impl.ExternalTerminal in project Payara by payara.
the class LocalOSGiShellCommand method executeCommand.
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
LineReader reader = null;
if (cmd == null) {
throw new CommandException("Remote command 'osgi' is not available.");
}
// restore echo flag, saved in validate
programOpts.setEcho(echo);
try {
if (encoding != null) {
// see Configuration.getEncoding()...
System.setProperty("input.encoding", encoding);
}
String[] args = new String[] { REMOTE_COMMAND, "asadmin-osgi-shell" };
args = enhanceForTarget(args);
shellType = cmd.executeAndReturnOutput(args).trim();
if (file == null) {
if (terminal != null) {
// Pause the asadmin terminal
terminal.pause();
}
System.out.println(strings.get("multimodeIntro"));
Terminal osgiShellTerminal = TerminalBuilder.builder().name(REMOTE_COMMAND).system(true).streams(new FileInputStream(FileDescriptor.in), System.out).build();
reader = LineReaderBuilder.builder().appName(REMOTE_COMMAND).terminal(osgiShellTerminal).completer(getCommandCompleter()).build();
reader.unsetOpt(LineReader.Option.INSERT_TAB);
return executeCommands(reader);
}
printPrompt = false;
if (!file.canRead()) {
throw new CommandException("File: " + file + " can not be read");
}
try (Terminal osgiShellTerminal = new ExternalTerminal(REMOTE_COMMAND, "", new FileInputStream(file), new NullOutputStream(), encoding != null ? Charset.forName(encoding) : Charset.defaultCharset())) {
reader = LineReaderBuilder.builder().terminal(osgiShellTerminal).appName(REMOTE_COMMAND).build();
// NB: wrapper on general in/out stream does not need closing by try-with-resource
return executeCommands(reader);
}
} catch (IOException e) {
throw new CommandException(e);
} finally {
if (reader != null && reader.getTerminal() != null) {
try {
reader.getTerminal().close();
} catch (IOException ioe) {
logger.log(Level.WARNING, "Error closing OSFI Shell terminal", ioe);
}
}
}
}
Aggregations