Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-64438] Implement removeAll on FlowNode actions to support addOrReplaceAction. #133

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.ObjectStreamException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -463,6 +464,15 @@ public Action set(int index, Action element) {
public int size() {
return actions.size();
}

@Override
public boolean removeAll(Collection<?> c) {
boolean changed = actions.removeAll(c);
if (changed) {
persistSafe();
}
return changed;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ public void nodeWithNoParentsInBruteForceScanForEnclosingBlock() {
});
}

@Test
mrginglymus marked this conversation as resolved.
Show resolved Hide resolved
public void addOrReplaceActionWorks() {
rr.then(r -> {
WorkflowJob j = r.createProject(WorkflowJob.class);
j.setDefinition(new CpsFlowDefinition("doubleWarning()", true));
r.buildAndAssertSuccess(j);
});
}

private void assertWarning(FlowNode node, Result expectedResult, BallColor expectedColor) {
WarningAction warningAction = node.getPersistentAction(WarningAction.class);
assertNotNull(warningAction);
Expand Down Expand Up @@ -572,5 +581,36 @@ public Set<? extends Class<?>> getRequiredContext() {
}
}
}

public static class DoubleWarningStep extends Step {

@DataBoundConstructor
public DoubleWarningStep() {}

@Override
public StepExecution start(StepContext context) throws Exception {
return new StepExecution(context) {
@Override
public boolean start() throws Exception {
getContext().get(FlowNode.class).addAction(new WarningAction(Result.FAILURE).withMessage("First"));
getContext().get(FlowNode.class).addOrReplaceAction(new WarningAction(Result.FAILURE).withMessage("Second"));
getContext().onSuccess(null);
return true;
}
};
}
@TestExtension("addOrReplaceActionWorks")
public static class DescriptorImpl extends StepDescriptor {
@Override
public String getFunctionName() {
return "doubleWarning";
}

@Override
public Set<? extends Class<?>> getRequiredContext() {
return Collections.singleton(FlowNode.class);
}
}
}
}