Skip to content

Commit

Permalink
Merge pull request #30 from jglick/FlowCopier.StandardActions
Browse files Browse the repository at this point in the history
Introduced FlowCopier.StandardActions
  • Loading branch information
jglick committed Feb 14, 2017
2 parents b8f6ce6 + c1a5367 commit 2117044
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -70,6 +70,11 @@
<artifactId>workflow-step-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/jenkinsci/plugins/workflow/flow/FlowCopier.java
Expand Up @@ -24,11 +24,18 @@

package org.jenkinsci.plugins.workflow.flow;

import com.google.common.collect.ImmutableList;
import hudson.Extension;
import hudson.ExtensionPoint;
import hudson.model.Action;
import hudson.model.ParametersAction;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.IOException;
import jenkins.scm.api.SCMRevisionAction;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;

/**
* A way for plugins to copy metadata and associated files from one flow execution to another.
Expand Down Expand Up @@ -64,4 +71,26 @@ public static abstract class ByRun extends FlowCopier {

}

@Restricted(DoNotUse.class) // impl
@Extension public static class StandardActions extends FlowCopier.ByRun {

// TODO cloned from ReplayAction; consider whether it is appropriate to share these (related but not identical case)
private static final Iterable<Class<? extends Action>> COPIED_ACTIONS = ImmutableList.of(
ParametersAction.class,
SCMRevisionAction.class
);

@Override public void copy(Run<?, ?> original, Run<?, ?> copy, TaskListener listener) throws IOException, InterruptedException {
for (Class<? extends Action> type : COPIED_ACTIONS) {
Action a = original.getAction(type);
if (a != null) {
// Especially for ParametersAction we must replace any existing action.
// For example, scheduleBuild2 will typically create an instance from default parameter values.
copy.replaceAction(a);
}
}
}

}

}

0 comments on commit 2117044

Please sign in to comment.