/** * Persists the current state of {@link CpsThreadGroup}. */ @CpsVmThreadOnly void saveProgram() throws IOException { File f = execution.getProgramDataFile(); saveProgram(f); }
public CpsGroovyShell build() { ClassLoader parent = this.parent; if (parent==null) parent = makeClassLoader(); CpsGroovyShell shell = new CpsGroovyShell(parent, execution, makeConfig()); for (GroovyShellDecorator d : decorators) { d.configureShell(execution,shell); } return shell; } }
CpsThread(CpsThreadGroup group, int id, Continuable program, FlowHead head, ContextVariableSet contextVariables) { this.group = group; this.id = id; this.program = group.getExecution().isSandbox() ? new SandboxContinuable(program,this) : program; this.head = head; this.contextVariables = contextVariables; }
@Override public boolean start() throws Exception { Closure body = ScriptBytecodeAdapter.getMethodPointer(this, "bodyBlock"); CpsStepContext cps = (CpsStepContext) getContext(); CpsThread t = CpsThread.current(); cps.newBodyInvoker(t.getGroup().export(body)) .withCallback(BodyExecutionCallback.wrap(cps)) .start(); return false; } }
@SuppressWarnings("unchecked") // Binding final void $initialize() throws IOException { // TODO JENKINS-33353 could make this a GlobalVariable instead getBinding().setVariable(STEPS_VAR, new DSL(execution.getOwner())); }
/** Default constructor for {@link CpsFlowExecution}. */ public CpsScript() throws IOException { // if the script is instantiated in workflow, automatically set up the contextual // 'execution' object. This allows those scripts to invoke workflow steps without // any special setup, making it easy to write reusable functions. CpsThread c = CpsThread.current(); if (c!=null) { execution = c.getExecution(); $initialize(); } }
/** * Obtains the Groovy compiler to be used for compiling user script * in the CPS-transformed and sandboxed manner. */ private GroovyShell $getShell() { return CpsThreadGroup.current().getExecution().getShell(); }
public String getThreadDump() { return execution.getThreadDump().toString(); }
private void tearDown(ThreadContext context) { CURRENT.set(null); cpsThreadGroup.busy = false; context.restore(); CpsFlowExecution execution = cpsThreadGroup.getExecution(); if (isShutdown()) { execution.logTimings(); } }
public CpsFlowExecution createExecution(CpsFlowDefinition fdef) throws Exception { exec = fdef.create(new FlowExecutionOwnerImpl()); return exec; }
@CpsVmThreadOnly public CpsThread addThread(Continuable program, FlowHead head, ContextVariableSet contextVariables) { assertVmThread(); CpsThread t = new CpsThread(this, iota++, program, head, contextVariables); threads.put(t.id, t); return t; }
/** * Evaluates the body but grow the {@link FlowNode}s on the same head as the current thread. * * The net effect is as if the body evaluation happens in the same thread as in the caller thread. */ @CpsVmThreadOnly /*package*/ void launch(CpsThread currentThread) { launch(currentThread, currentThread.head); }
@CpsVmThreadOnly /*package*/ void launch(CpsThread currentThread, FlowHead head) { execution.launch(this, currentThread, head); } }
void remove() { getExecution().removeHead(this); }
@Override public void print(Object value) { // TODO: handling 'print' correctly requires collapsing multiple adjacent print calls into one Step. println(value); }
public boolean hasScmContext(CpsScript script) { try { script.getProperty("scm"); return true; } catch (Exception e) { return false; } }
/** * Record time taken during a certain class of operation in this build. * @param kind what sort of operation is being done * @return something to {@link Timing#close} when finished */ Timing time(TimingKind kind) { return new Timing(kind); }
@Override public GroovyShellDecorator forTrusted() { return new UntrustedShellDecorator(); } }