Search in sources :

Example 1 with Remote

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

the class RemoteListOp method _call.

/**
     * Executes the remote-list operation.
     * 
     * @return {@code List<Remote>} of all remotes found in the config database, may be empty.
     */
@Override
protected ImmutableList<Remote> _call() {
    ConfigDatabase config = configDatabase();
    List<String> remotes = config.getAllSubsections("remote");
    List<Remote> allRemotes = new ArrayList<Remote>();
    for (String remoteName : remotes) {
        String remoteSection = "remote." + remoteName;
        Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
        Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
        Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
        Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
        Optional<String> remoteUserName = config.get(remoteSection + ".username");
        Optional<String> remotePassword = config.get(remoteSection + ".password");
        if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
            Optional<String> remotePushURL = config.get(remoteSection + ".pushurl");
            allRemotes.add(new Remote(remoteName, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()), remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull()));
        }
    }
    return ImmutableList.copyOf(allRemotes);
}
Also used : ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ArrayList(java.util.ArrayList) Remote(org.locationtech.geogig.api.Remote)

Example 2 with Remote

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

the class RemoteResolve method _call.

/**
     * Executes the remote-add operation.
     * 
     * @return the {@link Remote} that was added.
     */
@Override
protected Optional<Remote> _call() {
    if (name == null || name.isEmpty()) {
        throw new RemoteException(StatusCode.MISSING_NAME);
    }
    Optional<Remote> result = Optional.absent();
    ConfigDatabase config = configDatabase();
    List<String> allRemotes = config.getAllSubsections("remote");
    if (allRemotes.contains(name)) {
        String remoteSection = "remote." + name;
        Optional<String> remoteFetchURL = config.get(remoteSection + ".url");
        Optional<String> remoteFetch = config.get(remoteSection + ".fetch");
        Optional<String> remoteMapped = config.get(remoteSection + ".mapped");
        Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch");
        Optional<String> remoteUserName = config.get(remoteSection + ".username");
        Optional<String> remotePassword = config.get(remoteSection + ".password");
        if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) {
            Optional<String> remotePushURL = config.get(remoteSection + ".pushurl");
            Remote remote = new Remote(name, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()), remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull());
            result = Optional.of(remote);
        }
    }
    return result;
}
Also used : ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) Remote(org.locationtech.geogig.api.Remote)

Example 3 with Remote

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

the class LsRemote method _call.

/**
     * Lists all refs for the given remote.
     * 
     * @return an immutable set of the refs for the given remote
     */
@Override
protected ImmutableSet<Ref> _call() {
    Preconditions.checkState(remote.get().isPresent(), "Remote was not provided");
    final Remote remoteConfig = remote.get().get();
    if (local) {
        return locallyKnownRefs(remoteConfig);
    }
    getProgressListener().setDescription("Obtaining remote " + remoteConfig.getName());
    Optional<IRemoteRepo> remoteRepo = getRemoteRepo(remoteConfig);
    Preconditions.checkState(remoteRepo.isPresent(), "Remote could not be opened.");
    getProgressListener().setDescription("Connecting to remote " + remoteConfig.getName());
    try {
        remoteRepo.get().open();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    getProgressListener().setDescription("Connected to remote " + remoteConfig.getName() + ". Retrieving references");
    ImmutableSet<Ref> remoteRefs;
    try {
        remoteRefs = remoteRepo.get().listRefs(getHeads, getTags);
    } finally {
        try {
            remoteRepo.get().close();
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }
    return remoteRefs;
}
Also used : Ref(org.locationtech.geogig.api.Ref) IRemoteRepo(org.locationtech.geogig.remote.IRemoteRepo) Remote(org.locationtech.geogig.api.Remote) IOException(java.io.IOException)

Example 4 with Remote

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

the class SendPack method callInternal.

private TransferSummary callInternal(IRemoteRepo remoteRepo) {
    final Remote remote = this.remote;
    @Nullable String localRefSpec;
    @Nullable String remoteRefSpec;
    boolean force;
    TransferSummary result = new TransferSummary();
    for (TransferableRef ref : this.refsToPush) {
        localRefSpec = ref.getLocalRef();
        remoteRefSpec = ref.getRemoteRef();
        force = ref.isForceUpdate();
        if (ref.isDelete()) {
            Optional<Ref> deleted = remoteRepo.deleteRef(remoteRefSpec);
            if (deleted.isPresent()) {
                ChangedRef deleteResult = new ChangedRef(deleted.get(), null, REMOVED_REF);
                result.add(remote.getPushURL(), deleteResult);
            }
        } else {
            Optional<Ref> localRef = refParse(localRefSpec);
            checkState(localRef.isPresent(), "RefSpec %s does not exist", localRefSpec);
            Optional<Ref> newRef = push(remoteRepo, remote, localRef.get(), remoteRefSpec);
            if (newRef.isPresent()) {
                ChangeTypes changeType = remoteRefSpec == null ? ADDED_REF : CHANGED_REF;
                ChangedRef deleteResult = new ChangedRef(localRef.get(), newRef.get(), changeType);
                result.add(remote.getPushURL(), deleteResult);
            }
        }
    }
    return result;
}
Also used : ChangedRef(org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef) Ref(org.locationtech.geogig.api.Ref) Remote(org.locationtech.geogig.api.Remote) ChangedRef(org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) ChangeTypes(org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef.ChangeTypes) Nullable(javax.annotation.Nullable)

Example 5 with Remote

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

the class RemoteList method runInternal.

/**
     * Executes the remote list command.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final ImmutableList<Remote> remoteList;
    try {
        remoteList = cli.getGeogig().command(RemoteListOp.class).call();
    } catch (ConfigException e) {
        throw new CommandFailedException("Could not access the config database.", e);
    }
    for (Remote remote : remoteList) {
        if (verbose) {
            cli.getConsole().println(remote.getName() + " " + remote.getFetchURL() + " (fetch)");
            cli.getConsole().println(remote.getName() + " " + remote.getPushURL() + " (push)");
        } else {
            cli.getConsole().println(remote.getName());
        }
    }
}
Also used : Remote(org.locationtech.geogig.api.Remote) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Aggregations

Remote (org.locationtech.geogig.api.Remote)31 Test (org.junit.Test)14 RemoteAddOp (org.locationtech.geogig.api.porcelain.RemoteAddOp)13 IOException (java.io.IOException)8 Ref (org.locationtech.geogig.api.Ref)8 RemoteRemoveOp (org.locationtech.geogig.api.porcelain.RemoteRemoveOp)6 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)5 RemoteException (org.locationtech.geogig.api.porcelain.RemoteException)5 RemoteListOp (org.locationtech.geogig.api.porcelain.RemoteListOp)5 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)5 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)5 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)5 ConfigOp (org.locationtech.geogig.api.porcelain.ConfigOp)4 IRemoteRepo (org.locationtech.geogig.remote.IRemoteRepo)4 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)4 SymRef (org.locationtech.geogig.api.SymRef)3 LsRemote (org.locationtech.geogig.api.plumbing.LsRemote)3 ArrayList (java.util.ArrayList)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 ChangedRef (org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef)2