Search in sources :

Example 11 with Platform

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);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Example 12 with 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();
        }
    }
}
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 13 with Platform

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;
}
Also used : Context(org.locationtech.geogig.api.Context) DefaultPlatform(org.locationtech.geogig.api.DefaultPlatform) Platform(org.locationtech.geogig.api.Platform) DefaultPlatform(org.locationtech.geogig.api.DefaultPlatform) File(java.io.File) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 14 with Platform

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;
}
Also used : Platform(org.locationtech.geogig.api.Platform) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException)

Example 15 with Platform

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);
}
Also used : RevPersonImpl(org.locationtech.geogig.api.RevPersonImpl) Platform(org.locationtech.geogig.api.Platform)

Aggregations

Platform (org.locationtech.geogig.api.Platform)41 File (java.io.File)27 TestPlatform (org.locationtech.geogig.api.TestPlatform)10 Before (org.junit.Before)7 Context (org.locationtech.geogig.api.Context)7 GeogigModule (org.locationtech.geogig.di.GeogigModule)6 GeoGIG (org.locationtech.geogig.api.GeoGIG)5 ObjectId (org.locationtech.geogig.api.ObjectId)5 Repository (org.locationtech.geogig.repository.Repository)5 IOException (java.io.IOException)4 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)4 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)4 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)3 DefaultPlatform (org.locationtech.geogig.api.DefaultPlatform)3 MemoryModule (org.locationtech.geogig.api.MemoryModule)3 RevCommit (org.locationtech.geogig.api.RevCommit)3 RevTree (org.locationtech.geogig.api.RevTree)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 UnsupportedTerminal (jline.UnsupportedTerminal)2