44
44
import java .util .Set ;
45
45
import java .util .logging .Level ;
46
46
import java .util .logging .Logger ;
47
- import jakarta .inject .Inject ;
48
47
49
- import hudson .model .TaskListener ;
50
48
import jenkins .branch .BuildRetentionBranchProperty ;
51
49
import jenkins .branch .RateLimitBranchProperty ;
52
50
import jenkins .model .Jenkins ;
56
54
import org .jenkinsci .plugins .workflow .graphanalysis .DepthFirstScanner ;
57
55
import org .jenkinsci .plugins .workflow .graphanalysis .NodeStepTypePredicate ;
58
56
import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
59
- import org .jenkinsci .plugins .workflow .steps .AbstractStepDescriptorImpl ;
60
- import org .jenkinsci .plugins .workflow .steps .AbstractStepImpl ;
61
- import org .jenkinsci .plugins .workflow .steps .AbstractSynchronousStepExecution ;
62
57
import org .jenkinsci .plugins .workflow .steps .Step ;
63
- import org .jenkinsci .plugins .workflow .steps .StepContextParameter ;
58
+ import org .jenkinsci .plugins .workflow .steps .StepContext ;
59
+ import org .jenkinsci .plugins .workflow .steps .StepDescriptor ;
60
+ import org .jenkinsci .plugins .workflow .steps .StepExecution ;
61
+ import org .jenkinsci .plugins .workflow .steps .SynchronousStepExecution ;
64
62
import org .kohsuke .accmod .Restricted ;
65
63
import org .kohsuke .accmod .restrictions .DoNotUse ;
66
64
import org .kohsuke .stapler .DataBoundConstructor ;
70
68
* Resets the properties of the current job.
71
69
*/
72
70
@ SuppressWarnings ({"unchecked" , "rawtypes" }) // TODO JENKINS-26535: cannot bind List<JobProperty<?>>
73
- public class JobPropertyStep extends AbstractStepImpl {
71
+ public class JobPropertyStep extends Step {
74
72
75
73
private final List <JobProperty > properties ;
76
74
@@ -88,14 +86,22 @@ public Map<JobPropertyDescriptor,JobProperty> getPropertiesMap() {
88
86
return Descriptor .toMap ((List ) properties );
89
87
}
90
88
91
- public static class Execution extends AbstractSynchronousStepExecution <Void > {
89
+ @ Override public StepExecution start (StepContext context ) throws Exception {
90
+ return new Execution (this , context );
91
+ }
92
+
93
+ public static class Execution extends SynchronousStepExecution <Void > {
92
94
93
- @ Inject transient JobPropertyStep step ;
94
- @ StepContextParameter transient Run <?,?> build ;
95
- @ StepContextParameter transient TaskListener l ;
95
+ private transient final JobPropertyStep step ;
96
+
97
+ Execution (JobPropertyStep step , StepContext context ) {
98
+ super (context );
99
+ this .step = step ;
100
+ }
96
101
97
102
@ SuppressWarnings ("unchecked" ) // untypable
98
103
@ Override protected Void run () throws Exception {
104
+ Run <?,?> build = getContext ().get (Run .class );
99
105
Job <?,?> job = build .getParent ();
100
106
101
107
JobPropertyTrackerAction previousAction = job .getAction (JobPropertyTrackerAction .class );
@@ -162,11 +168,7 @@ public static class Execution extends AbstractSynchronousStepExecution<Void> {
162
168
163
169
}
164
170
165
- @ Extension public static class DescriptorImpl extends AbstractStepDescriptorImpl {
166
-
167
- public DescriptorImpl () {
168
- super (Execution .class );
169
- }
171
+ @ Extension public static class DescriptorImpl extends StepDescriptor {
170
172
171
173
@ Override public String getFunctionName () {
172
174
return "properties" ;
@@ -177,6 +179,10 @@ public DescriptorImpl() {
177
179
return "Set job properties" ;
178
180
}
179
181
182
+ @ Override public Set <? extends Class <?>> getRequiredContext () {
183
+ return Set .of (Run .class );
184
+ }
185
+
180
186
@ Override public Step newInstance (@ NonNull StaplerRequest req , @ NonNull JSONObject formData ) throws FormException {
181
187
if (req == null ) { // should not happen
182
188
return super .newInstance (null , formData );
0 commit comments