Skip to content

Commit

Permalink
Merge pull request #956 from Dohbedoh/JENKINS-74884
Browse files Browse the repository at this point in the history
[JENKINS-74884] Tie RunningFlowActions factory to a specific type of action
  • Loading branch information
jglick authored Nov 20, 2024
2 parents 5eebd32 + 82eabc0 commit af5c179
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.common.util.concurrent.FutureCallback;
import hudson.Extension;
import hudson.Functions;
import hudson.model.Action;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.security.Permission;
Expand Down Expand Up @@ -38,7 +37,7 @@
/**
* Shows thread dump for {@link CpsFlowExecution}.
*/
public final class CpsThreadDumpAction implements Action {
public final class CpsThreadDumpAction extends RunningFlowAction {

private final CpsFlowExecution execution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

package org.jenkinsci.plugins.workflow.cps;

import hudson.model.Action;
import java.io.IOException;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
* Allows a running flow to be paused or unpaused.
*/
public class PauseUnpauseAction implements Action {
public class PauseUnpauseAction extends RunningFlowAction {

static final String URL = "pause";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jenkinsci.plugins.workflow.cps;

import hudson.model.Action;

/**
* Parent class for transient {@link hudson.model.Action}s of running pipeline builds.
* @see org.jenkinsci.plugins.workflow.cps.RunningFlowActions
*/
public abstract class RunningFlowAction implements Action {

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
* Adds actions to the sidebar of a running Pipeline build.
*/
@Extension public class RunningFlowActions extends TransientActionFactory<FlowExecutionOwner.Executable> {


@Override
public Class<? extends Action> actionType() {
return RunningFlowAction.class;
}

@Override public Class<FlowExecutionOwner.Executable> type() {
return FlowExecutionOwner.Executable.class;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jenkinsci.plugins.workflow.cps;

import hudson.model.Action;
import jenkins.model.TransientActionFactory;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;

public class RunningFlowActionsTest {

// JenkinsRule required for initialization of TransientActionFactory cache
@Rule
public JenkinsRule r = new JenkinsRule();

@Test public void noRunningFlowActionsIfTypeIrrelevant() {
assertThat(TransientActionFactory.factoriesFor(WorkflowRun.class, TestNotARunningFlowAction.class),
not(hasItem(instanceOf(RunningFlowActions.class))));
assertThat(TransientActionFactory.factoriesFor(FlowExecutionOwner.Executable.class, TestNotARunningFlowAction.class),
not(hasItem(instanceOf(RunningFlowActions.class))));
assertThat(TransientActionFactory.factoriesFor(FlowExecutionOwner.Executable.class, RunningFlowAction.class),
hasItems(instanceOf(RunningFlowActions.class)));
}

@TestExtension("testNotARunningFlowAction")
public static class TestNotARunningFlowAction implements Action {

@Override
public String getIconFileName() {
return "";
}

@Override
public String getDisplayName() {
return "";
}

@Override
public String getUrlName() {
return "";
}
}
}

0 comments on commit af5c179

Please sign in to comment.