File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
build-tools/src/main/java/org/elasticsearch/gradle/plugin Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -316,20 +316,24 @@ private String extractClassNameFromDirectory(File dir) throws IOException {
316316 * if it exists or the preset one derived from the jar task
317317 */
318318 private String extractModuleNameFromDirectory (File dir ) throws IOException {
319- List <File > files = new ArrayList <>(List .of (dir ));
320- while (files .isEmpty () == false ) {
321- File find = files .removeFirst ();
322- if (find .exists ()) {
323- if (find .getName ().equals ("module-info.class" )) {
324- try (InputStream inputStream = new FileInputStream (find )) {
325- return extractModuleNameFromModuleInfo (inputStream );
319+ var visitor = new SimpleFileVisitor <Path >() {
320+ private String result = getModuleName ().getOrNull ();
321+
322+ @ Override
323+ public @ NotNull FileVisitResult visitFile (@ NotNull Path candidate , @ NotNull BasicFileAttributes attrs ) throws IOException {
324+ String name = candidate .getFileName ().toString (); // Just the part after the last dir separator
325+ if (name .equals ("module-info.class" )) {
326+ try (InputStream inputStream = new FileInputStream (candidate .toFile ())) {
327+ result = extractModuleNameFromModuleInfo (inputStream );
328+ return TERMINATE ;
326329 }
327- } else if ( find . isDirectory ()) {
328- files . addAll ( Arrays . asList ( find . listFiles ())) ;
330+ } else {
331+ return CONTINUE ;
329332 }
330333 }
331- }
332- return getModuleName ().getOrNull ();
334+ };
335+ Files .walkFileTree (dir .toPath (), visitor );
336+ return visitor .result ;
333337 }
334338
335339 /**
You can’t perform that action at this time.
0 commit comments