Skip to content

Commit 4656c9b

Browse files
bentshermanjorgee
andcommitted
Fix params block in included module (#6940)
Co-authored-by: Jorge Ejarque <jorgee@users.noreply.github.com> Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 3cef015 commit 4656c9b

5 files changed

Lines changed: 59 additions & 18 deletions

File tree

modules/nextflow/src/main/groovy/nextflow/Session.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,6 @@ class Session implements ISession {
10941094
}
10951095

10961096
void notifyAfterWorkflowExecution() {
1097-
10981097
}
10991098

11001099
void notifyFlowBegin() {

modules/nextflow/src/main/groovy/nextflow/script/BaseScript.groovy

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

modules/nextflow/src/main/groovy/nextflow/script/BaseScriptConsts.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ class BaseScriptConsts {
2525

2626
public static Object[] EMPTY_ARGS = [] as Object[]
2727

28-
public static List<String> PRIVATE_NAMES = ['session','processFactory','taskProcessor','meta','entryFlow', 'publisher']
28+
public static List<String> PRIVATE_NAMES = ['session', 'processFactory', 'taskProcessor', 'meta', 'paramsDef', 'entryFlow', 'outputDef']
2929
}

modules/nextflow/src/main/groovy/nextflow/script/OutputDef.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package nextflow.script
1818

1919
import groovy.transform.CompileStatic
2020
import groovy.util.logging.Slf4j
21-
import groovyx.gpars.dataflow.DataflowWriteChannel
2221
import nextflow.Session
2322
/**
2423
* Models the workflow output definition
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2026, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package nextflow.script
18+
19+
import groovy.transform.CompileStatic
20+
import nextflow.Session
21+
/**
22+
* Models the workflow params definition
23+
*
24+
* @author Ben Sherman <bentshermann@gmail.com>
25+
*/
26+
@CompileStatic
27+
class ParamsDef {
28+
29+
private Closure closure
30+
31+
ParamsDef(Closure closure) {
32+
this.closure = closure
33+
}
34+
35+
void apply(Session session) {
36+
final dsl = new ParamsDsl()
37+
final cl = (Closure)closure.clone()
38+
cl.setDelegate(dsl)
39+
cl.setResolveStrategy(Closure.DELEGATE_FIRST)
40+
cl.call()
41+
42+
dsl.apply(session)
43+
}
44+
45+
}

0 commit comments

Comments
 (0)