@@ -67,8 +67,7 @@ class Nextflow {
6767 return SysEnv . get(name)
6868 }
6969
70- static private fileNamePattern ( FilePatternSplitter splitter , Map opts ) {
71-
70+ private static List<Path > fileNamePattern ( FilePatternSplitter splitter , Map opts ) {
7271 final scheme = splitter. scheme
7372 final target = scheme ? " $scheme ://$splitter . parent " : splitter. parent
7473 final folder = toCanonicalPath(target)
@@ -77,15 +76,14 @@ class Nextflow {
7776 if ( opts == null ) opts = [:]
7877 if ( ! opts. type ) opts. type = ' file'
7978
80- def result = new LinkedList ()
79+ def result = new LinkedList< Path > ()
8180 try {
8281 FileHelper . visitFiles(opts, folder, pattern) { Path it -> result. add(it) }
8382 }
8483 catch (NoSuchFileException e) {
8584 log. debug " No such file or directory: $folder -- Skipping visit"
8685 }
8786 return result
88-
8987 }
9088
9189 static private String str0 (value ) {
@@ -113,11 +111,16 @@ class Nextflow {
113111 * @param path A file path eventually including a glob pattern e.g. /some/path/file*.txt
114112 * @return An instance of {@link Path} when a single file is matched or a list of {@link Path}s
115113 */
116- static file ( Map options = null , def filePattern ) {
117-
114+ static file (Map options = null , def filePattern ) {
118115 if ( ! filePattern )
119- throw new IllegalArgumentException (" Argument of `file` function cannot be ${ filePattern==null?'null':'empty'} " )
116+ throw new IllegalArgumentException (" Argument of `file()` function cannot be ${ filePattern==null?'null':'empty'} " )
117+ final result = file0(options, filePattern)
118+ if ( result instanceof Collection && result. size() != 1 && NF . isSyntaxParserV2() )
119+ log. warn " The `file()` function was called with a glob pattern that matched a collection of files -- use `files()` instead."
120+ return result
121+ }
120122
123+ private static file0 ( Map options = null , def filePattern ) {
121124 final path = filePattern as Path
122125 final glob = options?. containsKey(' glob' ) ? options. glob as boolean : isGlobAllowed(path)
123126 if ( ! glob ) {
@@ -140,9 +143,11 @@ class Nextflow {
140143 return result
141144 }
142145
143- static files ( Map options = null , def path ) {
144- def result = file(options, path)
145- return result instanceof List ? result : [result]
146+ static Collection<Path > files (Map options = null , def filePattern ) {
147+ if ( ! filePattern )
148+ throw new IllegalArgumentException (" Argument of `files()` function cannot be ${ filePattern==null?'null':'empty'} " )
149+ final result = file0(options, filePattern)
150+ return result instanceof Collection ? result : [result]
146151 }
147152
148153
0 commit comments