Search in sources :

Example 21 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class MeteredCommandHook method post.

@SuppressWarnings("unchecked")
@Override
public <T> T post(AbstractGeoGigOp<T> command, @Nullable Object retVal, @Nullable RuntimeException exception) throws Exception {
    CallStack stack = (CallStack) command.getClientData().get("metrics.callStack");
    if (stack == null || command.context().repository() == null) {
        return (T) retVal;
    }
    final Platform platform = command.context().platform();
    long endTime = platform.nanoTime();
    boolean success = exception == null;
    stack = CallStack.pop(endTime, success);
    long ellapsed = stack.getEllapsedNanos();
    double millis = endTime * toMillisFactor;
    METRICS_LOGGER.info("{}, {}, {}, {}", stack.getName(), stack.getStartTimeMillis(), millis, success);
    if (stack.isRoot()) {
        COMMAND_STACK_LOGGER.info("{}", stack.toString(TimeUnit.MILLISECONDS));
    }
    return (T) retVal;
}
Also used : Platform(org.locationtech.geogig.api.Platform)

Example 22 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class ShpImportTest 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 23 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class Serve method loadGeoGIG.

GeoGIG loadGeoGIG(String repo, GeogigCLI cli) {
    Platform platform = new DefaultPlatform();
    platform.setWorkingDir(new File(repo));
    GeoGIG geogig = new GeoGIG(cli.getGeogigInjector(), platform.pwd());
    if (geogig.command(ResolveGeogigDir.class).call().isPresent()) {
        geogig.getRepository();
    }
    return geogig;
}
Also used : 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 24 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class InitOp method _call.

/**
     * Executes the Init operation.
     * 
     * @return the initialized repository
     * @throws IllegalStateException if a repository cannot be created on the current directory or
     *         re-initialized in the current dir or one if its parents as determined by
     *         {@link ResolveGeogigDir}
     */
@Override
protected Repository _call() {
    final Platform platform = platform();
    final File workingDirectory = platform.pwd();
    checkState(workingDirectory != null, "working directory is null");
    final File targetDir = this.targetDir == null ? workingDirectory : this.targetDir;
    if (!targetDir.exists() && !targetDir.mkdirs()) {
        throw new IllegalArgumentException("Can't create directory " + targetDir.getAbsolutePath());
    }
    Repository repository;
    try {
        platform.setWorkingDir(targetDir);
        repository = callInternal();
    } finally {
        // restore current directory
        platform.setWorkingDir(workingDirectory);
    }
    return repository;
}
Also used : Repository(org.locationtech.geogig.repository.Repository) Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Example 25 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class RebaseOp method applyCommit.

/**
     * Applies the passed command.
     * 
     * @param commitToApply the commit to apply
     * @param useCommitChanges if true, applies the command completely, staging its changes before
     *        committing. If false, it commits the currently staged changes, ignoring the changes in
     *        the commit and using just its author and message
     */
private void applyCommit(RevCommit commitToApply, boolean useCommitChanges) {
    Repository repository = repository();
    Platform platform = platform();
    if (useCommitChanges) {
        ObjectId parentTreeId;
        ObjectId parentCommitId = ObjectId.NULL;
        if (commitToApply.getParentIds().size() > 0) {
            parentCommitId = commitToApply.getParentIds().get(0);
        }
        parentTreeId = ObjectId.NULL;
        if (repository.commitExists(parentCommitId)) {
            parentTreeId = repository.getCommit(parentCommitId).getTreeId();
        }
        // get changes
        Iterator<DiffEntry> diff = command(DiffTree.class).setOldTree(parentTreeId).setNewTree(commitToApply.getTreeId()).setReportTrees(true).call();
        // see if there are conflicts
        MergeScenarioReport report = command(ReportCommitConflictsOp.class).setCommit(commitToApply).call();
        if (report.getConflicts().isEmpty()) {
            // stage changes
            index().stage(getProgressListener(), diff, 0);
            // write new tree
            ObjectId newTreeId = command(WriteTree2.class).call();
            long timestamp = platform.currentTimeMillis();
            // Create new commit
            CommitBuilder builder = new CommitBuilder(commitToApply);
            builder.setParentIds(Arrays.asList(rebaseHead));
            builder.setTreeId(newTreeId);
            builder.setCommitterTimestamp(timestamp);
            builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));
            RevCommit newCommit = builder.build();
            repository.objectDatabase().put(newCommit);
            rebaseHead = newCommit.getId();
            command(UpdateRef.class).setName(currentBranch).setNewValue(rebaseHead).call();
            command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call();
            workingTree().updateWorkHead(newTreeId);
            index().updateStageHead(newTreeId);
        } else {
            Iterator<DiffEntry> unconflicted = report.getUnconflicted().iterator();
            // stage unconflicted changes
            index().stage(getProgressListener(), unconflicted, 0);
            workingTree().updateWorkHead(index().getTree().getId());
            // mark conflicted elements
            command(ConflictsWriteOp.class).setConflicts(report.getConflicts()).call();
            // created exception message
            StringBuilder msg = new StringBuilder();
            msg.append("error: could not apply ");
            msg.append(commitToApply.getId().toString().substring(0, 7));
            msg.append(" " + commitToApply.getMessage() + "\n");
            for (Conflict conflict : report.getConflicts()) {
                msg.append("CONFLICT: conflict in " + conflict.getPath() + "\n");
            }
            File branchFile = new File(getRebaseFolder(), "branch");
            try {
                Files.write(currentBranch, branchFile, Charsets.UTF_8);
            } catch (IOException e) {
                throw new IllegalStateException("Cannot create current branch info file");
            }
            throw new RebaseConflictsException(msg.toString());
        }
    } else {
        // write new tree
        ObjectId newTreeId = command(WriteTree2.class).call();
        long timestamp = platform.currentTimeMillis();
        // Create new commit
        CommitBuilder builder = new CommitBuilder(commitToApply);
        builder.setParentIds(Arrays.asList(rebaseHead));
        builder.setTreeId(newTreeId);
        builder.setCommitterTimestamp(timestamp);
        builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));
        RevCommit newCommit = builder.build();
        repository.objectDatabase().put(newCommit);
        rebaseHead = newCommit.getId();
        command(UpdateRef.class).setName(currentBranch).setNewValue(rebaseHead).call();
        command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call();
        workingTree().updateWorkHead(newTreeId);
        index().updateStageHead(newTreeId);
    }
}
Also used : Platform(org.locationtech.geogig.api.Platform) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) IOException(java.io.IOException) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Repository(org.locationtech.geogig.repository.Repository) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) CanRunDuringConflict(org.locationtech.geogig.di.CanRunDuringConflict) File(java.io.File) WriteTree2(org.locationtech.geogig.api.plumbing.WriteTree2) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) RevCommit(org.locationtech.geogig.api.RevCommit)

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