Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10 from jglick/optional-block-JENKINS-26107
[JENKINS-26107] StepContext.hasBody implementation
  • Loading branch information
jglick committed May 19, 2016
2 parents 3868a97 + 9b2acc7 commit 891a1bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -152,7 +152,7 @@ public class CpsStepContext extends DefaultStepContext { // TODO add XStream cla
*
* This is the implicit closure block passed to the step invocation.
*/
private BodyReference body;
private @CheckForNull BodyReference body;

private final int threadId;

Expand All @@ -174,12 +174,12 @@ public class CpsStepContext extends DefaultStepContext { // TODO add XStream cla
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();
}

Expand Down Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 891a1bd

Please sign in to comment.