Skip to content

Commit

Permalink
[JENKINS-26107] StepContext.hasBody implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed May 12, 2016
1 parent 3868a97 commit 9b2acc7
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> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>workflow-step-api</artifactId> <artifactId>workflow-step-api</artifactId>
<version>1.15</version> <version>2.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <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. * This is the implicit closure block passed to the step invocation.
*/ */
private BodyReference body; private @CheckForNull BodyReference body;


private final int threadId; private final int threadId;


Expand All @@ -174,12 +174,12 @@ public class CpsStepContext extends DefaultStepContext { // TODO add XStream cla
private transient volatile boolean loadingThreadGroup; private transient volatile boolean loadingThreadGroup;


@CpsVmThreadOnly @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.threadId = thread.id;
this.executionRef = executionRef; this.executionRef = executionRef;
this.id = node.getId(); this.id = node.getId();
this.node = node; this.node = node;
this.body = thread.group.export(body); this.body = body != null ? thread.group.export(body) : null;
this.stepDescriptorId = step.getId(); this.stepDescriptorId = step.getId();
} }


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


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

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


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


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


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


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


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

0 comments on commit 9b2acc7

Please sign in to comment.