use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.
the class Init method runInternal.
/**
* Executes the init command.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
// argument location if provided, or current directory otherwise
final File targetDirectory;
{
File currDir = cli.getPlatform().pwd();
if (location != null && location.size() == 1) {
String target = location.get(0);
File f = new File(target);
if (!f.isAbsolute()) {
f = new File(currDir, target).getCanonicalFile();
}
targetDirectory = f;
} else {
targetDirectory = currDir;
}
}
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);
try {
repository = geogig.command(InitOp.class).setConfig(suppliedConfiguration).setTarget(targetDirectory).call();
} catch (IllegalArgumentException e) {
throw new CommandFailedException(e.getMessage(), e);
} finally {
geogig.close();
}
}
File repoDirectory;
try {
repoDirectory = new File(repository.getLocation().toURI());
} catch (URISyntaxException e) {
throw new CommandFailedException("Environment home can't be resolved to a directory", e);
}
String message;
if (repoExisted) {
message = "Reinitialized existing Geogig repository in " + repoDirectory.getAbsolutePath();
} else {
message = "Initialized empty Geogig repository in " + repoDirectory.getAbsolutePath();
}
cli.getConsole().println(message);
}
use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.
the class CachingModuleTest method setUp.
@Before
public void setUp() throws Exception {
odbCache = mock(Cache.class);
indexCache = mock(Cache.class);
final ObjectDatabaseCacheFactory odbCacheFac = mock(ObjectDatabaseCacheFactory.class);
when(odbCacheFac.get()).thenReturn(odbCache);
final StagingDatabaseCacheFactory indexCacheFac = mock(StagingDatabaseCacheFactory.class);
when(indexCacheFac.get()).thenReturn(indexCache);
File workingDirectory = tmpFolder.getRoot();
final Platform platform = new TestPlatform(workingDirectory);
Module module = new AbstractModule() {
@Override
protected void configure() {
bind(Context.class).to(GuiceInjector.class).in(Scopes.SINGLETON);
Multibinder.newSetBinder(binder(), Decorator.class);
bind(DecoratorProvider.class).in(Scopes.SINGLETON);
DataStreamSerializationFactoryV1 sfac = DataStreamSerializationFactoryV1.INSTANCE;
bind(ObjectSerializingFactory.class).toInstance(sfac);
bind(ObjectDatabase.class).to(HeapObjectDatabse.class).in(Scopes.SINGLETON);
bind(StagingDatabase.class).to(HeapStagingDatabase.class).in(Scopes.SINGLETON);
ConfigDatabase config = new IniFileConfigDatabase(platform);
bind(ConfigDatabase.class).toInstance(config);
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);
odb.put(o3);
index.put(s1);
index.put(s2);
index.put(s3);
}
use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.
the class DepthSearchTest method addTree.
private RevTreeBuilder addTree(RevTreeBuilder root, final String treePath, String... singleNodeNames) {
Context mockInjector = mock(Context.class);
when(mockInjector.objectDatabase()).thenReturn(odb);
CreateTree op = new CreateTree().setIndex(false);
op.setContext(mockInjector);
RevTreeBuilder subTreeBuilder = op.call();
if (singleNodeNames != null) {
for (String singleNodeName : singleNodeNames) {
String nodePath = NodeRef.appendChild(treePath, singleNodeName);
ObjectId fakeFeatureOId = ObjectId.forString(nodePath);
// forString(treePath);
ObjectId fakeTypeOId = ObjectId.NULL;
subTreeBuilder.put(Node.create(singleNodeName, fakeFeatureOId, fakeTypeOId, TYPE.FEATURE, null));
}
}
RevTree subtree = subTreeBuilder.build();
WriteBack writeBack = fakeGeogig.command(WriteBack.class).setAncestor(root).setChildPath(treePath).setTree(subtree).setMetadataId(fakeTreeMetadataId);
ObjectId newRootId = writeBack.call();
return fakeGeogig.command(RevObjectParse.class).setObjectId(newRootId).call(RevTree.class).get().builder(odb);
}
use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.
the class LsTree method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
String ref = null;
if (refList != null && !refList.isEmpty()) {
ref = refList.get(0);
}
LsTreeOp.Strategy lsStrategy = LsTreeOp.Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = LsTreeOp.Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = LsTreeOp.Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = LsTreeOp.Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = LsTreeOp.Strategy.TREES_ONLY;
}
}
final Context geogig = this.getCommandLocator(context);
final Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start(true);
out.writeLsTreeResponse(iter, verbose);
out.finish();
}
});
}
use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.
the class PullWebOp method run.
/**
* Runs the command and builds the appropriate response.
*
* @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();
Optional<RevCommit> mergeCommit = Optional.absent();
out.writeMergeResponse(mergeCommit, report, geogig, ours.getId(), theirs.getId(), ancestor.get());
out.finish();
}
});
}
}
Aggregations