use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.
the class GeoJsonImportTest method setUpGeogig.
private void setUpGeogig(GeogigCLI cli) throws Exception {
final File userhome = tempFolder.newFolder("mockUserHomeDir");
final File workingDir = tempFolder.newFolder("mockWorkingDir");
tempFolder.newFolder("mockWorkingDir/.geogig");
final Platform platform = mock(Platform.class);
when(platform.pwd()).thenReturn(workingDir);
when(platform.getUserHome()).thenReturn(userhome);
cli.setPlatform(platform);
}
use of org.locationtech.geogig.api.Platform 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();
}
}
}
use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.
the class Main method loadGeoGIG.
static GeoGIG loadGeoGIG(String repo) {
Platform platform = new DefaultPlatform();
platform.setWorkingDir(new File(repo));
Context inj = GlobalContextBuilder.builder.build();
GeoGIG geogig = new GeoGIG(inj, platform.pwd());
if (geogig.command(ResolveGeogigDir.class).call().isPresent()) {
geogig.getRepository();
return geogig;
}
return geogig;
}
use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.
the class MeteredCommandHook method pre.
@Override
public <C extends AbstractGeoGigOp<?>> C pre(C command) throws CannotRunGeogigOperationException {
Boolean enabled;
if (command.context().repository() == null) {
return command;
}
ConfigDatabase configDb = command.context().configDatabase();
try {
enabled = configDb.get(METRICS_ENABLED, Boolean.class).or(Boolean.FALSE);
} catch (ConfigException e) {
if (StatusCode.INVALID_LOCATION.equals(e.statusCode)) {
enabled = Boolean.FALSE;
} else {
throw e;
}
}
if (!enabled.booleanValue()) {
return command;
}
final Platform platform = command.context().platform();
final long startTime = platform.currentTimeMillis();
final long nanoTime = platform.nanoTime();
final String name = command.getClass().getSimpleName();
CallStack stack = CallStack.push(name, startTime, nanoTime);
command.getClientData().put("metrics.callStack", stack);
return command;
}
use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.
the class TagCreateOp method resolveTagger.
private RevPerson resolveTagger() {
final String nameKey = "user.name";
final String emailKey = "user.email";
Optional<String> name = command(ConfigGet.class).setName(nameKey).call();
Optional<String> email = command(ConfigGet.class).setName(emailKey).call();
checkState(name.isPresent(), "%s not found in config. Use geogig config [--global] %s <your name> to configure it.", nameKey, nameKey);
checkState(email.isPresent(), "%s not found in config. Use geogig config [--global] %s <your email> to configure it.", emailKey, emailKey);
String taggerName = name.get();
String taggerEmail = email.get();
Platform platform = platform();
long taggerTimeStamp = platform.currentTimeMillis();
int taggerTimeZoneOffset = platform.timeZoneOffset(taggerTimeStamp);
return new RevPersonImpl(taggerName, taggerEmail, taggerTimeStamp, taggerTimeZoneOffset);
}
Aggregations