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