Skip to content

Commit

Permalink
Merge pull request #974 from jglick/StepExecution.acceptAll
Browse files Browse the repository at this point in the history
Using `StepExecution.acceptAll`
  • Loading branch information
jglick authored Jan 24, 2025
2 parents 91e9951 + 8c9547d commit cd7dc51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
6 changes: 6 additions & 0 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>686.v603d058a_e148</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

package org.jenkinsci.plugins.workflow;

import com.google.common.base.Function;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
Expand Down Expand Up @@ -214,17 +213,14 @@ public static final class Execution extends AbstractStepExecutionImpl {
}
}
public static void finish(final boolean terminate) {
StepExecution.applyAll(Execution.class, new Function<>() {
@Override public Void apply(Execution input) {
try {
input.listener.getLogger().println((terminate ? "finally" : "still") + " running as " + input.flow.getAuthentication().getName() + " from " + Thread.currentThread().getName());
if (terminate) {
input.getContext().onSuccess(null);
}
} catch (Exception x) {
input.getContext().onFailure(x);
StepExecution.acceptAll(Execution.class, input -> {
try {
input.listener.getLogger().println((terminate ? "finally" : "still") + " running as " + input.flow.getAuthentication().getName() + " from " + Thread.currentThread().getName());
if (terminate) {
input.getContext().onSuccess(null);
}
return null;
} catch (Exception x) {
input.getContext().onFailure(x);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.workflow.cps;

import com.google.common.base.Function;
import com.google.common.collect.Sets;
import groovy.lang.Closure;
import hudson.model.Result;
Expand Down Expand Up @@ -151,22 +150,14 @@ public boolean start() throws Exception {
SemaphoreStep.waitForStart("b/1", b);
SemaphoreStep.waitForStart("c/1", b);
final RetainsBodyStep.Execution[] execs = new RetainsBodyStep.Execution[3];
StepExecution.applyAll(RetainsBodyStep.Execution.class, new Function<>() {
@Override public Void apply(RetainsBodyStep.Execution exec) {
execs[exec.count] = exec;
return null;
}
}).get();
StepExecution.acceptAll(RetainsBodyStep.Execution.class, exec -> execs[exec.count] = exec).get();
assertNotNull(execs[0]);
assertNotNull(execs[1]);
assertNotNull(execs[2]);
final Set<SemaphoreStep.Execution> semaphores = new HashSet<>();
StepExecution.applyAll(SemaphoreStep.Execution.class, new Function<>() {
@Override public Void apply(SemaphoreStep.Execution exec) {
if (exec.getStatus().matches("waiting on [ab]/1")) {
semaphores.add(exec);
}
return null;
StepExecution.acceptAll(SemaphoreStep.Execution.class, exec -> {
if (exec.getStatus().matches("waiting on [ab]/1")) {
semaphores.add(exec);
}
}).get();
assertThat(semaphores, iterableWithSize(2));
Expand Down

0 comments on commit cd7dc51

Please sign in to comment.