6060import edu .umd .cs .findbugs .annotations .CheckForNull ;
6161import edu .umd .cs .findbugs .annotations .NonNull ;
6262import groovy .lang .MissingPropertyException ;
63- import jakarta .inject .Inject ;
6463import jenkins .model .Jenkins ;
6564import jenkins .scm .impl .SingleSCMSource ;
6665import org .codehaus .groovy .control .MultipleCompilationErrorsException ;
7069import org .jenkinsci .plugins .workflow .cps .CpsFlowExecution ;
7170import org .jenkinsci .plugins .workflow .cps .CpsThread ;
7271import 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 ;
7777import org .kohsuke .accmod .Restricted ;
7878import org .kohsuke .accmod .restrictions .DoNotUse ;
7979import org .kohsuke .groovy .sandbox .GroovyInterceptor ;
8686/**
8787 * Dynamically injects a library into the running build.
8888 */
89- public class LibraryStep extends AbstractStepImpl {
89+ public class LibraryStep extends Step {
9090
9191 private static final Logger LOGGER = Logger .getLogger (LibraryStep .class .getName ());
9292
@@ -118,11 +118,11 @@ public Boolean getChangelog() {
118118 this .changelog = changelog ;
119119 }
120120
121- @ Extension public static class DescriptorImpl extends AbstractStepDescriptorImpl {
121+ @ Override public StepExecution start (StepContext context ) throws Exception {
122+ return new Execution (this , context );
123+ }
122124
123- public DescriptorImpl () {
124- super (Execution .class );
125- }
125+ @ Extension public static class DescriptorImpl extends StepDescriptor {
126126
127127 @ Override public String getFunctionName () {
128128 return "library" ;
@@ -132,6 +132,10 @@ public DescriptorImpl() {
132132 return "Load a library on the fly" ;
133133 }
134134
135+ @ Override public Set <? extends Class <?>> getRequiredContext () {
136+ return Set .of (Run .class , TaskListener .class , FlowExecution .class );
137+ }
138+
135139 @ Restricted (DoNotUse .class ) // Jelly
136140 public Collection <LibraryRetrieverDescriptor > getRetrieverDescriptors () {
137141 return Jenkins .get ().getDescriptorByType (LibraryConfiguration .DescriptorImpl .class ).getRetrieverDescriptors ();
@@ -157,15 +161,20 @@ public AutoCompletionCandidates doAutoCompleteIdentifier(@AncestorInPath ItemGro
157161
158162 }
159163
160- public static class Execution extends AbstractSynchronousNonBlockingStepExecution <LoadedClasses > {
164+ public static class Execution extends SynchronousNonBlockingStepExecution <LoadedClasses > {
161165
162166 private static final long serialVersionUID = 1L ;
163167
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+ }
167174
168175 @ Override protected LoadedClasses run () throws Exception {
176+ Run <?,?> run = getContext ().get (Run .class );
177+ TaskListener listener = getContext ().get (TaskListener .class );
169178 String [] parsed = LibraryAdder .parse (step .identifier );
170179 String name = parsed [0 ], version = parsed [1 ];
171180 boolean trusted = false ;
@@ -204,9 +213,9 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
204213 // uses the library step with a non-null retriever to check out a static version of the library.
205214 // Fixing this would require us being able to detect usage of SCMVar precisely, which is not currently possible.
206215 else if (retriever instanceof SCMRetriever ) {
207- verifyRevision (((SCMRetriever ) retriever ).getScm (), name );
216+ verifyRevision (((SCMRetriever ) retriever ).getScm (), name , run , listener );
208217 } 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 );
210219 }
211220
212221 LibraryRecord record = new LibraryRecord (name , version , trusted , changelog , cachingConfiguration , source );
@@ -236,9 +245,9 @@ else if (retriever instanceof SCMRetriever) {
236245 return new LoadedClasses (name , record .getDirectoryName (), trusted , changelog , run );
237246 }
238247
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 {
240249 for (LibraryStepRetrieverVerifier revisionVerifier : LibraryStepRetrieverVerifier .all ()) {
241- revisionVerifier .verify (this . run , listener , scm , name );
250+ revisionVerifier .verify (run , listener , scm , name );
242251 }
243252 }
244253
0 commit comments