Skip to content
Permalink
Browse files

[JENKINS-26107] StepContext.hasBody implementation.

  • Loading branch information...
jglick committed May 12, 2016
1 parent 3868a97 commit 9b2acc778065bba8232fbb5dd6255c0d53d73098
@@ -69,7 +69,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-step-api</artifactId>
<version>1.15</version>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -152,7 +152,7 @@
*
* This is the implicit closure block passed to the step invocation.
*/
private BodyReference body;
private @CheckForNull BodyReference body;

private final int threadId;

@@ -174,12 +174,12 @@
private transient volatile boolean loadingThreadGroup;

@CpsVmThreadOnly
CpsStepContext(StepDescriptor step, CpsThread thread, FlowExecutionOwner executionRef, FlowNode node, Closure body) {
CpsStepContext(StepDescriptor step, CpsThread thread, FlowExecutionOwner executionRef, FlowNode node, @CheckForNull Closure body) {
this.threadId = thread.id;
this.executionRef = executionRef;
this.id = node.getId();
this.node = node;
this.body = thread.group.export(body);
this.body = body != null ? thread.group.export(body) : null;
this.stepDescriptorId = step.getId();
}

@@ -269,14 +269,19 @@ public String getDisplayName() {
}
}

@Override public boolean hasBody() {
return body != null;
}

@Override
public CpsBodyInvoker newBodyInvoker() {
if (body == null) {
throw new IllegalStateException("There is no body to invoke");
}
return newBodyInvoker(body);
}

public CpsBodyInvoker newBodyInvoker(BodyReference body) {
if (body==null)
throw new IllegalStateException("There's no body to invoke");
public @Nonnull CpsBodyInvoker newBodyInvoker(@Nonnull BodyReference body) {
return new CpsBodyInvoker(this,body);
}

@@ -60,6 +60,7 @@
import java.util.logging.Logger;

import static java.util.logging.Level.*;
import javax.annotation.Nonnull;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import static org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.*;
import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.*;
@@ -149,17 +150,15 @@ public CpsThread getThread(int id) {
}

@CpsVmThreadOnly("root")
public BodyReference export(Closure body) {
public @Nonnull BodyReference export(@Nonnull Closure body) {
assertVmThread();
if (body==null) return null;
int id = iota++;
closures.put(id, body);
return new StaticBodyReference(id,body);
}

@CpsVmThreadOnly("root")
public BodyReference export(final Script body) {
if (body==null) return null;
public @Nonnull BodyReference export(@Nonnull final Script body) {
return export(new Closure(null) {
@Override
public Object call() {

0 comments on commit 9b2acc7

Please sign in to comment.
You can’t perform that action at this time.