Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jan 18, 2024
1 parent 1b2ce0e commit 08714a4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 52 deletions.
12 changes: 6 additions & 6 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM: -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>656.v54853706d987</version> <!-- TODO https://github.com/jenkinsci/workflow-step-api-plugin/pull/149 -->
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -104,12 +110,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.log.TaskListenerDecorator;
import org.jenkinsci.plugins.workflow.steps.BodyInvoker;
import org.jenkinsci.plugins.workflow.steps.DynamicContext;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
Expand Down Expand Up @@ -155,21 +154,20 @@ private static final class DecoratorImpl extends TaskListenerDecorator {
}
}
private static final class YesPleaseDecorate implements Serializable {}
public static final class DecoratorStep extends Step implements Serializable {
public static final class DecoratorStep extends Step {
@DataBoundConstructor public DecoratorStep() {}
@DataBoundSetter public @CheckForNull String message;
@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.block(context, this::start);
}
private void start(StepContext context, BodyInvoker invoker) throws Exception {
if (message != null) {
TaskListenerDecorator original = context.get(TaskListenerDecorator.class);
DecoratorImpl subsequent = new DecoratorImpl(message);
LOGGER.log(Level.INFO, "merging {0} with {1}", new Object[] {original, subsequent});
invoker.withContext(TaskListenerDecorator.merge(original, subsequent));
} else {
invoker.withContext(new YesPleaseDecorate());
}
return StepExecutions.block(context, (c, invoker) -> {
if (message != null) {
TaskListenerDecorator original = c.get(TaskListenerDecorator.class);
DecoratorImpl subsequent = new DecoratorImpl(message);
LOGGER.log(Level.INFO, "merging {0} with {1}", new Object[] {original, subsequent});
invoker.withContext(TaskListenerDecorator.merge(original, subsequent));
} else {
invoker.withContext(new YesPleaseDecorate());
}
});
}
@TestExtension("smokes") public static final class DescriptorImpl extends StepDescriptor {
@Override public String getFunctionName() {
Expand Down Expand Up @@ -213,11 +211,10 @@ private static final class Message implements Serializable {
public static final class GetMessageStep extends Step {
@DataBoundConstructor public GetMessageStep() {}
@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronous(context, GetMessageStep::run);
}
private static Object run(StepContext context) throws Exception {
Message message = context.get(Message.class);
return message != null ? message.text : null;
return StepExecutions.synchronous(context, c -> {
Message message = c.get(Message.class);
return message != null ? message.text : null;
});
}
@TestExtension("dynamicVsStatic") public static final class DescriptorImpl extends StepDescriptor {
@Override public String getFunctionName() {
Expand All @@ -228,7 +225,7 @@ private static Object run(StepContext context) throws Exception {
}
}
}
public static final class WithStaticMessageStep extends Step implements Serializable {
public static final class WithStaticMessageStep extends Step {
public final String text;
@DataBoundConstructor public WithStaticMessageStep(String text) {
this.text = text;
Expand Down Expand Up @@ -266,7 +263,7 @@ private static final class DynamicMessage implements Serializable {
return dynamicMessage != null ? new Message(dynamicMessage.text) : null;
}
}
public static final class WithDynamicMessageStep extends Step implements Serializable {
public static final class WithDynamicMessageStep extends Step {
public final String text;
@DataBoundConstructor public WithDynamicMessageStep(String text) {
this.text = text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import hudson.model.Describable;
import hudson.model.Executor;
import hudson.model.Result;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
import java.util.logging.Level;
Expand Down Expand Up @@ -927,17 +926,14 @@ public void scriptInitializerCallsCpsTransformedMethod() throws Exception {
jenkins.assertLogContains("Scripts not permitted to use field Test metaClass", b);
}

public static class UnsafeParameterStep extends Step implements Serializable {
public static class UnsafeParameterStep extends Step {
private final UnsafeDescribable val;
@DataBoundConstructor
public UnsafeParameterStep(UnsafeDescribable val) {
this.val = val;
}
public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
val.doSomething();
return null;
});
@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlockingVoid(context, c -> val.doSomething());
}
@TestExtension
public static class DescriptorImpl extends StepDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ public static class NopStep extends Step {
public NopStep(Object value) {}
@Override
public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronous(context, unused -> null);
return StepExecutions.synchronousVoid(context, c -> {});
}
@TestExtension
public static class DescriptorImpl extends StepDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public MonomorphicListStep(List<MonomorphicData> data) {
}

@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
return StepExecutions.synchronousNonBlockingVoid(context, c -> {
for (MonomorphicData d : data) {
c.get(TaskListener.class).getLogger().println(d.getArgs());
}
return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public MonomorphicListWithSymbolStep(List<MonomorphicDataWithSymbol> data) {
}

@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
return StepExecutions.synchronousNonBlockingVoid(context, c -> {
for (MonomorphicDataWithSymbol d : data) {
c.get(TaskListener.class).getLogger().println(d.getArgs());
}
return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public MonomorphicStep(MonomorphicData data) {
}

@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
c.get(TaskListener.class).getLogger().println(data.getArgs());
return null;
});
return StepExecutions.synchronousNonBlockingVoid(context, c -> c.get(TaskListener.class).getLogger().println(data.getArgs()));
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public MonomorphicWithSymbolStep(MonomorphicDataWithSymbol data) {
}

@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
c.get(TaskListener.class).getLogger().println(data.getArgs());
return null;
});
return StepExecutions.synchronousNonBlockingVoid(context, c -> c.get(TaskListener.class).getLogger().println(data.getArgs()));
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ public void setModerate(boolean m) {
}

@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
return StepExecutions.synchronousNonBlockingVoid(context, c -> {
TaskListener listener = c.get(TaskListener.class);
if (moderate) {
listener.getLogger().println("Introducing " + SymbolLookup.getSymbolValue(state).iterator().next());
}
state.sayHello(listener);
return null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public DetectionMetaStep(Chemical compound) {
}

@Override public StepExecution start(StepContext context) throws Exception {
return StepExecutions.synchronousNonBlocking(context, c -> {
c.get(TaskListener.class).getLogger().println("Detecting " + compound.getClass().getName());
return null;
});
return StepExecutions.synchronousNonBlockingVoid(context, c -> c.get(TaskListener.class).getLogger().println("Detecting " + compound.getClass().getName()));
}

@Extension(ordinal=100)
Expand Down

0 comments on commit 08714a4

Please sign in to comment.