@@ -44,9 +44,11 @@ abstract class BaseScript extends Script implements ExecutionContext {
4444
4545 private ScriptMeta meta
4646
47+ private ParamsDef paramsDef
48+
4749 private WorkflowDef entryFlow
4850
49- private OutputDef publisher
51+ private OutputDef outputDef
5052
5153 @Lazy InputStream stdin = { System . in }()
5254
@@ -113,13 +115,7 @@ abstract class BaseScript extends Script implements ExecutionContext {
113115 if ( ExecutionStack . withinWorkflow() )
114116 throw new IllegalStateException (" Workflow params definition is not allowed within a workflow" )
115117
116- final dsl = new ParamsDsl ()
117- final cl = (Closure )body. clone()
118- cl. setDelegate(dsl)
119- cl. setResolveStrategy(Closure . DELEGATE_FIRST )
120- cl. call()
121-
122- dsl. apply(session)
118+ this . paramsDef = new ParamsDef (body)
123119 }
124120
125121 /**
@@ -182,21 +178,21 @@ abstract class BaseScript extends Script implements ExecutionContext {
182178 /**
183179 * Define an output block.
184180 *
185- * @param closure
181+ * @param body
186182 */
187- protected void output (Closure closure ) {
183+ protected void output (Closure body ) {
188184 if ( ! entryFlow )
189185 throw new IllegalStateException (" Workflow output definition must be defined after the entry workflow" )
190186 if ( ExecutionStack . withinWorkflow() )
191187 throw new IllegalStateException (" Workflow output definition is not allowed within a workflow" )
192188
193- publisher = new OutputDef (closure )
189+ this . outputDef = new OutputDef (body )
194190 }
195191
196192 protected IncludeDef include ( IncludeDef include ) {
197- if (ExecutionStack . withinWorkflow())
193+ if ( ExecutionStack . withinWorkflow() )
198194 throw new IllegalStateException (" Include statement is not allowed within a workflow definition" )
199- include .setSession(session)
195+ return include . setSession(session)
200196 }
201197
202198 /**
@@ -246,9 +242,11 @@ abstract class BaseScript extends Script implements ExecutionContext {
246242
247243 // invoke the entry workflow
248244 session. notifyBeforeWorkflowExecution()
245+ if ( paramsDef )
246+ paramsDef. apply(session)
249247 final ret = entryFlow. invoke_a(BaseScriptConsts . EMPTY_ARGS )
250- if ( publisher )
251- publisher . apply(session)
248+ if ( outputDef )
249+ outputDef . apply(session)
252250 session. notifyAfterWorkflowExecution()
253251 return ret
254252 }
0 commit comments