Search in sources :

Example 91 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class GeogigCLI method printUsage.

/**
     * This method should be used instead of {@link JCommander#usage()} so the help string is
     * printed to the cli's {@link #getConsole() console} (and hence to wherever its output is sent)
     * instead of directly to {@code System.out}
     */
public void printUsage(JCommander mainCommander) {
    StringBuilder out = new StringBuilder();
    mainCommander.usage(out);
    ConsoleReader console = getConsole();
    try {
        console.println(out.toString());
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException)

Example 92 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class OSMHistoryImport method commit.

/**
     * @param cli
     * @param changeset
     * @throws IOException
     */
private void commit(GeogigCLI cli, Changeset changeset) throws IOException {
    Preconditions.checkArgument(!changeset.isOpen());
    ConsoleReader console = cli.getConsole();
    console.print("Committing changeset " + changeset.getId() + "...");
    console.flush();
    GeoGIG geogig = cli.getGeogig();
    CommitOp command = geogig.command(CommitOp.class);
    command.setAllowEmpty(true);
    String message = "";
    if (changeset.getComment().isPresent()) {
        message = changeset.getComment().get() + "\nchangeset " + changeset.getId();
    } else {
        message = "changeset " + changeset.getId();
    }
    command.setMessage(message);
    final String userName = changeset.getUserName();
    command.setAuthor(userName, null);
    command.setAuthorTimestamp(changeset.getCreated());
    // osm timestamps are in GMT
    command.setAuthorTimeZoneOffset(0);
    if (userName != null) {
        command.setCommitter(userName, null);
    }
    command.setCommitterTimestamp(changeset.getClosed().get());
    // osm timestamps are in GMT
    command.setCommitterTimeZoneOffset(0);
    ProgressListener listener = cli.getProgressListener();
    listener.setProgress(0f);
    listener.started();
    command.setProgressListener(listener);
    try {
        RevCommit commit = command.call();
        Ref head = geogig.command(RefParse.class).setName(Ref.HEAD).call().get();
        Preconditions.checkState(commit.getId().equals(head.getObjectId()));
        updateBranchChangeset(geogig, changeset.getId());
        listener.complete();
        console.println("Commit " + commit.getId().toString());
        console.flush();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) ConsoleReader(jline.console.ConsoleReader) ProgressListener(org.locationtech.geogig.api.ProgressListener) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) GeoGIG(org.locationtech.geogig.api.GeoGIG) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) IOException(java.io.IOException) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 93 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class OSMMap method runInternal.

/**
     * Executes the map command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args == null || args.isEmpty() || args.size() != 1) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    checkState(cli.getGeogig().getRepository().index().isClean() && cli.getGeogig().getRepository().workingTree().isClean(), "Working tree and index are not clean");
    String mappingFilepath = args.get(0);
    Mapping mapping = Mapping.fromFile(mappingFilepath);
    geogig = cli.getGeogig();
    ObjectId oldTreeId = geogig.getRepository().workingTree().getTree().getId();
    message = message == null ? "Applied mapping " + new File(mappingFilepath).getName() : message;
    ObjectId newTreeId = geogig.command(OSMMapOp.class).setMapping(mapping).setMessage(message).call().getId();
    ConsoleReader console = cli.getConsole();
    if (newTreeId.equals(oldTreeId)) {
        console.println("No features matched the specified filter, or they provided no updated data.\n" + "No changes have been made to the working tree");
    } else {
    // print something?
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId) Mapping(org.locationtech.geogig.osm.internal.Mapping) File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 94 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class OSMUnmap method runInternal.

/**
     * Executes the map command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args == null || args.isEmpty() || args.size() != 1) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    String path = args.get(0);
    geogig = cli.getGeogig();
    ObjectId oldTreeId = geogig.getRepository().workingTree().getTree().getId();
    ObjectId newTreeId = geogig.command(OSMUnmapOp.class).setPath(path).call().getId();
    ConsoleReader console = cli.getConsole();
    if (newTreeId.equals(oldTreeId)) {
        console.println("No differences were found after unmapping.\n" + "No changes have been made to the working tree");
    } else {
    // print something?
    }
}
Also used : OSMUnmapOp(org.locationtech.geogig.osm.internal.OSMUnmapOp) ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 95 with ConsoleReader

use of jline.console.ConsoleReader in project GeoGig by boundlessgeo.

the class OSMHistoryImport method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(args.numThreads > 0 && args.numThreads < 7, "numthreads must be between 1 and 6");
    ConsoleReader console = cli.getConsole();
    final String osmAPIUrl = resolveAPIURL();
    final long startIndex;
    final long endIndex = args.endIndex;
    if (args.resume) {
        GeoGIG geogig = cli.getGeogig();
        long lastChangeset = getCurrentBranchChangeset(geogig);
        startIndex = 1 + lastChangeset;
    } else {
        startIndex = args.startIndex;
    }
    console.println(String.format("Obtaining OSM changesets %,d to %,d from %s", startIndex, args.endIndex, osmAPIUrl));
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("osm-history-fetch-thread-%d").build();
    final ExecutorService executor = Executors.newFixedThreadPool(args.numThreads, threadFactory);
    final File targetDir = resolveTargetDir();
    console.println("Downloading to " + targetDir.getAbsolutePath());
    console.flush();
    HistoryDownloader downloader;
    downloader = new HistoryDownloader(osmAPIUrl, targetDir, startIndex, endIndex, executor);
    Envelope env = parseBbox();
    Predicate<Changeset> filter = parseFilter(env);
    downloader.setChangesetFilter(filter);
    try {
        importOsmHistory(cli, console, downloader, env);
    } finally {
        executor.shutdownNow();
        try {
            executor.awaitTermination(30, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new CommandFailedException(e);
        }
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) HistoryDownloader(org.locationtech.geogig.osm.internal.history.HistoryDownloader) ConsoleReader(jline.console.ConsoleReader) Envelope(com.vividsolutions.jts.geom.Envelope) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) File(java.io.File) Changeset(org.locationtech.geogig.osm.internal.history.Changeset) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

ConsoleReader (jline.console.ConsoleReader)97 UnsupportedTerminal (jline.UnsupportedTerminal)44 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)42 GeoGIG (org.locationtech.geogig.api.GeoGIG)22 IOException (java.io.IOException)19 Before (org.junit.Before)19 Test (org.junit.Test)17 File (java.io.File)12 MockitoException (org.mockito.exceptions.base.MockitoException)12 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 TestPlatform (org.locationtech.geogig.api.TestPlatform)8 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)8 Ref (org.locationtech.geogig.api.Ref)7 CLITestContextBuilder (org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder)7 Ansi (org.fusesource.jansi.Ansi)6 NodeRef (org.locationtech.geogig.api.NodeRef)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 FileInputStream (java.io.FileInputStream)4 RevObject (org.locationtech.geogig.api.RevObject)4