Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.Context


                bind(ObjectDatabaseCacheFactory.class).toInstance(odbCacheFac);
                bind(StagingDatabaseCacheFactory.class).toInstance(indexCacheFac);
            }
        };

        Context injector = Guice.createInjector(Modules.override(new CachingModule()).with(module))
                .getInstance(org.locationtech.geogig.api.Context.class);

        odb = injector.objectDatabase();
        index = injector.stagingDatabase();
        odb.open();
        index.open();

        odb.put(o1);
        odb.put(o2);
View Full Code Here


        Ref master = new Ref(Ref.MASTER, ObjectId.forString("hash me"));

        when(mockRefParse.call()).thenReturn(Optional.of(master));

        Context injector = mock(Context.class);
        when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse);
        when(injector.platform()).thenReturn(platform);
        when(injector.repository()).thenReturn(mockRepo);
        init.setContext(injector);

        assertTrue(ResolveGeogigDir.lookup(platform.pwd()).isPresent());
        assertNotNull(init.call());
        verify(platform, atLeastOnce()).pwd();
View Full Code Here

    public GeoGIG newGeoGIG() {
        return newGeoGIG(Hints.readWrite());
    }

    public GeoGIG newGeoGIG(Hints hints) {
        Context inj = newGeogigInjector(hints);
        GeoGIG geogig = new GeoGIG(inj, platform.pwd());
        try {
            geogig.getRepository();
        } catch (Exception e) {
            throw Throwables.propagate(e);
View Full Code Here

        final boolean repoExisted;
        final Repository repository;
        {
            GeoGIG geogig = cli.getGeogig();
            if (geogig == null) {
                Context geogigInjector = cli.getGeogigInjector();
                geogig = new GeoGIG(geogigInjector);
            }
            repoExisted = determineIfRepoExists(targetDirectory, geogig);
            final Map<String, String> suppliedConfiguration = splitConfig(config);
View Full Code Here

    public void run(CommandContext context) {
        if (this.getTransactionId() == null) {
            throw new CommandSpecException(
                    "No transaction was specified, add requires a transaction to preserve the stability of the repository.");
        }
        final Context geogig = this.getCommandLocator(context);

        AddOp command = geogig.command(AddOp.class);

        if (path != null) {
            command.addPattern(path);
        }
View Full Code Here

        }
        if (this.path == null) {
            throw new CommandSpecException("No path was specified for removal.");
        }

        final Context geogig = this.getCommandLocator(context);
        RemoveOp command = geogig.command(RemoveOp.class);

        NodeRef.checkValidPath(path);

        Optional<NodeRef> node = geogig.command(FindTreeChild.class)
                .setParent(geogig.workingTree().getTree()).setIndex(true).setChildPath(path)
                .call();
        if (node.isPresent()) {
            NodeRef nodeRef = node.get();
            if (nodeRef.getType() == TYPE.TREE) {
                if (!recursive) {
View Full Code Here

     *
     * @param context - the context to use for this command
     */
    @Override
    public void run(CommandContext context) {
        final Context geogig = this.getCommandLocator(context);

        Optional<ObjectId> commit = Optional.absent();
        if (branchOrCommit != null) {
            commit = geogig.command(RevParse.class).setRefSpec(branchOrCommit).call();
            if (!commit.isPresent()) {
                throw new CommandSpecException("Could not resolve branch or commit");
            }
        }

        try {
            final BlameReport report = geogig.command(BlameOp.class).setPath(path)
                    .setCommit(commit.orNull()).call();

            context.setResponseContent(new CommandResponse() {
                @Override
                public void write(ResponseWriter out) throws Exception {
View Full Code Here

        if (this.getTransactionId() == null) {
            throw new CommandSpecException(
                    "No transaction was specified, checkout requires a transaction to preserve the stability of the repository.");
        }

        final Context geogig = this.getCommandLocator(context);
        CheckoutOp command = geogig.command(CheckoutOp.class);
        if (branchOrCommit != null) {
            Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();

            if (!head.isPresent()) {
                throw new CommandSpecException("Repository has no HEAD, can't merge.");
            }
View Full Code Here

     *
     * @param context - the context to use for this command
     */
    @Override
    public void run(CommandContext context) {
        final Context geogig = this.getCommandLocator(context);

        PullOp command = geogig.command(PullOp.class)
                .setAuthor(authorName.orNull(), authorEmail.orNull()).setRemote(remoteName)
                .setAll(fetchAll).addRefSpec(refSpec);
        try {
            final PullResult result = command.call();
            final Iterator<DiffEntry> iter;
            if (result.getOldRef() != null && result.getNewRef() != null
                    && result.getOldRef().equals(result.getNewRef())) {
                iter = null;
            } else {
                if (result.getOldRef() == null) {
                    iter = geogig.command(DiffOp.class)
                            .setNewVersion(result.getNewRef().getObjectId())
                            .setOldVersion(ObjectId.NULL).call();
                } else {
                    iter = geogig.command(DiffOp.class)
                            .setNewVersion(result.getNewRef().getObjectId())
                            .setOldVersion(result.getOldRef().getObjectId()).call();
                }
            }

            context.setResponseContent(new CommandResponse() {
                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writePullResponse(result, iter, geogig);
                    out.finish();
                }
            });
        } catch (SynchronizationException e) {
            switch (e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                context.setResponseContent(CommandResponse
                        .error("Unable to pull, the remote history is shallow."));
            }
        } catch (MergeConflictsException e) {
            String[] refs = refSpec.split(":");
            String remoteRef = Ref.REMOTES_PREFIX + remoteName + "/" + refs[0];
            Optional<Ref> sourceRef = geogig.command(RefParse.class).setName(remoteRef).call();
            String destinationref = "";
            if (refs.length == 2) {
                destinationref = refs[1];
            } else {
                final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD)
                        .call();
                if (!currHead.isPresent()) {
                    context.setResponseContent(CommandResponse
                            .error("Repository has no HEAD, can't pull."));
                } else if (!(currHead.get() instanceof SymRef)) {
                    context.setResponseContent(CommandResponse
                            .error("Can't pull from detached HEAD"));
                }
                final SymRef headRef = (SymRef) currHead.get();
                destinationref = headRef.getTarget();
            }

            Optional<Ref> destRef = geogig.command(RefParse.class).setName(destinationref).call();
            final RevCommit theirs = context.getGeoGIG().getRepository()
                    .getCommit(sourceRef.get().getObjectId());
            final RevCommit ours = context.getGeoGIG().getRepository()
                    .getCommit(destRef.get().getObjectId());
            final Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class)
                    .setLeft(ours).setRight(theirs).call();
            context.setResponseContent(new CommandResponse() {
                final MergeScenarioReport report = geogig.command(ReportMergeScenarioOp.class)
                        .setMergeIntoCommit(ours).setToMergeCommit(theirs).call();

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
View Full Code Here

     *
     * @param context - the context to use for this command
     */
    @Override
    public void run(CommandContext context) {
        final Context geogig = this.getCommandLocator(context);
        final List<FeatureTypeStats> stats = Lists.newArrayList();
        LogOp logOp = geogig.command(LogOp.class).setFirstParentOnly(true);
        final Iterator<RevCommit> log;
        if (since != null && !since.trim().isEmpty()) {
            Date untilTime = new Date();
            Date sinceTime = new Date(geogig.command(ParseTimestamp.class).setString(since).call());
            logOp.setTimeRange(new Range<Date>(Date.class, sinceTime, untilTime));
        }
        if (this.until != null) {
            Optional<ObjectId> until;
            until = geogig.command(RevParse.class).setRefSpec(this.until).call();
            Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", this.until);
            logOp.setUntil(until.get());
        }

        LsTreeOp lsTreeOp = geogig.command(LsTreeOp.class)
                .setStrategy(LsTreeOp.Strategy.TREES_ONLY);
        if (path != null && !path.trim().isEmpty()) {
            lsTreeOp.setReference(path);
            logOp.addPath(path);
        }
        final Iterator<NodeRef> treeIter = lsTreeOp.call();

        while (treeIter.hasNext()) {
            NodeRef node = treeIter.next();
            stats.add(new FeatureTypeStats(node.path(), context.getGeoGIG().getRepository()
                    .getTree(node.objectId()).size()));
        }
        log = logOp.call();

        RevCommit firstCommit = null;
        RevCommit lastCommit = null;
        int totalCommits = 0;
        final List<RevPerson> authors = Lists.newArrayList();

        if (log.hasNext()) {
            lastCommit = log.next();
            authors.add(lastCommit.getAuthor());
            totalCommits++;
        }
        while (log.hasNext()) {
            firstCommit = log.next();
            RevPerson newAuthor = firstCommit.getAuthor();
            // If the author isn't defined, use the committer for the purposes of statistics.
            if (!newAuthor.getName().isPresent() && !newAuthor.getEmail().isPresent()) {
                newAuthor = firstCommit.getCommitter();
            }
            if (newAuthor.getName().isPresent() || newAuthor.getEmail().isPresent()) {
                boolean authorFound = false;
                for (RevPerson author : authors) {
                    if (newAuthor.getName().equals(author.getName())
                            && newAuthor.getEmail().equals(author.getEmail())) {
                        authorFound = true;
                        break;
                    }
                }
                if (!authorFound) {
                    authors.add(newAuthor);
                }
            }
            totalCommits++;
        }
        int addedFeatures = 0;
        int modifiedFeatures = 0;
        int removedFeatures = 0;
        if (since != null && !since.trim().isEmpty() && firstCommit != null && lastCommit != null) {
            final Iterator<DiffEntry> diff = geogig.command(DiffOp.class)
                    .setOldVersion(firstCommit.getId()).setNewVersion(lastCommit.getId())
                    .setFilter(path).call();
            while (diff.hasNext()) {
                DiffEntry entry = diff.next();
                if (entry.changeType() == DiffEntry.ChangeType.ADDED) {
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.