17
17
package org .springframework .boot .cli .command ;
18
18
19
19
import java .io .File ;
20
+ import java .io .IOException ;
20
21
import java .net .URL ;
21
22
import java .util .ArrayList ;
23
+ import java .util .Arrays ;
22
24
import java .util .Collections ;
25
+ import java .util .Enumeration ;
23
26
import java .util .List ;
24
27
25
28
import joptsimple .OptionSet ;
@@ -69,11 +72,11 @@ public FileOptions(OptionSet optionSet, ClassLoader classLoader,
69
72
break ;
70
73
}
71
74
if (filename .endsWith (".groovy" ) || filename .endsWith (".java" )) {
72
- File file = getFile (filename , classLoader );
73
- if (file == null ) {
75
+ List < File > file = getFiles (filename , classLoader );
76
+ if (file . isEmpty () ) {
74
77
throw new IllegalArgumentException ("Can't find " + filename );
75
78
}
76
- files .add (file );
79
+ files .addAll (file );
77
80
}
78
81
}
79
82
}
@@ -84,27 +87,38 @@ public FileOptions(OptionSet optionSet, ClassLoader classLoader,
84
87
throw new RuntimeException ("Please specify at least one file to run" );
85
88
}
86
89
for (String path : defaultPaths ) {
87
- File file = getFile (path , classLoader );
88
- if (file != null && file .exists ()) {
89
- files .add (file );
90
+ for (File file : getFiles (path , classLoader )) {
91
+ if (file != null && file .exists ()) {
92
+ files .add (file );
93
+ }
90
94
}
91
95
}
92
96
}
93
97
this .files = Collections .unmodifiableList (files );
94
98
}
95
99
96
- private File getFile (String filename , ClassLoader classLoader ) {
100
+ private List < File > getFiles (String filename , ClassLoader classLoader ) {
97
101
File file = new File (filename );
98
102
if (file .isFile () && file .canRead ()) {
99
- return file ;
103
+ return Arrays . asList ( file ) ;
100
104
}
105
+ List <File > result = new ArrayList <File >();
101
106
if (classLoader != null ) {
102
- URL url = classLoader .getResource (filename );
103
- if (url != null && url .toString ().startsWith ("file:" )) {
104
- return new File (url .toString ().substring ("file:" .length ()));
107
+ Enumeration <URL > urls ;
108
+ try {
109
+ urls = classLoader .getResources (filename );
110
+ while (urls .hasMoreElements ()) {
111
+ URL url = urls .nextElement ();
112
+ if (url != null && url .toString ().startsWith ("file:" )) {
113
+ result .add (new File (url .toString ().substring ("file:" .length ())));
114
+ }
115
+ }
116
+ }
117
+ catch (IOException e ) {
118
+ // Ignore
105
119
}
106
120
}
107
- return null ;
121
+ return result ;
108
122
}
109
123
110
124
public List <?> getArgs () {
0 commit comments