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);
}
}
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);
}
}
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?
}
}
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?
}
}
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);
}
}
}
Aggregations