28
28
import edu .umd .cs .findbugs .annotations .NonNull ;
29
29
import hudson .AbortException ;
30
30
import hudson .Extension ;
31
+ import hudson .Util ;
31
32
import hudson .model .Action ;
32
33
import hudson .model .Descriptor ;
33
34
import hudson .model .Failure ;
68
69
import org .kohsuke .stapler .QueryParameter ;
69
70
import org .kohsuke .stapler .Stapler ;
70
71
import org .kohsuke .stapler .StaplerRequest ;
72
+ import org .kohsuke .stapler .StaplerRequest2 ;
71
73
import org .kohsuke .stapler .interceptor .RequirePOST ;
72
74
73
75
/**
@@ -89,7 +91,7 @@ public CpsFlowDefinition(String script) throws Descriptor.FormException {
89
91
@ DataBoundConstructor
90
92
public CpsFlowDefinition (String script , boolean sandbox ) throws Descriptor .FormException {
91
93
ScriptApproval .validateSandbox (sandbox );
92
- StaplerRequest req = Stapler .getCurrentRequest ();
94
+ StaplerRequest2 req = Stapler .getCurrentRequest2 ();
93
95
this .script = sandbox ? script : ScriptApproval .get ().configuring (script , GroovyLanguage .get (),
94
96
ApprovalContext .create ().withCurrentUser ().withItemAsKey (req != null ? req .findAncestorObject (Item .class ) : null ), req == null );
95
97
this .sandbox = sandbox ;
@@ -146,8 +148,26 @@ public static class DescriptorImpl extends FlowDefinitionDescriptor {
146
148
* @DataBoundSetters have been invoked (rather than in the @DataBoundConstructor), which is why we use Descriptor.newInstance.
147
149
*/
148
150
@ Override
151
+ public FlowDefinition newInstance (@ NonNull StaplerRequest2 req , @ NonNull JSONObject formData ) throws FormException {
152
+ if (Util .isOverridden (FlowDefinitionDescriptor .class , getClass (), "newInstance" , StaplerRequest .class , JSONObject .class )) {
153
+ return newInstance (StaplerRequest .fromStaplerRequest2 (req ), formData );
154
+ } else {
155
+ CpsFlowDefinition cpsFlowDefinition = (CpsFlowDefinition ) super .newInstance (req , formData );
156
+ return newInstanceImpl (cpsFlowDefinition , req , formData );
157
+ }
158
+ }
159
+
160
+ /**
161
+ * @deprecated use {@link #newInstance(StaplerRequest2, JSONObject)}
162
+ */
163
+ @ Deprecated
164
+ @ Override
149
165
public FlowDefinition newInstance (@ NonNull StaplerRequest req , @ NonNull JSONObject formData ) throws FormException {
150
166
CpsFlowDefinition cpsFlowDefinition = (CpsFlowDefinition ) super .newInstance (req , formData );
167
+ return newInstanceImpl (cpsFlowDefinition , StaplerRequest .toStaplerRequest2 (req ), formData );
168
+ }
169
+
170
+ private FlowDefinition newInstanceImpl (CpsFlowDefinition cpsFlowDefinition , @ NonNull StaplerRequest2 req , @ NonNull JSONObject formData ) {
151
171
if (!cpsFlowDefinition .sandbox && formData .get ("oldScript" ) != null ) {
152
172
String oldScript = formData .getString ("oldScript" );
153
173
boolean approveIfAdmin = !StringUtils .equals (oldScript , cpsFlowDefinition .script );
0 commit comments