Search in sources :

Example 1 with OperationCanceledException

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);
}
Also used : AfterTestCase(org.whole.lang.tests.model.AfterTestCase) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) Tests(org.whole.lang.tests.model.Tests) Constraint(org.whole.lang.tests.model.Constraint) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) Results(org.whole.lang.tests.model.Results) Test(org.whole.lang.tests.model.Test) BeforeTest(org.whole.lang.tests.model.BeforeTest) AfterTest(org.whole.lang.tests.model.AfterTest) IntLiteral(org.whole.lang.tests.model.IntLiteral) BeforeTestCase(org.whole.lang.tests.model.BeforeTestCase)

Example 2 with OperationCanceledException

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();
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider)

Example 3 with OperationCanceledException

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);
}
Also used : ITaskDialogFactory(org.whole.lang.workflows.ui.dialogs.ITaskDialogFactory) Variable(org.whole.lang.workflows.model.Variable) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) VisitException(org.whole.lang.visitors.VisitException) Assignments(org.whole.lang.workflows.model.Assignments)

Example 4 with OperationCanceledException

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();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 5 with OperationCanceledException

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();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITransactionScope(org.whole.lang.bindings.ITransactionScope) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) Method(java.lang.reflect.Method) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) OperationCanceledException(org.whole.lang.operations.OperationCanceledException)

Aggregations

OperationCanceledException (org.whole.lang.operations.OperationCanceledException)16 IEntity (org.whole.lang.model.IEntity)8 CommandStack (org.eclipse.gef.commands.CommandStack)6 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)6 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)5 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)3 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)2 AfterTest (org.whole.lang.tests.model.AfterTest)2 BeforeTest (org.whole.lang.tests.model.BeforeTest)2 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 TreeSet (java.util.TreeSet)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1