/** * Runs the {@link AbstractGeoGigOp command} given by its {@code className} with the provided * {@code parameters} */ private Object runCommand(String className, Map<String, Object> parameters) throws ClassNotFoundException { @SuppressWarnings("unchecked") Class<AbstractGeoGigOp<?>> clazz = (Class<AbstractGeoGigOp<?>>) Class.forName(className); AbstractGeoGigOp<?> operation = repository.command(clazz); @SuppressWarnings("unused") Map<String, Object> oldParams = Scripting.getParamMap(operation); Scripting.setParamMap(parameters, operation); return operation.call(); }
final Context context = command.context(); List<Index> updates; try { ProgressListener listener = command.getProgressListener(); listener.started(); .call(); if (!listener.isCanceled() && !updates.isEmpty()) { listener.setDescription(String.format("updated indexes: %s\n", updates));
testOp.setContext(context); assertEquals(context, testOp.context()); testOp.command(AbstractGeoGigOp.class); verify(context).command(AbstractGeoGigOp.class); testOp.workingTree(); verify(context).workingTree(); testOp.stagingArea(); verify(context).stagingArea(); testOp.refDatabase(); verify(context).refDatabase(); testOp.platform(); verify(context).platform(); testOp.objectDatabase(); verify(context).objectDatabase(); testOp.conflictsDatabase(); verify(context).conflictsDatabase(); testOp.configDatabase(); verify(context).configDatabase(); testOp.graphDatabase(); verify(context).graphDatabase();
@Override public T call() throws Exception { if (command.getProgressListener().isCanceled()) { this.status = Status.CANCELLED; return null; } this.status = Status.RUNNING; try { command.setProgressListener(progress); T result = command.call(); if (command.getProgressListener().isCanceled()) { this.status = Status.CANCELLED; } else { this.status = Status.FINISHED; } return result; } catch (Throwable e) { this.status = Status.FAILED; throw e; } } }
@Override public <C extends AbstractGeoGigOp<?>> C pre(C command) throws CannotRunGeogigOperationException { /* * Store the ref name and its old value in the command's user properties to be used in the * post-hook if the operation was successful */ Map<String, Object> params = Scripting.getParamMap(command); String refName = (String) params.get("name"); command.getClientData().put("name", refName); // ignore if still inside a transaction or updating a known symref boolean ignore = command.context() instanceof GeogigTransaction; ignore |= (Ref.WORK_HEAD.equals(refName) || Ref.STAGE_HEAD.equals(refName)); if (ignore) { command.getClientData().put("ignore", Boolean.TRUE); // ignore updates to work/stage heads, we only care of updates to branches return command; } Optional<Ref> currentValue = command.command(RefParse.class).setName(refName).call(); command.getClientData().put("oldValue", currentValue); LOGGER.debug("GWC geogig truncate pre-hook engaged for ref '{}'", refName); return command; }
testOp.addListener(listener1); testOp.addListener(listener2); testOp.call(); assertTrue(preCalled1.get()); assertTrue(postCalled1.get()); testOp2.addListener(listener3); try { testOp2.call(); fail(); } catch (RuntimeException e) {
public Context getContext() { return command.command.context(); }
private void verifyFetchedIndexes(AbstractGeoGigOp<?> command, TransferSummary ts) { Set<String> remotes = ts.getRefDiffs().keySet(); for (String remoteURI : remotes) { FetchOp op = (FetchOp) command; Remote remoteObj = op.getRemotes().stream() .filter(r -> remoteURI.equals(r.getFetchURL())).findFirst().get(); String fetchURL = remoteObj.getFetchURL(); Repository remote = (Repository) command.getClientData().get(fetchURL); Collection<RefDiff> collection = ts.getRefDiffs().get(remoteURI); for (RefDiff rd : collection) { if (rd.isDelete()) { continue; } Ref newRef = rd.getNewRef(); Repository local = command.context().repository(); String localRef = newRef.getName(); String remoteBranch = remoteObj.mapToRemote(localRef).orElse(null); verifyClonedIndexes(local, remote, Optional.of(localRef), Optional.of(remoteBranch)); } } }
@Test public void testProgressListener() { AbstractGeoGigOp<String> testOp = new AbstractGeoGigOp<String>() { @Override protected String _call() { return "myValue"; } }; DefaultProgressListener listener = new DefaultProgressListener(); listener.setMaxProgress(1000); listener.setDescription("command progress"); testOp.setProgressListener(null); assertTrue(testOp.getProgressListener() instanceof ProgressListener); testOp.setProgressListener(listener); assertEquals(listener, testOp.getProgressListener()); ProgressListener subProgress = testOp.subProgress(100); subProgress.setMaxProgress(100); subProgress.setProgress(50); assertEquals(50, (int) listener.getProgress()); subProgress.complete(); assertEquals(100, (int) listener.getProgress()); }
/** * Constructs a new progress listener based on a specified sub progress amount. * * @param amount amount of progress * @return the newly constructed progress listener */ protected ProgressListener subProgress(float amount) { return new SubProgressListener(getProgressListener(), amount); }
@Override public AbstractGeoGigOp<?> decorate(Object subject) { Preconditions.checkNotNull(subject); AbstractGeoGigOp<?> operation = (AbstractGeoGigOp<?>) subject; Boolean conflicts = operation.command(ConflictsCheckOp.class).call(); if (conflicts.booleanValue()) { throw new ConflictsException( "Cannot run operation while merge or rebase conflicts exist."); } return (AbstractGeoGigOp<?>) subject; }
public @Override <I> I decorate(I subject) { AbstractGeoGigOp<?> op = (AbstractGeoGigOp<?>) subject; CommandHookChain callChain = CommandHookChain.builder().command(op).build(); if (!callChain.isEmpty()) { op.addListener(new HooksListener(callChain)); } return subject; }
@Override protected ConfigDatabase configDatabase() { return configDbOverride == null ? super.configDatabase() : configDbOverride; }
public Optional<UUID> getTransactionId() { Context context = command.command.context(); if (context instanceof GeogigTransaction) { GeogigTransaction tx = (GeogigTransaction) context; UUID txId = tx.getTransactionId(); return Optional.of(txId); } return Optional.absent(); }
/** * Constructs a new progress listener based on a specified sub progress amount. * * @param amount amount of progress * @return the newly constructed progress listener */ protected ProgressListener subProgress(float amount) { return new SubProgressListener(getProgressListener(), amount); }
@SuppressWarnings("unchecked") @Override public AbstractGeoGigOp<?> decorate(Object subject) { Preconditions.checkNotNull(subject); AbstractGeoGigOp<?> operation = (AbstractGeoGigOp<?>) subject; Boolean conflicts = operation.command(ConflictsCheckOp.class).call(); if (conflicts.booleanValue()) { throw new ConflictsException( "Cannot run operation while merge or rebase conflicts exist."); } return (AbstractGeoGigOp<?>) subject; }
@Override public <I> I decorate(I subject) { AbstractGeoGigOp<?> op = (AbstractGeoGigOp<?>) subject; CommandHookChain callChain = CommandHookChain.builder().command(op).build(); if (!callChain.isEmpty()) { op.addListener(new HooksListener(callChain)); } return subject; }
@Override protected ConfigDatabase configDatabase() { return configDbOverride == null ? super.configDatabase() : configDbOverride; }
public void commitSyncTransaction(ProgressListener listener) throws ConflictsException { context.command(TransactionEnd.class).setAuthor(authorName.orNull(), authorEmail.orNull()) .setTransaction(this).setCancel(false).setProgressListener(listener).call(); }
final Context context = command.context(); List<Index> updates; try { ProgressListener listener = command.getProgressListener(); listener.started(); log.debug("Calling UpdateIndexesOp for {}", ref); .call(); if (!listener.isCanceled() && !updates.isEmpty()) { listener.setDescription("updated indexes: %s", updates);