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);
}
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;
}
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;
}
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;
}
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());
}
}
}
Aggregations