@@ -192,20 +192,16 @@ public void execute() throws Exception {
192
192
}
193
193
194
194
private List <JavaRuntime > searchJava () throws IOException , InterruptedException {
195
- final int maxDepth = 2 ;
195
+ final int maxDepth = 3 ;
196
196
197
- Queue <File > fileQueue = new ArrayDeque <>(64 );
198
- ArrayList <JavaRuntime > binaryList = new ArrayList <>();
199
- final String relative = "bin" + File .separator + OperatingSystem .CURRENT_OS .getJavaExecutable ();
200
197
File [] subDirs = directory .listFiles (File ::isDirectory );
201
- if (subDirs == null ) return binaryList ;
202
- fileQueue .addAll (Arrays .asList (subDirs ));
198
+ if (subDirs == null ) return Collections .emptyList ();
199
+ List <JavaRuntime > binaryList = new ArrayList <>();
200
+ Queue <File > fileQueue = new LinkedList <>(Arrays .asList (subDirs ));
203
201
fileQueue .add (directory );
202
+ final String relative = "bin" + File .separator + OperatingSystem .CURRENT_OS .getJavaExecutable ();
204
203
int depth = 0 ;
205
- while (depth < maxDepth ) {
206
- if (isCancelled ())
207
- return Collections .emptyList ();
208
- if (fileQueue .isEmpty ()) break ;
204
+ while (!fileQueue .isEmpty ()) {
209
205
final File dir = fileQueue .poll ();
210
206
if (dir == directory ) {
211
207
depth ++;
@@ -218,11 +214,15 @@ private List<JavaRuntime> searchJava() throws IOException, InterruptedException
218
214
binaryList .add (JavaManager .getJava (binary .toPath ()));
219
215
continue ;
220
216
}
221
- subDirs = dir .listFiles (File ::isDirectory );
222
- if (subDirs != null )
223
- fileQueue .addAll (Arrays .asList (subDirs ));
217
+ if (depth < maxDepth - 1 ) {
218
+ subDirs = dir .listFiles (File ::isDirectory );
219
+ if (subDirs != null )
220
+ fileQueue .addAll (Arrays .asList (subDirs ));
221
+ }
222
+ if (isCancelled ())
223
+ return Collections .emptyList ();
224
224
}
225
- return binaryList ;
225
+ return Collections . unmodifiableList ( binaryList ) ;
226
226
}
227
227
}
228
228
0 commit comments