Search in sources :

Example 1 with DumbTerminal

use of org.jline.terminal.impl.DumbTerminal in project Payara by payara.

the class AsadminTrustManager method isItOKToAddCertToTrustStore.

/**
 * Displays the certificate and prompts the user whether or
 * not it is trusted.
 * @param c
 * @throws IOException
 * @return true if the user trusts the certificate
 */
private boolean isItOKToAddCertToTrustStore(X509Certificate c) {
    if (!interactive) {
        return true;
    }
    String result = null;
    LineReader lineReader = null;
    try {
        lineReader = LineReaderBuilder.builder().terminal(new DumbTerminal(System.in, System.out)).build();
        result = lineReader.readLine(STRING_MANAGER.get("certificateTrustPrompt"));
    } catch (IOException ioe) {
        logger.log(Level.WARNING, "Error instantiating console", ioe);
    } finally {
        if (lineReader != null && lineReader.getTerminal() != null) {
            try {
                lineReader.getTerminal().close();
            } catch (IOException ioe) {
                logger.log(Level.WARNING, "Error closing terminal", ioe);
            }
        }
    }
    return result != null && result.equalsIgnoreCase("y");
}
Also used : LineReader(org.jline.reader.LineReader) IOException(java.io.IOException) DumbTerminal(org.jline.terminal.impl.DumbTerminal)

Example 2 with DumbTerminal

use of org.jline.terminal.impl.DumbTerminal in project flink by apache.

the class CliClientITCase method runSqlStatements.

/**
 * Returns printed results for each ran SQL statements.
 *
 * @param statements the SQL statements to run
 * @return the printed results on SQL Client
 */
private List<Result> runSqlStatements(List<String> statements) throws IOException {
    final String sqlContent = String.join("", statements);
    DefaultContext defaultContext = new DefaultContext(Collections.emptyList(), new Configuration(MINI_CLUSTER_RESOURCE.getClientConfiguration()).set(ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR, ExecutionConfigOptions.LegacyCastBehaviour.DISABLED), Collections.singletonList(new DefaultCLI()));
    final Executor executor = new LocalExecutor(defaultContext);
    InputStream inputStream = new ByteArrayInputStream(sqlContent.getBytes());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
    String sessionId = executor.openSession("test-session");
    try (Terminal terminal = new DumbTerminal(inputStream, outputStream);
        CliClient client = new CliClient(() -> terminal, sessionId, executor, historyPath, HideSqlStatement.INSTANCE)) {
        client.executeInInteractiveMode();
        String output = new String(outputStream.toByteArray());
        return normalizeOutput(output);
    }
}
Also used : LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor) Executor(org.apache.flink.table.client.gateway.Executor) Configuration(org.apache.flink.configuration.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultCLI(org.apache.flink.client.cli.DefaultCLI) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) Terminal(org.jline.terminal.Terminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor)

Example 3 with DumbTerminal

use of org.jline.terminal.impl.DumbTerminal in project flink by apache.

the class CliClientTest method testHistoryFile.

@Test
public void testHistoryFile() throws Exception {
    final MockExecutor mockExecutor = new MockExecutor();
    String sessionId = mockExecutor.openSession("test-session");
    InputStream inputStream = new ByteArrayInputStream("help;\nuse catalog cat;\n".getBytes());
    Path historyFilePath = historyTempFile();
    try (Terminal terminal = new DumbTerminal(inputStream, new TerminalUtils.MockOutputStream());
        CliClient client = new CliClient(() -> terminal, sessionId, mockExecutor, historyFilePath, null)) {
        client.executeInInteractiveMode();
        List<String> content = Files.readAllLines(historyFilePath);
        assertThat(content.size()).isEqualTo(2);
        assertThat(content.get(0)).contains("help");
        assertThat(content.get(1)).contains("use catalog cat");
    }
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DumbTerminal(org.jline.terminal.impl.DumbTerminal) Terminal(org.jline.terminal.Terminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) Test(org.junit.Test)

Aggregations

DumbTerminal (org.jline.terminal.impl.DumbTerminal)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Terminal (org.jline.terminal.Terminal)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 DefaultCLI (org.apache.flink.client.cli.DefaultCLI)1 Configuration (org.apache.flink.configuration.Configuration)1 Executor (org.apache.flink.table.client.gateway.Executor)1 DefaultContext (org.apache.flink.table.client.gateway.context.DefaultContext)1 LocalExecutor (org.apache.flink.table.client.gateway.local.LocalExecutor)1 LineReader (org.jline.reader.LineReader)1 Test (org.junit.Test)1