use of org.whole.lang.operations.OperationCanceledException in project whole by wholeplatform.
the class TestsInterpreterVisitor method visit.
@Override
public void visit(TestCase entity) {
String name = entity.getName().getValue();
Results results = TestsEntityFactory.instance.createResults();
printWriter().printf("* %s test case running:\n\n", name);
try {
IEntityIterator<BeforeTestCase> beforeIterator = IteratorFactory.<BeforeTestCase>childMatcherIterator().withPattern(BeforeTestCase);
beforeIterator.reset(entity.getAspects());
for (BeforeTestCase beforeTestCase : beforeIterator) {
beforeTestCase.accept(this);
getResult();
}
Tests tests = entity.getTests();
for (int i = 0; i < tests.wSize(); i++) {
Test test = tests.get(i);
if (getBindings().wIsSet("runSingleTest") && getBindings().wGet("runSingleTest") != test)
continue;
test.accept(this);
IntLiteral result = null;
switch(getResult().wGet(outcome).wEnumValue().getOrdinal()) {
case OutcomeEnum.ERROR_ord:
result = results.getErrors();
break;
case OutcomeEnum.FAILURE_ord:
result = results.getFailures();
break;
case OutcomeEnum.SUCCESS_ord:
result = results.getSuccesses();
break;
default:
throw new WholeIllegalArgumentException("unsupported outcome");
}
result.setValue(result.getValue() + 1);
}
IEntityIterator<AfterTestCase> afterIterator = IteratorFactory.<AfterTestCase>childMatcherIterator().withPattern(AfterTestCase);
afterIterator.reset(entity.getAspects());
for (AfterTestCase afterTestCase : afterIterator) {
afterTestCase.accept(this);
getResult();
}
boolean testCaseSuccess = results.getErrors().getValue() + results.getFailures().getValue() == 0;
printWriter().printf("\n* %s test case %s\n", name, testCaseSuccess ? "OK" : "FAILED");
} catch (OperationCanceledException e) {
throw e;
} catch (RuntimeException e) {
reportError(name, e);
results.getErrors().setValue(entity.getTests().wSize());
results.getFailures().setValue(0);
results.getSuccesses().setValue(0);
}
if (EntityUtils.isResolver(entity.getExpectedResults()))
entity.setExpectedResults(EntityUtils.clone(results));
if (!Matcher.match(results, entity.getActualResults()))
entity.setActualResults(results);
setResult(results);
}
use of org.whole.lang.operations.OperationCanceledException in project whole by wholeplatform.
the class LoadContentsVisitor method visit.
@Override
public void visit(FileArtifact file) {
env().wEnterScope();
file.getName().accept(this);
file.getMetadata().accept(this);
String fileName = env().wStringValue("name");
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath filePath = ArtifactsWorkspaceUtils.getParentPath(bindings).append(fileName);
InputStream in;
try {
in = workspaceRoot.getFile(filePath).getContents(true);
} catch (CoreException e) {
throw new OperationCanceledException(e);
}
env().wDefValue("className", StringUtils.stripFileExtension(fileName));
// TODO use IFile
env().wDefValue("persistenceProvider", new StreamPersistenceProvider(in, null, env()));
file.setContent(CommonsEntityAdapterFactory.createStageUpFragment(ArtifactsEntityDescriptorEnum.Content, readContents()));
env().wExitScope();
}
use of org.whole.lang.operations.OperationCanceledException in project whole by wholeplatform.
the class WorkflowsIDEInterpreterVisitor method visit.
@Override
public void visit(Task entity) {
entity.getLabel().accept(this);
String title = PrettyPrinterOperation.toPrettyPrintString(getResult());
entity.getDescription().accept(this);
String description = PrettyPrinterOperation.toPrettyPrintString(getResult());
Assignments assignments = EntityUtils.clone(entity.getAssignments());
Variable factoryVariable = entity.getFactory();
ITaskDialogFactory factory;
if (EntityUtils.isNotResolver(factoryVariable)) {
factoryVariable.accept(this);
factory = (ITaskDialogFactory) getResultValue();
} else if (EntityUtils.isNotResolver(assignments)) {
factory = AssignmentsDialogFactory.instance();
} else
factory = ConfirmationDialogFactory.instance();
if (EntityUtils.isNotResolver(assignments)) {
stagedVisit(assignments, 1);
assignments = (Assignments) getResult();
}
if (!TaskDialogHelper.showTaskDialog(factory, title, description, assignments, getBindings()))
throw new OperationCanceledException(new VisitException("task not completed: " + description));
assignments.accept(this);
}
use of org.whole.lang.operations.OperationCanceledException in project whole by wholeplatform.
the class NormalizeModelRunnable method run.
@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("self"), label);
pm.beginTask("Normalizing...", IOperationProgressMonitor.TOTAL_WORK);
try {
mtc.begin();
HandlersBehavior.normalizeModel(bm);
mtc.commit();
if (mtc.canUndo())
commandStack.execute(mtc);
} catch (OperationCanceledException e) {
mtc.rollbackIfNeeded();
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
} finally {
pm.endTask();
}
}
use of org.whole.lang.operations.OperationCanceledException in project whole by wholeplatform.
the class HandlersBehavior method generateJava.
public static void generateJava(IBindingManager bm) {
ClassLoader cl = ReflectionFactory.getClassLoader(bm);
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
Class<?> generatorClass = Class.forName("org.whole.lang.ui.actions.JavaModelGeneratorAction", true, cl);
Method generateMethod = generatorClass.getMethod("generate", IProgressMonitor.class, IEntity.class, IBindingManager.class);
final IOperationProgressMonitor operationProgressMonitor = (IOperationProgressMonitor) bm.wGetValue("progressMonitor");
generateMethod.invoke(null, operationProgressMonitor.getAdapter(IProgressMonitor.class), bm.wGet("self"), bm);
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
ts.rollback();
bm.wExitScope();
}
}
Aggregations