60
60
import edu .umd .cs .findbugs .annotations .CheckForNull ;
61
61
import edu .umd .cs .findbugs .annotations .NonNull ;
62
62
import groovy .lang .MissingPropertyException ;
63
- import javax .inject .Inject ;
64
63
import jenkins .model .Jenkins ;
65
64
import jenkins .scm .impl .SingleSCMSource ;
66
65
import org .codehaus .groovy .control .MultipleCompilationErrorsException ;
70
69
import org .jenkinsci .plugins .workflow .cps .CpsFlowExecution ;
71
70
import org .jenkinsci .plugins .workflow .cps .CpsThread ;
72
71
import org .jenkinsci .plugins .workflow .flow .FlowExecution ;
73
- import org .jenkinsci .plugins .workflow .steps .AbstractStepDescriptorImpl ;
74
- import org .jenkinsci .plugins .workflow .steps .AbstractStepImpl ;
75
- import org .jenkinsci .plugins .workflow .steps .AbstractSynchronousNonBlockingStepExecution ;
76
- import org .jenkinsci .plugins .workflow .steps .StepContextParameter ;
72
+ import org .jenkinsci .plugins .workflow .steps .Step ;
73
+ import org .jenkinsci .plugins .workflow .steps .StepContext ;
74
+ import org .jenkinsci .plugins .workflow .steps .StepDescriptor ;
75
+ import org .jenkinsci .plugins .workflow .steps .StepExecution ;
76
+ import org .jenkinsci .plugins .workflow .steps .SynchronousNonBlockingStepExecution ;
77
77
import org .kohsuke .accmod .Restricted ;
78
78
import org .kohsuke .accmod .restrictions .DoNotUse ;
79
79
import org .kohsuke .groovy .sandbox .GroovyInterceptor ;
86
86
/**
87
87
* Dynamically injects a library into the running build.
88
88
*/
89
- public class LibraryStep extends AbstractStepImpl {
89
+ public class LibraryStep extends Step {
90
90
91
91
private static final Logger LOGGER = Logger .getLogger (LibraryStep .class .getName ());
92
92
@@ -118,11 +118,11 @@ public Boolean getChangelog() {
118
118
this .changelog = changelog ;
119
119
}
120
120
121
- @ Extension public static class DescriptorImpl extends AbstractStepDescriptorImpl {
121
+ @ Override public StepExecution start (StepContext context ) throws Exception {
122
+ return new Execution (this , context );
123
+ }
122
124
123
- public DescriptorImpl () {
124
- super (Execution .class );
125
- }
125
+ @ Extension public static class DescriptorImpl extends StepDescriptor {
126
126
127
127
@ Override public String getFunctionName () {
128
128
return "library" ;
@@ -132,6 +132,10 @@ public DescriptorImpl() {
132
132
return "Load a library on the fly" ;
133
133
}
134
134
135
+ @ Override public Set <? extends Class <?>> getRequiredContext () {
136
+ return Set .of (Run .class , TaskListener .class , FlowExecution .class );
137
+ }
138
+
135
139
@ Restricted (DoNotUse .class ) // Jelly
136
140
public Collection <LibraryRetrieverDescriptor > getRetrieverDescriptors () {
137
141
return Jenkins .get ().getDescriptorByType (LibraryConfiguration .DescriptorImpl .class ).getRetrieverDescriptors ();
@@ -157,15 +161,20 @@ public AutoCompletionCandidates doAutoCompleteIdentifier(@AncestorInPath ItemGro
157
161
158
162
}
159
163
160
- public static class Execution extends AbstractSynchronousNonBlockingStepExecution <LoadedClasses > {
164
+ public static class Execution extends SynchronousNonBlockingStepExecution <LoadedClasses > {
161
165
162
166
private static final long serialVersionUID = 1L ;
163
167
164
- @ Inject private transient LibraryStep step ;
165
- @ StepContextParameter private transient Run <?,?> run ;
166
- @ StepContextParameter private transient TaskListener listener ;
168
+ private transient final LibraryStep step ;
169
+
170
+ Execution (LibraryStep step , StepContext context ) {
171
+ super (context );
172
+ this .step = step ;
173
+ }
167
174
168
175
@ Override protected LoadedClasses run () throws Exception {
176
+ Run <?,?> run = getContext ().get (Run .class );
177
+ TaskListener listener = getContext ().get (TaskListener .class );
169
178
String [] parsed = LibraryAdder .parse (step .identifier );
170
179
String name = parsed [0 ], version = parsed [1 ];
171
180
boolean trusted = false ;
@@ -204,9 +213,9 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
204
213
// uses the library step with a non-null retriever to check out a static version of the library.
205
214
// Fixing this would require us being able to detect usage of SCMVar precisely, which is not currently possible.
206
215
else if (retriever instanceof SCMRetriever ) {
207
- verifyRevision (((SCMRetriever ) retriever ).getScm (), name );
216
+ verifyRevision (((SCMRetriever ) retriever ).getScm (), name , run , listener );
208
217
} else if (retriever instanceof SCMSourceRetriever && ((SCMSourceRetriever ) retriever ).getScm () instanceof SingleSCMSource ) {
209
- verifyRevision (((SingleSCMSource ) ((SCMSourceRetriever ) retriever ).getScm ()).getScm (), name );
218
+ verifyRevision (((SingleSCMSource ) ((SCMSourceRetriever ) retriever ).getScm ()).getScm (), name , run , listener );
210
219
}
211
220
212
221
LibraryRecord record = new LibraryRecord (name , version , trusted , changelog , cachingConfiguration , source );
@@ -236,9 +245,9 @@ else if (retriever instanceof SCMRetriever) {
236
245
return new LoadedClasses (name , record .getDirectoryName (), trusted , changelog , run );
237
246
}
238
247
239
- private void verifyRevision (SCM scm , String name ) throws IOException , InterruptedException {
248
+ private void verifyRevision (SCM scm , String name , Run <?,?> run , TaskListener listener ) throws IOException , InterruptedException {
240
249
for (LibraryStepRetrieverVerifier revisionVerifier : LibraryStepRetrieverVerifier .all ()) {
241
- revisionVerifier .verify (this . run , listener , scm , name );
250
+ revisionVerifier .verify (run , listener , scm , name );
242
251
}
243
252
}
244
253
0 commit comments