Search in sources :

Example 16 with UnsupportedTerminal

use of jline.UnsupportedTerminal in project GeoGig by boundlessgeo.

the class GeoJsonExportTest method setUpInternal.

@Override
public void setUpInternal() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    cli = new GeogigCLI(consoleReader);
    cli.setGeogig(geogig);
    // Add points
    insertAndAdd(points1);
    insertAndAdd(points2);
    insertAndAdd(points3);
    geogig.command(CommitOp.class).call();
    // Add lines
    insertAndAdd(lines1);
    insertAndAdd(lines2);
    insertAndAdd(lines3);
    geogig.command(CommitOp.class).call();
}
Also used : GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp)

Example 17 with UnsupportedTerminal

use of jline.UnsupportedTerminal in project GeoGig by boundlessgeo.

the class GeoJsonImportTest method setUp.

@Before
public void setUp() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    cli = new GeogigCLI(consoleReader);
    setUpGeogig(cli);
}
Also used : GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) Before(org.junit.Before)

Example 18 with UnsupportedTerminal

use of jline.UnsupportedTerminal in project GeoGig by boundlessgeo.

the class OracleDescribeTest method testDescribeException.

@Test
public void testDescribeException() throws Exception {
    ConsoleReader consoleReader = new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    GeogigCLI mockCli = spy(new GeogigCLI(consoleReader));
    setUpGeogig(mockCli);
    when(mockCli.getConsole()).thenThrow(new MockitoException("Exception"));
    OracleDescribe describeCommand = new OracleDescribe();
    describeCommand.table = "table1";
    describeCommand.dataStoreFactory = TestHelper.createTestFactory();
    exception.expect(MockitoException.class);
    describeCommand.run(mockCli);
}
Also used : GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 19 with UnsupportedTerminal

use of jline.UnsupportedTerminal in project GeoGig by boundlessgeo.

the class ConsoleResourceResource method processRequest.

private JsonObject processRequest(JsonObject json, final GeoGIG geogig) {
    JsonObject response;
    final String command = json.get("method").getAsString();
    final String queryId = json.get("id").getAsString();
    // not used, we're getting the whole command and args in the "method" object
    // JsonArray paramsArray = json.get("params").getAsJsonArray();
    InputStream in = new ByteArrayInputStream(new byte[0]);
    // dumps output to a temp file if > threshold
    FileBackedOutputStream out = new FileBackedOutputStream(4096);
    try {
        // pass it a BufferedOutputStream 'cause it doesn't buffer the internal FileOutputStream
        ConsoleReader console = new ConsoleReader(in, new BufferedOutputStream(out), new UnsupportedTerminal());
        Platform platform = geogig.getPlatform();
        GeogigCLI geogigCLI = new GeogigCLI(geogig, console);
        geogigCLI.setPlatform(platform);
        geogigCLI.disableProgressListener();
        String[] args = ArgumentTokenizer.tokenize(command);
        final int exitCode = geogigCLI.execute(args);
        response = new JsonObject();
        response.addProperty("id", queryId);
        final int charCountLimit = getOutputLimit(geogig.getContext());
        final StringBuilder output = getLimitedOutput(out, charCountLimit);
        if (exitCode == 0) {
            response.addProperty("result", output.toString());
            response.addProperty("error", (String) null);
        } else {
            Exception exception = geogigCLI.exception;
            JsonObject error = buildError(exitCode, output, exception);
            response.add("error", error);
        }
        return response;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } finally {
        // delete temp file
        try {
            out.reset();
        } catch (IOException ignore) {
            ignore.printStackTrace();
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) Platform(org.locationtech.geogig.api.Platform) UnsupportedTerminal(jline.UnsupportedTerminal) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) IOException(java.io.IOException) GeogigCLI(org.locationtech.geogig.cli.GeogigCLI) ByteArrayInputStream(java.io.ByteArrayInputStream) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 20 with UnsupportedTerminal

use of jline.UnsupportedTerminal in project GeoGig by boundlessgeo.

the class GeogigConsole method run.

private void run(final InputStream in, final OutputStream out) throws IOException {
    final Terminal terminal;
    if (interactive) {
        terminal = null;
    /* let jline select an appropriate one */
    } else {
        // no colors in output
        terminal = new UnsupportedTerminal();
    }
    ConsoleReader consoleReader = new ConsoleReader(in, out, terminal);
    consoleReader.setAutoprintThreshold(20);
    consoleReader.setPaginationEnabled(interactive);
    consoleReader.setHistoryEnabled(interactive);
    // needed for CTRL+C not to let the console broken
    consoleReader.getTerminal().setEchoEnabled(interactive);
    final GeogigCLI cli = new GeogigCLI(consoleReader);
    if (interactive) {
        addCommandCompleter(consoleReader, cli);
    } else {
        // no progress percent in output
        cli.disableProgressListener();
    }
    GeogigCLI.addShutdownHook(cli);
    setPrompt(cli);
    cli.close();
    try {
        runInternal(cli);
    } finally {
        try {
            cli.close();
        } finally {
            try {
                if (terminal != null) {
                    terminal.restore();
                }
                consoleReader.shutdown();
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) Terminal(jline.Terminal) UnsupportedTerminal(jline.UnsupportedTerminal) IOException(java.io.IOException)

Aggregations

UnsupportedTerminal (jline.UnsupportedTerminal)43 ConsoleReader (jline.console.ConsoleReader)43 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)42 Before (org.junit.Before)19 Test (org.junit.Test)15 MockitoException (org.mockito.exceptions.base.MockitoException)12 TestPlatform (org.locationtech.geogig.api.TestPlatform)8 File (java.io.File)7 CLITestContextBuilder (org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder)7 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)6 IOException (java.io.IOException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Platform (org.locationtech.geogig.api.Platform)2 FileBackedOutputStream (com.google.common.io.FileBackedOutputStream)1 JsonObject (com.google.gson.JsonObject)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1