Search in sources :

Example 1 with FunctionCallEnv

use of com.cloudbees.groovy.cps.impl.FunctionCallEnv in project groovy-cps by cloudbees.

the class VariableDeclarationTest method createVariable.

@SuppressWarnings("unchecked")
private <T> T createVariable(Class<T> clazz) {
    try {
        FunctionCallEnv env = new FunctionCallEnv(null, Continuation.HALT, null, null);
        Next p = new Next(b.block(b.declareVariable(clazz, "x"), b.return_($x)), env, Continuation.HALT);
        return (T) p.run().yield.wrapReplay();
    } catch (InvocationTargetException x) {
        throw new AssertionError(x);
    }
}
Also used : FunctionCallEnv(com.cloudbees.groovy.cps.impl.FunctionCallEnv) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with FunctionCallEnv

use of com.cloudbees.groovy.cps.impl.FunctionCallEnv in project workflow-cps-plugin by jenkinsci.

the class CpsBodyExecution method createContinuable.

/**
 * Creates {@link Continuable} that executes the given invocation and pass its result to {@link FutureCallback}.
 *
 * The {@link Continuable} itself will just yield null. {@link CpsThreadGroup} considers the whole
 * execution a failure if any of the threads fail, so this behaviour ensures that a problem in the closure
 * body won't terminate the workflow.
 */
private Continuable createContinuable(CpsThread currentThread, CpsCallableInvocation inv) {
    // we need FunctionCallEnv that acts as the back drop of try/catch block.
    // TODO: we need to capture the surrounding calling context to capture variables, and switch to ClosureCallEnv
    FunctionCallEnv caller = new FunctionCallEnv(null, onSuccess, null, null);
    if (currentThread.getExecution().isSandbox())
        caller.setInvoker(new SandboxInvoker());
    // catch an exception thrown from body and treat that as a failure
    TryBlockEnv env = new TryBlockEnv(caller, null);
    env.addHandler(Throwable.class, onFailure);
    return new Continuable(// perhaps at some point in the future we'll let the Step implementation control this.
    inv.invoke(env, null, onSuccess));
}
Also used : FunctionCallEnv(com.cloudbees.groovy.cps.impl.FunctionCallEnv) Continuable(com.cloudbees.groovy.cps.Continuable) SandboxInvoker(com.cloudbees.groovy.cps.sandbox.SandboxInvoker) TryBlockEnv(com.cloudbees.groovy.cps.impl.TryBlockEnv)

Example 3 with FunctionCallEnv

use of com.cloudbees.groovy.cps.impl.FunctionCallEnv in project groovy-cps by cloudbees.

the class Envs method empty.

/**
     * Works like {@link #empty()} except it allows a custom {@link Invoker}.
     */
public static Env empty(Invoker inv) {
    FunctionCallEnv e = new FunctionCallEnv(null, Continuation.HALT, null, null);
    e.setInvoker(inv);
    return e;
}
Also used : FunctionCallEnv(com.cloudbees.groovy.cps.impl.FunctionCallEnv)

Aggregations

FunctionCallEnv (com.cloudbees.groovy.cps.impl.FunctionCallEnv)3 Continuable (com.cloudbees.groovy.cps.Continuable)1 TryBlockEnv (com.cloudbees.groovy.cps.impl.TryBlockEnv)1 SandboxInvoker (com.cloudbees.groovy.cps.sandbox.SandboxInvoker)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1